phyjaafar commited on
Commit
ac5bab0
·
verified ·
1 Parent(s): 0ec188e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -48
app.py CHANGED
@@ -3,73 +3,68 @@ import numpy as np
3
 
4
  def calculate_tia(t1, a1, t2, a2):
5
  try:
6
- # حساب معدل الإفراغ k
7
  k = np.log(a1 / a2) / (t2 - t1)
8
- # حساب النشاط الابتدائي A₀
9
  a0 = a1 / np.exp(-k * t1)
10
- # حساب النشاط التكاملي TIA
11
  tia = a0 / k
12
- result = f"**Results:**\n- A₀ = {a0:.2f} MBq\n- k = {k:.5f} per hour\n- TIA = {tia:.2f} MBq·h"
13
- except:
14
- result = "Error: Please enter valid numbers."
 
 
 
 
 
 
15
 
16
  return result
17
 
18
  with gr.Blocks() as demo:
19
- gr.Markdown("#gr.Markdown("""
20
- ---
21
-
22
- ### ℹ️ **What Is This Tool?**
23
 
24
- This free, open-source web application is designed to calculate **Time-Integrated Activity (TIA)** for patients undergoing **Lutetium-177 PSMA therapy** in metastatic prostate cancer. It uses only two post-treatment SPECT imaging time points to produce accurate, personalized dosimetry in resource-constrained settings.
 
 
25
 
26
- The tool relies on a simplified yet clinically validated mathematical model (mono-exponential washout), commonly used for organs with regular clearance kinetics such as kidneys or PSMA-positive tumors.
 
 
27
 
28
- ---
 
 
29
 
30
- ### ⚙️ **How Does It Work?**
 
 
31
 
32
- You simply enter:
33
- - Two imaging time points (in hours)
34
- - Measured activity for each point (in MBq)
35
 
36
- The tool automatically:
37
- - Fits the time–activity curve (TAC) using exponential modeling
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
- ### 🧠 **Scientific Basis**
 
 
 
44
 
45
- This method applies the following model:
 
46
 
47
- > **A(t) = A₀ · exp(–k · t)**
48
- > **TIA = A₀ / k**
49
 
50
- Where:
51
- - _A(t)_ is the activity at time _t_
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 model is suitable for organs and lesions that exhibit predictable biological clearance and helps support practical dosimetry protocols in clinical or academic environments.
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()