Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,108 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import json
|
| 3 |
-
import pandas as pd
|
| 4 |
-
|
| 5 |
-
# ----------------------------
|
| 6 |
-
# LOAD DATA FRESH EVERY CLICK
|
| 7 |
-
# ----------------------------
|
| 8 |
-
def load_data():
|
| 9 |
-
with open("data.json", "r") as f:
|
| 10 |
-
raw = json.load(f)
|
| 11 |
-
|
| 12 |
-
if isinstance(raw, dict) and "patients" in raw:
|
| 13 |
-
return raw["patients"]
|
| 14 |
-
return raw
|
| 15 |
-
|
| 16 |
-
# ----------------------------
|
| 17 |
-
# SEPSIS SCORING
|
| 18 |
-
# ----------------------------
|
| 19 |
-
def sepsis_score(patient):
|
| 20 |
-
score = 0
|
| 21 |
-
findings = []
|
| 22 |
-
|
| 23 |
-
visits = patient.get("visits", [])
|
| 24 |
-
if not visits:
|
| 25 |
-
return "Low", ["No visit data"], []
|
| 26 |
-
|
| 27 |
-
labs = visits[-1].get("labs", [])
|
| 28 |
-
|
| 29 |
-
for lab in labs:
|
| 30 |
-
name = lab.get("lab_name")
|
| 31 |
-
value = lab.get("value")
|
| 32 |
-
|
| 33 |
-
if name == "WBC" and value > 12:
|
| 34 |
-
score += 1
|
| 35 |
-
findings.append(f"WBC {value}")
|
| 36 |
-
|
| 37 |
-
if name == "Glucose" and value > 140:
|
| 38 |
-
score += 1
|
| 39 |
-
findings.append(f"Glucose {value}")
|
| 40 |
-
|
| 41 |
-
if name == "Creatinine" and value > 1.3:
|
| 42 |
-
score += 1
|
| 43 |
-
findings.append(f"Creatinine {value}")
|
| 44 |
-
|
| 45 |
-
if score == 0:
|
| 46 |
-
severity = "Low"
|
| 47 |
-
elif score == 1:
|
| 48 |
-
severity = "Moderate"
|
| 49 |
-
else:
|
| 50 |
-
severity = "High"
|
| 51 |
-
|
| 52 |
-
return severity, findings, labs
|
| 53 |
-
|
| 54 |
-
# ----------------------------
|
| 55 |
-
# MAIN FUNCTION
|
| 56 |
-
# ----------------------------
|
| 57 |
-
def analyze(index):
|
| 58 |
-
df = load_data() # <-- reload EVERY TIME (kills caching issues)
|
| 59 |
-
|
| 60 |
-
index = int(index)
|
| 61 |
-
print("INDEX:", index)
|
| 62 |
-
|
| 63 |
-
if index >= len(df):
|
| 64 |
-
index = 0
|
| 65 |
-
|
| 66 |
-
patient = df[index]
|
| 67 |
-
|
| 68 |
-
severity, findings, labs = sepsis_score(patient)
|
| 69 |
-
|
| 70 |
-
demo = patient.get("demographics", {})
|
| 71 |
-
|
| 72 |
-
summary = pd.DataFrame([{
|
| 73 |
-
"Index": index,
|
| 74 |
-
"PatientID": patient.get("patient_id"),
|
| 75 |
-
"Age": demo.get("age"),
|
| 76 |
-
"Sex": demo.get("sex"),
|
| 77 |
-
"Conditions": ", ".join(patient.get("conditions", []))
|
| 78 |
-
}])
|
| 79 |
-
|
| 80 |
-
labs_df = pd.DataFrame(labs)
|
| 81 |
-
|
| 82 |
-
explanation = f"Severity: {severity} | Findings: {findings}"
|
| 83 |
-
|
| 84 |
-
return summary, labs_df, severity, explanation
|
| 85 |
-
|
| 86 |
-
# ----------------------------
|
| 87 |
-
# UI
|
| 88 |
-
# ----------------------------
|
| 89 |
-
with gr.Blocks() as app:
|
| 90 |
-
|
| 91 |
-
gr.Markdown("# HipAAsynth Lab — FINAL FIX")
|
| 92 |
-
|
| 93 |
-
index = gr.Slider(0, 10, step=1, value=0, label="Patient Index")
|
| 94 |
-
|
| 95 |
-
btn = gr.Button("Analyze")
|
| 96 |
-
|
| 97 |
-
summary = gr.Dataframe()
|
| 98 |
-
labs = gr.Dataframe()
|
| 99 |
-
severity = gr.Textbox()
|
| 100 |
-
explanation = gr.Textbox()
|
| 101 |
-
|
| 102 |
-
btn.click(
|
| 103 |
-
analyze,
|
| 104 |
-
inputs=[index],
|
| 105 |
-
outputs=[summary, labs, severity, explanation]
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|