Coca77 commited on
Commit
dad52a8
·
verified ·
1 Parent(s): 49acab7

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -123
app.py DELETED
@@ -1,123 +0,0 @@
1
- import gradio as gr
2
- import json
3
- import pandas as pd
4
-
5
- # ----------------------------
6
- # LOAD DATA
7
- # ----------------------------
8
- with open("data.json", "r") as f:
9
- df = json.load(f)
10
-
11
- # ----------------------------
12
- # SEPSIS SCORING (DETERMINISTIC)
13
- # ----------------------------
14
- def sepsis_score(patient):
15
- score = 0
16
- notes = []
17
-
18
- try:
19
- visits = patient.get("visits", [])
20
-
21
- if not visits:
22
- return "Low", ["No visit data"]
23
-
24
- latest = visits[-1]
25
- labs = latest.get("labs", [])
26
-
27
- for lab in labs:
28
- name = lab.get("lab_name")
29
- value = lab.get("value")
30
-
31
- if name == "WBC" and value and value > 12:
32
- score += 1
33
- notes.append("Elevated WBC")
34
-
35
- if name == "Glucose" and value and value > 140:
36
- score += 1
37
- notes.append("Elevated glucose")
38
-
39
- if name == "Creatinine" and value and value > 1.3:
40
- score += 1
41
- notes.append("Elevated creatinine")
42
-
43
- except Exception:
44
- notes.append("Parsing error")
45
-
46
- if score == 0:
47
- severity = "Low"
48
- elif score == 1:
49
- severity = "Moderate"
50
- else:
51
- severity = "High"
52
-
53
- return severity, notes
54
-
55
- # ----------------------------
56
- # EXPLANATION
57
- # ----------------------------
58
- def explain(severity, notes):
59
- return f"""
60
- Sepsis Risk Assessment (Deterministic)
61
-
62
- Severity: {severity}
63
-
64
- Findings:
65
- {", ".join(notes) if notes else "No abnormal indicators"}
66
-
67
- This output is for validation purposes only.
68
- Not for clinical use.
69
- """
70
-
71
- # ----------------------------
72
- # ANALYZE FUNCTION
73
- # ----------------------------
74
- def analyze(index):
75
- index = int(index)
76
-
77
- if index >= len(df):
78
- return pd.DataFrame(), "Error", "Index out of range"
79
-
80
- patient = df[index]
81
-
82
- severity, notes = sepsis_score(patient)
83
- explanation = explain(severity, notes)
84
-
85
- # Flatten for display
86
- demo = patient.get("demographics", {})
87
-
88
- table = {
89
- "age": [demo.get("age")],
90
- "sex": [demo.get("sex")],
91
- "conditions": [", ".join(patient.get("conditions", []))]
92
- }
93
-
94
- return pd.DataFrame(table), severity, explanation
95
-
96
- # ----------------------------
97
- # UI
98
- # ----------------------------
99
- with gr.Blocks() as app:
100
- gr.Markdown("# HipAAsynth Lab — Sepsis Validation Demo")
101
-
102
- gr.Markdown("Select a patient and click Analyze")
103
-
104
- index = gr.Slider(
105
- minimum=0,
106
- maximum=len(df) - 1,
107
- step=1,
108
- label="Patient Index"
109
- )
110
-
111
- btn = gr.Button("Analyze")
112
-
113
- output_table = gr.Dataframe(label="Patient Summary")
114
- severity_out = gr.Textbox(label="Severity")
115
- explanation_out = gr.Textbox(label="Explanation")
116
-
117
- btn.click(
118
- fn=analyze,
119
- inputs=index,
120
- outputs=[output_table, severity_out, explanation_out]
121
- )
122
-
123
- app.launch()