sonitv commited on
Commit
dbd3299
·
verified ·
1 Parent(s): b526d61

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +10 -14
  2. app.py +284 -0
  3. requirements.txt +0 -3
README.md CHANGED
@@ -1,20 +1,16 @@
1
  ---
2
- title: IMPROVE
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
  pinned: false
11
- short_description: Mechanical Power Optimization
12
- license: apache-2.0
13
  ---
14
 
15
- # Welcome to Streamlit!
16
 
17
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
18
 
19
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
20
- forums](https://discuss.streamlit.io).
 
1
  ---
2
+ title: IMPROVE Framework
3
+ emoji: 🏥
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.28.0
8
+ app_file: app.py
 
9
  pinned: false
 
 
10
  ---
11
 
12
+ # IMPROVE Framework
13
 
14
+ Personalized Mechanical Power Optimization for Ventilator Settings.
15
 
16
+ Built for ESICM Datathon 2025.
 
app.py ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import plotly.graph_objects as go
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ # Page setup
7
+ st.set_page_config(page_title="IMPROVE Framework", layout="wide")
8
+ st.markdown("""
9
+ <style>
10
+ .stApp { background-color: #FFFFFF; }
11
+ h1 { color: #000000; font-size: 28px; font-weight: bold; border-bottom: 2px solid #0366D6; padding-bottom: 10px; }
12
+ h2 { color: #000000; font-size: 20px; font-weight: 600; margin-top: 30px; }
13
+ h3 { color: #000000; font-size: 16px; font-weight: 600; }
14
+ p, div, label, span { color: #000000 !important; }
15
+ .stSlider > div > div > div { color: #000000 !important; }
16
+ .metric-box { background: #F5F5F5; border: 1px solid #DDDDDD; border-radius: 8px; padding: 15px; margin: 5px; }
17
+ .metric-label { font-size: 12px; color: #666666; text-transform: uppercase; font-weight: 600; }
18
+ .metric-value { font-size: 24px; color: #000000; font-weight: bold; font-family: monospace; }
19
+ .recommendation-box { padding: 20px; border-radius: 8px; margin-top: 20px; }
20
+ .success { background: #D4EDDA; border-left: 5px solid #28A745; }
21
+ .warning { background: #FFF3CD; border-left: 5px solid #FFC107; }
22
+ .info { background: #D1ECF1; border-left: 5px solid #17A2B8; }
23
+
24
+ /* SIDEBAR WHITE TEXT */
25
+ .css-1d391kg, .css-1lcbmhc, section[data-testid="stSidebar"] {
26
+ background-color: #1a1a1a !important;
27
+ }
28
+ .css-1d391kg .stMarkdown, .css-1d391kg p, .css-1d391kg label,
29
+ .css-1d391kg h1, .css-1d391kg h2, .css-1d391kg h3,
30
+ section[data-testid="stSidebar"] p, section[data-testid="stSidebar"] label,
31
+ section[data-testid="stSidebar"] .stMarkdown, section[data-testid="stSidebar"] div {
32
+ color: #FFFFFF !important;
33
+ }
34
+ .css-1d391kg .stSelectbox label, section[data-testid="stSidebar"] .stSelectbox label {
35
+ color: #FFFFFF !important;
36
+ }
37
+
38
+ /* Slider current value indicator */
39
+ .current-value-marker {
40
+ background: #0366D6;
41
+ color: white;
42
+ padding: 2px 8px;
43
+ border-radius: 4px;
44
+ font-size: 11px;
45
+ font-weight: 600;
46
+ font-family: monospace;
47
+ display: inline-block;
48
+ margin-bottom: 5px;
49
+ }
50
+ </style>
51
+ """, unsafe_allow_html=True)
52
+
53
+ # Patient data
54
+ PATIENTS = [
55
+ {"id": "ICU-001", "age": 58, "sex": "M", "weight": 78, "diagnosis": "ARDS", "rr": 18, "vt": 450, "peep": 8, "p_plat": 25, "mort_7d": 0.15, "mort_48h": 0.09},
56
+ {"id": "ICU-002", "age": 67, "sex": "F", "weight": 65, "diagnosis": "Sepsis", "rr": 24, "vt": 380, "peep": 12, "p_plat": 28, "mort_7d": 0.28, "mort_48h": 0.17},
57
+ {"id": "ICU-003", "age": 45, "sex": "M", "weight": 82, "diagnosis": "Trauma", "rr": 12, "vt": 550, "peep": 5, "p_plat": 20, "mort_7d": 0.08, "mort_48h": 0.05},
58
+ {"id": "ICU-004", "age": 72, "sex": "F", "weight": 60, "diagnosis": "Pneumonia", "rr": 32, "vt": 320, "peep": 15, "p_plat": 32, "mort_7d": 0.45, "mort_48h": 0.27},
59
+ {"id": "ICU-005", "age": 55, "sex": "M", "weight": 90, "diagnosis": "ARDS", "rr": 16, "vt": 500, "peep": 10, "p_plat": 22, "mort_7d": 0.12, "mort_48h": 0.07},
60
+ {"id": "ICU-006", "age": 63, "sex": "F", "weight": 55, "diagnosis": "Sepsis", "rr": 28, "vt": 350, "peep": 14, "p_plat": 30, "mort_7d": 0.35, "mort_48h": 0.21},
61
+ {"id": "ICU-007", "age": 49, "sex": "M", "weight": 75, "diagnosis": "Trauma", "rr": 20, "vt": 480, "peep": 8, "p_plat": 26, "mort_7d": 0.18, "mort_48h": 0.11},
62
+ {"id": "ICU-008", "age": 38, "sex": "F", "weight": 68, "diagnosis": "Pneumonia", "rr": 14, "vt": 600, "peep": 6, "p_plat": 18, "mort_7d": 0.05, "mort_48h": 0.03},
63
+ {"id": "ICU-009", "age": 71, "sex": "M", "weight": 70, "diagnosis": "ARDS", "rr": 26, "vt": 400, "peep": 12, "p_plat": 29, "mort_7d": 0.32, "mort_48h": 0.19},
64
+ {"id": "ICU-010", "age": 52, "sex": "F", "weight": 62, "diagnosis": "Sepsis", "rr": 22, "vt": 420, "peep": 9, "p_plat": 24, "mort_7d": 0.22, "mort_48h": 0.13},
65
+ ]
66
+
67
+ def calculate_mp(rr, vt, p_plat, peep):
68
+ """Gattinoni formula"""
69
+ return 0.098 * rr * (vt/1000) * (p_plat - peep/2)
70
+
71
+ def predict_outcomes(base_mort_7d, base_mort_48h, current_mp, new_mp):
72
+ """Simple prediction model"""
73
+ ratio = new_mp / current_mp if current_mp > 0 else 1
74
+
75
+ if ratio < 0.85: # Good reduction
76
+ mort_7d = base_mort_7d * 0.85
77
+ mort_48h = base_mort_48h * 0.80
78
+ oxy = 0.75
79
+ elif ratio < 1.0: # Small reduction
80
+ mort_7d = base_mort_7d * 0.95
81
+ mort_48h = base_mort_48h * 0.92
82
+ oxy = 0.70
83
+ else: # Increase
84
+ mort_7d = base_mort_7d * min(1.3, (1 + (ratio - 1) * 1.5))
85
+ mort_48h = base_mort_48h * min(1.4, (1 + (ratio - 1) * 2))
86
+ oxy = max(0.40, 0.65 - (ratio - 1) * 0.5)
87
+
88
+ return (max(0.01, min(0.99, mort_7d)),
89
+ max(0.01, min(0.99, mort_48h)),
90
+ oxy)
91
+
92
+ # Main App
93
+ st.markdown("<h1>IMPROVE Framework</h1>", unsafe_allow_html=True)
94
+ st.markdown("<p style='color: #000000;'>Mechanical Power Optimization for Ventilator Settings</p>", unsafe_allow_html=True)
95
+
96
+ # Sidebar - Patient Selection (with white text on dark background)
97
+ selected_id = st.sidebar.selectbox("Select Patient", [p["id"] for p in PATIENTS])
98
+ patient = next(p for p in PATIENTS if p["id"] == selected_id)
99
+
100
+ # Calculate baseline MP
101
+ current_mp = calculate_mp(patient["rr"], patient["vt"], patient["p_plat"], patient["peep"])
102
+
103
+ # Sidebar - Patient Details
104
+ st.sidebar.markdown("---")
105
+ st.sidebar.subheader("Demographics")
106
+ st.sidebar.write(f"**Age:** {patient['age']} years")
107
+ st.sidebar.write(f"**Sex:** {patient['sex']}")
108
+ st.sidebar.write(f"**Weight:** {patient['weight']} kg")
109
+ st.sidebar.write(f"**Diagnosis:** {patient['diagnosis']}")
110
+
111
+ st.sidebar.markdown("---")
112
+ st.sidebar.subheader("Current Ventilator Settings")
113
+ st.sidebar.write(f"**Respiratory Rate:** {patient['rr']} b/min")
114
+ st.sidebar.write(f"**Tidal Volume:** {patient['vt']} mL")
115
+ st.sidebar.write(f"**PEEP:** {patient['peep']} cmH₂O")
116
+ st.sidebar.write(f"**Plateau Pressure:** {patient['p_plat']} cmH₂O")
117
+ st.sidebar.write(f"**Mechanical Power:** {current_mp:.1f} J/min")
118
+ st.sidebar.write(f"**Mortality (7d):** {patient['mort_7d']:.0%}")
119
+
120
+ # Main content
121
+ col1, col2 = st.columns([1, 2])
122
+
123
+ with col1:
124
+ st.markdown("<h2 style='color: #000000;'>Adjust Parameters</h2>", unsafe_allow_html=True)
125
+ st.markdown(f"<p style='color: #000000;'>Baseline MP: <b>{current_mp:.1f}</b> J/min</p>", unsafe_allow_html=True)
126
+
127
+ # RR Slider with current value marker
128
+ st.markdown(f"""
129
+ <div style='margin-bottom: -10px;'>
130
+ <span style='color: #666; font-size: 12px;'>Current: </span>
131
+ <span class='current-value-marker'>{patient['rr']} b/min</span>
132
+ </div>
133
+ """, unsafe_allow_html=True)
134
+ new_rr = st.slider("Respiratory Rate", min_value=8, max_value=40, value=patient["rr"], step=1, label_visibility="collapsed")
135
+
136
+ # VT Slider with current value marker
137
+ st.markdown(f"""
138
+ <div style='margin-bottom: -10px; margin-top: 15px;'>
139
+ <span style='color: #666; font-size: 12px;'>Current: </span>
140
+ <span class='current-value-marker'>{patient['vt']} mL</span>
141
+ </div>
142
+ """, unsafe_allow_html=True)
143
+ new_vt = st.slider("Tidal Volume", min_value=250, max_value=700, value=patient["vt"], step=10, label_visibility="collapsed")
144
+
145
+ # PEEP Slider with current value marker
146
+ st.markdown(f"""
147
+ <div style='margin-bottom: -10px; margin-top: 15px;'>
148
+ <span style='color: #666; font-size: 12px;'>Current: </span>
149
+ <span class='current-value-marker'>{patient['peep']} cmH₂O</span>
150
+ </div>
151
+ """, unsafe_allow_html=True)
152
+ new_peep = st.slider("PEEP", min_value=0, max_value=20, value=patient["peep"], step=1, label_visibility="collapsed")
153
+
154
+ with col2:
155
+ # Calculate new values
156
+ new_mp = calculate_mp(new_rr, new_vt, patient["p_plat"], new_peep)
157
+ mp_change = new_mp - current_mp
158
+ mp_reduction = ((current_mp - new_mp) / current_mp * 100)
159
+
160
+ # Predict outcomes
161
+ mort_7d, mort_48h, oxy = predict_outcomes(
162
+ patient["mort_7d"], patient["mort_48h"], current_mp, new_mp
163
+ )
164
+
165
+ st.markdown("<h2 style='color: #000000;'>Predicted Outcomes</h2>", unsafe_allow_html=True)
166
+
167
+ # Metrics in boxes
168
+ m1, m2, m3, m4 = st.columns(4)
169
+
170
+ with m1:
171
+ color = "#28A745" if mp_reduction > 5 else "#FFC107" if mp_reduction > 0 else "#6C757D"
172
+ st.markdown(f"""
173
+ <div class="metric-box">
174
+ <div class="metric-label">Mechanical Power</div>
175
+ <div class="metric-value" style="color: {color};">{new_mp:.1f}</div>
176
+ <div style="font-family: monospace; font-size: 12px; color: #666;">
177
+ Δ {mp_change:+.1f} ({mp_reduction:+.1f}%)
178
+ </div>
179
+ </div>
180
+ """, unsafe_allow_html=True)
181
+
182
+ with m2:
183
+ delta = mort_7d - patient["mort_7d"]
184
+ color = "#DC3545" if delta > 0.01 else "#28A745"
185
+ st.markdown(f"""
186
+ <div class="metric-box">
187
+ <div class="metric-label">Mortality (7 days)</div>
188
+ <div class="metric-value" style="color: {color};">{mort_7d:.1%}</div>
189
+ <div style="font-family: monospace; font-size: 12px; color: #666;">
190
+ Δ {delta:+.3f}
191
+ </div>
192
+ </div>
193
+ """, unsafe_allow_html=True)
194
+
195
+ with m3:
196
+ delta = mort_48h - patient["mort_48h"]
197
+ color = "#DC3545" if delta > 0.01 else "#28A745"
198
+ st.markdown(f"""
199
+ <div class="metric-box">
200
+ <div class="metric-label">Mortality (48 hours)</div>
201
+ <div class="metric-value" style="color: {color};">{mort_48h:.1%}</div>
202
+ <div style="font-family: monospace; font-size: 12px; color: #666;">
203
+ Δ {delta:+.3f}
204
+ </div>
205
+ </div>
206
+ """, unsafe_allow_html=True)
207
+
208
+ with m4:
209
+ st.markdown(f"""
210
+ <div class="metric-box">
211
+ <div class="metric-label">Oxygenation</div>
212
+ <div class="metric-value">{oxy:.0%}</div>
213
+ <div style="font-family: monospace; font-size: 12px; color: #666;">
214
+ Probability
215
+ </div>
216
+ </div>
217
+ """, unsafe_allow_html=True)
218
+
219
+ # Recommendation
220
+ st.markdown("<h2 style='color: #000000;'>Recommendation</h2>", unsafe_allow_html=True)
221
+
222
+ # Check if changed
223
+ if new_rr == patient["rr"] and new_vt == patient["vt"] and new_peep == patient["peep"]:
224
+ st.markdown("""
225
+ <div class="recommendation-box info">
226
+ <b style='color: #0c5460;'>CURRENT SETTINGS</b><br><br>
227
+ Adjust sliders to see predicted effects of ventilator parameter changes.<br>
228
+ Target: Reduce Mechanical Power while keeping mortality risk increase ≤ 1%.
229
+ </div>
230
+ """, unsafe_allow_html=True)
231
+
232
+ elif mp_reduction > 5 and (mort_7d - patient["mort_7d"]) <= 0.01:
233
+ st.markdown(f"""
234
+ <div class="recommendation-box success">
235
+ <b style='color: #155724;'>REDUCE MECHANICAL POWER</b><br><br>
236
+ <b>Current:</b> RR={patient['rr']}, VT={patient['vt']}, PEEP={patient['peep']}<br>
237
+ <b>Recommended:</b> RR={new_rr}, VT={new_vt}, PEEP={new_peep}<br><br>
238
+ Expected outcome: MP reduced by {mp_reduction:.1f}%<br>
239
+ Mortality risk: {patient['mort_7d']:.1%} → {mort_7d:.1%}<br>
240
+ 48h mortality: {patient['mort_48h']:.1%} → {mort_48h:.1%}
241
+ </div>
242
+ """, unsafe_allow_html=True)
243
+
244
+ elif (mort_7d - patient["mort_7d"]) > 0.01:
245
+ st.markdown("""
246
+ <div class="recommendation-box warning">
247
+ <b style='color: #856404;'>MAINTAIN CURRENT SETTINGS</b><br><br>
248
+ Proposed changes would increase mortality risk beyond safe threshold (+1% limit).<br>
249
+ Current settings are safer for this patient.
250
+ </div>
251
+ """, unsafe_allow_html=True)
252
+
253
+ else:
254
+ st.markdown(f"""
255
+ <div class="recommendation-box info">
256
+ <b style='color: #0c5460;'>MARGINAL BENEFIT</b><br><br>
257
+ MP reduction of {mp_reduction:.1f}% is achievable but minimal.<br>
258
+ Consider maintaining current settings unless other factors apply.
259
+ </div>
260
+ """, unsafe_allow_html=True)
261
+
262
+ # Simple chart
263
+ fig = go.Figure()
264
+ categories = ['MP (J/min)', 'Mortality 7d (%)', 'Mortality 48h (%)']
265
+ current_vals = [current_mp, patient["mort_7d"]*100, patient["mort_48h"]*100]
266
+ new_vals = [new_mp, mort_7d*100, mort_48h*100]
267
+
268
+ fig.add_trace(go.Bar(name='Current', x=categories, y=current_vals, marker_color='#6C757D'))
269
+ fig.add_trace(go.Bar(name='Proposed', x=categories, y=new_vals, marker_color='#0366D6'))
270
+
271
+ fig.update_layout(
272
+ barmode='group',
273
+ height=300,
274
+ paper_bgcolor='white',
275
+ plot_bgcolor='white',
276
+ font=dict(color='black'),
277
+ legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
278
+ margin=dict(l=40, r=40, t=60, b=40)
279
+ )
280
+
281
+ st.plotly_chart(fig, use_container_width=True)
282
+
283
+ st.markdown("---")
284
+ st.caption("IMPROVE Framework | CMC Vellore & Ashoka University | ESICM Datathon 2025")
requirements.txt CHANGED
@@ -1,3 +0,0 @@
1
- altair
2
- pandas
3
- streamlit