File size: 2,952 Bytes
654bb88
 
08fa91e
654bb88
08fa91e
654bb88
08fa91e
654bb88
 
 
ac5bab0
 
 
 
 
08fa91e
ac5bab0
395dfad
08fa91e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
654bb88
 
ac5bab0
0ec188e
ac5bab0
 
 
0ec188e
ac5bab0
 
 
0ec188e
08fa91e
 
 
 
 
0ec188e
ac5bab0
 
 
0ec188e
ac5bab0
 
0ec188e
ac5bab0
 
0ec188e
ac5bab0
 
0ec188e
ac5bab0
 
 
 
0ec188e
ac5bab0
 
0ec188e
ac5bab0
0ec188e
ac5bab0
 
0ec188e
ac5bab0
0ec188e
ac5bab0
 
08fa91e
654bb88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import gradio as gr
import numpy as np
import matplotlib.pyplot as plt

def calculate_and_plot(t1, a1, t2, a2):
    try:
        # الحسابات الأساسية
        k = np.log(a1 / a2) / (t2 - t1)
        a0 = a1 / np.exp(-k * t1)
        tia = a0 / k

        result = f"""
        ### ✅ Results
        - **A₀ (initial activity):** {a0:.2f} MBq  
        - **k (washout rate):** {k:.5f} / hour  
        - **TIA:** {tia:.2f} MBq·h  
        """

        # إنشاء نقاط الرسم
        t_points = np.linspace(0, max(t2 + 40, 200), 100)
        a_points = a0 * np.exp(-k * t_points)

        # رسم المنحنى باستخدام matplotlib
        fig, ax = plt.subplots(figsize=(6, 4))
        ax.plot(t_points, a_points, label="Fitted Curve", color='blue')
        ax.scatter([t1, t2], [a1, a2], color='red', label="Input Points")
        ax.set_xlabel("Time (hours)")
        ax.set_ylabel("Activity (MBq)")
        ax.set_title("Mono-Exponential Washout Curve")
        ax.grid(True)
        ax.legend()
        plt.tight_layout()

        return result, fig

    except Exception:
        return "⚠️ Error: Please check your inputs.", None

with gr.Blocks() as demo:
    gr.Markdown("# ⚛️ Lu-177 Dosimetry Tool\nEstimate Time-Integrated Activity (TIA) from Two SPECT Time Points")

    with gr.Row():
        t1 = gr.Number(label="Time Point 1 (hours)", value=20)
        a1 = gr.Number(label="Activity at Time 1 (MBq)", value=12)

    with gr.Row():
        t2 = gr.Number(label="Time Point 2 (hours)", value=60)
        a2 = gr.Number(label="Activity at Time 2 (MBq)", value=4)

    output_text = gr.Markdown()
    output_plot = gr.Plot()
    button = gr.Button("Calculate & Plot TIA")

    button.click(fn=calculate_and_plot, inputs=[t1, a1, t2, a2], outputs=[output_text, output_plot])

    gr.Markdown("""
    ---
    ### ℹ️ What Is This Tool?

    This open-source calculator estimates **Time-Integrated Activity (TIA)** for patients receiving **Lutetium-177 PSMA therapy** for metastatic prostate cancer.  
    It uses **two post-treatment SPECT/CT time points** to fit a simplified **mono-exponential washout model**, helping clinicians perform dose calculations with minimal imaging.

    ---
    ### ⚙️ How It Works

    You enter two scan times (hours) and their corresponding measured activity (MBq).  
    The tool automatically:

    - Fits an exponential time–activity curve  
    - Calculates the washout rate (_k_)  
    - Estimates initial activity (_A₀_)  
    - Computes **TIA = A₀ / k**, which can be used in absorbed dose estimation

    ---
    ### 🧠 Scientific Basis

    Model used:

    > A(t) = A₀ · exp(–k · t)  
    > TIA = A₀ / k

    This approach is ideal for organs with regular clearance kinetics (e.g., kidneys) or tumors with predictable washout, and is based on principles used in MIRD dosimetry and EANM guidelines.

    ---
    """)

demo.launch()