Spaces:
Running
Running
Upload 2 files
Browse files- app.py +61 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def piv_tool(velocity, shear, hr):
|
| 4 |
+
v = "HIGH - stenosis risk" if float(velocity) > 2.0 else "NORMAL"
|
| 5 |
+
s = "HIGH - thrombosis risk" if float(shear) > 10 else "NORMAL"
|
| 6 |
+
return "Velocity: " + str(velocity) + " m/s - " + v + "\nShear: " + str(shear) + " Pa - " + s
|
| 7 |
+
|
| 8 |
+
def tgt_tool(tat, pf12, hemo, platelets, time):
|
| 9 |
+
risk = sum([float(tat)>15, float(pf12)>2.0, float(hemo)>50, float(platelets)<150])
|
| 10 |
+
overall = "HIGH THROMBOGENIC RISK" if risk>=3 else "MODERATE RISK" if risk>=2 else "LOW RISK"
|
| 11 |
+
return "TAT:" + str(tat) + " PF1.2:" + str(pf12) + " Hemo:" + str(hemo) + " Platelets:" + str(platelets) + "\nResult: " + overall
|
| 12 |
+
|
| 13 |
+
def upad_tool(r, g, b):
|
| 14 |
+
creatinine = max(0, round(0.02*(float(r)-float(b))-0.5, 2))
|
| 15 |
+
stage = "Normal" if creatinine<1.2 else "Borderline" if creatinine<1.5 else "Stage 2 CKD" if creatinine<3.0 else "Stage 3-4 CKD" if creatinine<6.0 else "Stage 5 CKD"
|
| 16 |
+
return "Creatinine: " + str(creatinine) + " mg/dL\nStage: " + stage
|
| 17 |
+
|
| 18 |
+
def ask(q):
|
| 19 |
+
answers = {
|
| 20 |
+
"sylgard": "Sylgard 184 is used in the MCL to create transparent test sections for PIV imaging. Mixed at 10:1 ratio, cured 48hrs.",
|
| 21 |
+
"tgt": "TGT uses Arduino Uno + Stepper Motor at 70 bpm. Blood sampled at 0,20,40,60 min. Measures TAT, PF1.2, hemolysis.",
|
| 22 |
+
"jaffe": "Jaffe reaction: creatinine + picric acid = orange-red color. Used in uPAD for CKD creatinine detection.",
|
| 23 |
+
"piv": "PIV = Particle Image Velocimetry. Green laser + high speed camera measures velocity and shear stress in MCL.",
|
| 24 |
+
"ckd": "CKD detected via uPAD Jaffe reaction. Normal creatinine < 1.2 mg/dL. CKD threshold > 1.5 mg/dL.",
|
| 25 |
+
"mhv": "Lab uses 27mm SJM Regent MHV. Tested in MCL for hemodynamics and TGT for thrombogenicity.",
|
| 26 |
+
}
|
| 27 |
+
for key, answer in answers.items():
|
| 28 |
+
if key in q.lower():
|
| 29 |
+
return answer
|
| 30 |
+
return "CardioLab AI covers MCL, PIV, TGT, uPAD, CKD, FSI, MHV. Ask about any topic!"
|
| 31 |
+
|
| 32 |
+
with gr.Blocks(title="CardioLab AI - SJSU") as demo:
|
| 33 |
+
gr.Markdown("# CardioLab AI Agent")
|
| 34 |
+
gr.Markdown("### SJSU Biomedical Engineering | Open Source")
|
| 35 |
+
gr.Markdown("GitHub: github.com/pranatechsol/Cardio-Lab-Ai")
|
| 36 |
+
with gr.Tab("Ask Agent"):
|
| 37 |
+
q = gr.Textbox(label="Ask about CardioLab research")
|
| 38 |
+
a = gr.Textbox(label="Answer", lines=4)
|
| 39 |
+
gr.Button("Ask CardioLab AI").click(ask, inputs=q, outputs=a)
|
| 40 |
+
with gr.Tab("PIV Analysis"):
|
| 41 |
+
v = gr.Number(label="Max Velocity m/s", value=1.8)
|
| 42 |
+
s = gr.Number(label="Shear Stress Pa", value=6.5)
|
| 43 |
+
h = gr.Number(label="Heart Rate bpm", value=72)
|
| 44 |
+
out = gr.Textbox(label="Result", lines=4)
|
| 45 |
+
gr.Button("Analyze PIV").click(piv_tool, inputs=[v,s,h], outputs=out)
|
| 46 |
+
with gr.Tab("TGT Results"):
|
| 47 |
+
t1 = gr.Number(label="TAT", value=18)
|
| 48 |
+
t2 = gr.Number(label="PF1.2", value=2.5)
|
| 49 |
+
t3 = gr.Number(label="Free Hemoglobin", value=60)
|
| 50 |
+
t4 = gr.Number(label="Platelet Count", value=140)
|
| 51 |
+
t5 = gr.Number(label="Time minutes", value=40)
|
| 52 |
+
out2 = gr.Textbox(label="Result", lines=5)
|
| 53 |
+
gr.Button("Analyze TGT").click(tgt_tool, inputs=[t1,t2,t3,t4,t5], outputs=out2)
|
| 54 |
+
with gr.Tab("uPAD CKD"):
|
| 55 |
+
r = gr.Number(label="R value", value=210)
|
| 56 |
+
g = gr.Number(label="G value", value=140)
|
| 57 |
+
b = gr.Number(label="B value", value=80)
|
| 58 |
+
out3 = gr.Textbox(label="Result", lines=4)
|
| 59 |
+
gr.Button("Analyze uPAD").click(upad_tool, inputs=[r,g,b], outputs=out3)
|
| 60 |
+
|
| 61 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|