Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,73 +3,68 @@ import numpy as np
|
|
3 |
|
4 |
def calculate_tia(t1, a1, t2, a2):
|
5 |
try:
|
6 |
-
#
|
7 |
k = np.log(a1 / a2) / (t2 - t1)
|
8 |
-
#
|
9 |
a0 = a1 / np.exp(-k * t1)
|
10 |
-
#
|
11 |
tia = a0 / k
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
return result
|
17 |
|
18 |
with gr.Blocks() as demo:
|
19 |
-
gr.Markdown("#
|
20 |
-
---
|
21 |
-
|
22 |
-
### ℹ️ **What Is This Tool?**
|
23 |
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
|
|
|
|
|
27 |
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
-
|
34 |
-
- Measured activity for each point (in MBq)
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
- Calculates the washout rate (_k_), initial activity (_A₀_), and total time-integrated activity (_TIA = A₀ / k_)
|
39 |
-
- Displays results instantly and clearly
|
40 |
|
41 |
-
|
|
|
42 |
|
43 |
-
|
|
|
|
|
|
|
44 |
|
45 |
-
|
|
|
46 |
|
47 |
-
|
48 |
-
> **TIA = A₀ / k**
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
- _A₀_ is the estimated initial activity
|
53 |
-
- _k_ is the washout rate (clearance constant)
|
54 |
-
- _TIA_ is the integrated activity over time used to estimate absorbed radiation dose
|
55 |
|
56 |
-
This
|
57 |
|
58 |
-
---
|
59 |
-
""")
|
60 |
-
.")
|
61 |
-
|
62 |
-
with gr.Row():
|
63 |
-
t1 = gr.Number(label="Time Point 1 (hours)", value=20)
|
64 |
-
a1 = gr.Number(label="Activity at t1 (MBq)", value=12)
|
65 |
-
|
66 |
-
with gr.Row():
|
67 |
-
t2 = gr.Number(label="Time Point 2 (hours)", value=60)
|
68 |
-
a2 = gr.Number(label="Activity at t2 (MBq)", value=4)
|
69 |
|
70 |
-
button = gr.Button("Calculate TIA")
|
71 |
-
output = gr.Markdown()
|
72 |
-
|
73 |
-
button.click(fn=calculate_tia, inputs=[t1, a1, t2, a2], outputs=output)
|
74 |
-
|
75 |
demo.launch()
|
|
|
3 |
|
4 |
def calculate_tia(t1, a1, t2, a2):
|
5 |
try:
|
6 |
+
# Calculate washout rate constant (k)
|
7 |
k = np.log(a1 / a2) / (t2 - t1)
|
8 |
+
# Estimate initial activity (A₀)
|
9 |
a0 = a1 / np.exp(-k * t1)
|
10 |
+
# Calculate Time-Integrated Activity (TIA)
|
11 |
tia = a0 / k
|
12 |
+
|
13 |
+
result = f"""
|
14 |
+
### ✅ Results
|
15 |
+
- **A₀ (initial activity):** {a0:.2f} MBq
|
16 |
+
- **k (washout rate):** {k:.5f} / hour
|
17 |
+
- **TIA (time-integrated activity):** {tia:.2f} MBq·h
|
18 |
+
"""
|
19 |
+
except Exception:
|
20 |
+
result = "⚠️ Error: Please check your inputs. Values must be positive and non-zero."
|
21 |
|
22 |
return result
|
23 |
|
24 |
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("# ⚛️ Lu-177 Dosimetry Tool\nEstimate Time-Integrated Activity (TIA) from Two SPECT Time Points")
|
|
|
|
|
|
|
26 |
|
27 |
+
with gr.Row():
|
28 |
+
t1 = gr.Number(label="Time Point 1 (hours)", value=20)
|
29 |
+
a1 = gr.Number(label="Activity at Time 1 (MBq)", value=12)
|
30 |
|
31 |
+
with gr.Row():
|
32 |
+
t2 = gr.Number(label="Time Point 2 (hours)", value=60)
|
33 |
+
a2 = gr.Number(label="Activity at Time 2 (MBq)", value=4)
|
34 |
|
35 |
+
output = gr.Markdown()
|
36 |
+
button = gr.Button("Calculate TIA")
|
37 |
+
button.click(fn=calculate_tia, inputs=[t1, a1, t2, a2], outputs=output)
|
38 |
|
39 |
+
gr.Markdown("""
|
40 |
+
---
|
41 |
+
### ℹ️ What Is This Tool?
|
42 |
|
43 |
+
This open-source calculator estimates **Time-Integrated Activity (TIA)** for patients receiving **Lutetium-177 PSMA therapy** for metastatic prostate cancer.
|
44 |
+
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.
|
|
|
45 |
|
46 |
+
---
|
47 |
+
### ⚙️ How It Works
|
|
|
|
|
48 |
|
49 |
+
You enter two scan times (hours) and their corresponding measured activity (MBq).
|
50 |
+
The tool automatically:
|
51 |
|
52 |
+
- Fits an exponential time–activity curve
|
53 |
+
- Calculates the washout rate (_k_)
|
54 |
+
- Estimates initial activity (_A₀_)
|
55 |
+
- Computes **TIA = A₀ / k**, which can be used in absorbed dose estimation
|
56 |
|
57 |
+
---
|
58 |
+
### 🧠 Scientific Basis
|
59 |
|
60 |
+
Model used:
|
|
|
61 |
|
62 |
+
> A(t) = A₀ · exp(–k · t)
|
63 |
+
> TIA = A₀ / k
|
|
|
|
|
|
|
64 |
|
65 |
+
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.
|
66 |
|
67 |
+
---
|
68 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
|
|
|
|
|
|
|
|
|
|
70 |
demo.launch()
|