Coca77 commited on
Commit
3914636
·
verified ·
1 Parent(s): 5eef54b

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -143
app.py DELETED
@@ -1,143 +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
- # IMPROVED SEPSIS SCORING
13
- # ----------------------------
14
- def sepsis_score(patient):
15
- score = 0
16
- findings = []
17
-
18
- visits = patient.get("visits", [])
19
- if not visits:
20
- return "Low", ["No visit data"], []
21
-
22
- latest = visits[-1]
23
- labs = latest.get("labs", [])
24
-
25
- for lab in labs:
26
- name = lab.get("lab_name")
27
- value = lab.get("value")
28
-
29
- if name == "WBC":
30
- if value > 12:
31
- score += 1
32
- findings.append(f"WBC elevated ({value})")
33
-
34
- if name == "Glucose":
35
- if value > 140:
36
- score += 1
37
- findings.append(f"Hyperglycemia ({value})")
38
-
39
- if name == "Creatinine":
40
- if value > 1.3:
41
- score += 1
42
- findings.append(f"Renal stress ({value})")
43
-
44
- # More realistic tiers
45
- if score == 0:
46
- severity = "Low"
47
- elif score == 1:
48
- severity = "Elevated"
49
- elif score == 2:
50
- severity = "High"
51
- else:
52
- severity = "Critical"
53
-
54
- return severity, findings, labs
55
-
56
- # ----------------------------
57
- # EXPLANATION (GEMMA-READY STYLE)
58
- # ----------------------------
59
- def explain(severity, findings):
60
- return f"""
61
- Deterministic Sepsis Evaluation
62
-
63
- Severity Classification: {severity}
64
-
65
- Clinical Indicators:
66
- {", ".join(findings) if findings else "No abnormal indicators detected"}
67
-
68
- Interpretation:
69
- This assessment is derived from structured laboratory thresholds and rule-based evaluation.
70
-
71
- This output is intended for validation and testing purposes only.
72
- Not for clinical use.
73
- """
74
-
75
- # ----------------------------
76
- # ANALYZE FUNCTION
77
- # ----------------------------
78
- def analyze(index):
79
- index = int(index)
80
- patient = df[index]
81
-
82
- severity, findings, labs = sepsis_score(patient)
83
- explanation = explain(severity, findings)
84
-
85
- demo = patient.get("demographics", {})
86
-
87
- # Patient summary
88
- summary_df = pd.DataFrame([{
89
- "Patient Index": index,
90
- "Age": demo.get("age"),
91
- "Sex": demo.get("sex"),
92
- "Conditions": ", ".join(patient.get("conditions", []))
93
- }])
94
-
95
- # Labs table
96
- labs_rows = []
97
- for lab in labs:
98
- labs_rows.append({
99
- "Lab": lab.get("lab_name"),
100
- "Value": lab.get("value")
101
- })
102
-
103
- labs_df = pd.DataFrame(labs_rows)
104
-
105
- return summary_df, labs_df, severity, explanation
106
-
107
- # ----------------------------
108
- # UI
109
- # ----------------------------
110
- with gr.Blocks() as app:
111
-
112
- gr.Markdown("# HipAAsynth Lab")
113
- gr.Markdown("Deterministic Clinical Validation Environment")
114
-
115
- with gr.Row():
116
- index = gr.Slider(
117
- minimum=0,
118
- maximum=len(df) - 1,
119
- step=1,
120
- value=0,
121
- label="Patient Selector"
122
- )
123
- btn = gr.Button("Run Evaluation")
124
-
125
- with gr.Row():
126
- severity_out = gr.Textbox(label="Severity Classification")
127
-
128
- with gr.Row():
129
- summary_out = gr.Dataframe(label="Patient Summary")
130
-
131
- with gr.Row():
132
- labs_out = gr.Dataframe(label="Latest Laboratory Results")
133
-
134
- with gr.Row():
135
- explanation_out = gr.Textbox(label="System Explanation")
136
-
137
- btn.click(
138
- fn=analyze,
139
- inputs=index,
140
- outputs=[summary_out, labs_out, severity_out, explanation_out]
141
- )
142
-
143
- app.launch()