niol08 commited on
Commit
117b655
Β·
verified Β·
1 Parent(s): d88eb7e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +47 -92
src/streamlit_app.py CHANGED
@@ -93,103 +93,58 @@ for tab, sig in zip(tabs, ["ECG", "EMG", "VAG", "PCG"]):
93
  "_Note: Do not upload `.mp3`, `.flac`, or stereo filesβ€”they may fail to process properly._"
94
  )
95
 
96
- # Replace your file uploader section with this corrected version:
97
-
98
- # Initialize session state
99
- if f"uploaded_file_{sig}" not in st.session_state:
100
- st.session_state[f"uploaded_file_{sig}"] = None
101
-
102
- # File uploader with proper callback
103
- def handle_file_upload():
104
- st.session_state[f"uploaded_file_{sig}"] = st.session_state[f"upload_{sig}"]
105
-
106
  uploaded = st.file_uploader(
107
  f"Upload {sig} file",
108
  type=FILE_TYPES[sig],
109
- key=f"upload_{sig}",
110
- on_change=handle_file_upload
111
  )
112
-
113
- # Check if file was uploaded
114
- if uploaded is not None:
115
- st.session_state[f"uploaded_file_{sig}"] = uploaded
116
- st.success(f"βœ… File uploaded: {uploaded.name} ({uploaded.size} bytes)")
117
-
118
- # Show file details
119
- col1, col2 = st.columns(2)
120
- with col1:
121
- st.info(f"πŸ“ **Filename:** {uploaded.name}")
122
- st.info(f"🏷️ **Type:** {uploaded.type}")
123
- with col2:
124
- st.info(f"πŸ“ **Size:** {uploaded.size} bytes")
125
- st.info(f"βœ… **Status:** Ready for analysis")
126
-
127
- elif st.session_state[f"uploaded_file_{sig}"] is not None:
128
- uploaded = st.session_state[f"uploaded_file_{sig}"]
129
- st.info(f"πŸ“ Using previously uploaded file: {uploaded.name}")
130
- else:
131
- st.warning("⚠️ No file uploaded yet")
132
- st.info(f"πŸ’‘ Supported formats: {', '.join(FILE_TYPES[sig])}")
133
-
134
- # Add control buttons
135
- col1, col2 = st.columns([1, 1])
136
- with col1:
137
- if st.button(f"πŸ”„ Refresh", key=f"refresh_{sig}"):
138
- st.rerun()
139
-
140
- with col2:
141
- if st.session_state[f"uploaded_file_{sig}"] is not None:
142
- if st.button(f"πŸ—‘οΈ Clear File", key=f"clear_{sig}"):
143
- st.session_state[f"uploaded_file_{sig}"] = None
144
- st.rerun()
145
-
146
- # Your existing analysis buttons (keep them the same, but check session state)
147
- if st.session_state[f"uploaded_file_{sig}"] is not None:
148
- uploaded = st.session_state[f"uploaded_file_{sig}"]
149
 
150
- if sig == "ECG" and st.button("Run Diagnostic", key=f"run_{sig}"):
151
- label, human, conf, gnote = analyze_signal(
152
- uploaded, MODELS["ECG"], GEMINI_API_KEY, signal_type="ECG"
153
- )
154
- st.success(f"**{label} – {human}**\n\nConfidence: {conf:.2%}")
155
- if gnote:
156
- st.markdown("### 🧠 Gemini Insight")
157
- st.write(gnote)
158
- elif not GEMINI_API_KEY:
159
- st.info("Gemini key missing – no explanation.")
160
-
161
- elif sig == "PCG" and st.button("Run Diagnostic", key=f"run_{sig}"):
162
- label, human, conf, gnote = analyze_pcg_signal(
163
- uploaded, MODELS["PCG"], GEMINI_API_KEY
164
- )
165
- st.success(f"**{label}**\n\nConfidence: {conf:.2%}")
166
- if gnote:
167
- st.markdown("### 🧠 Gemini Insight")
168
- st.write(gnote)
169
- elif not GEMINI_API_KEY:
170
- st.info("Gemini key missing – no explanation.")
171
-
172
- elif sig == "EMG" and st.button("Run Diagnostic", key=f"run_{sig}"):
173
- human, conf, gnote = analyze_emg_signal(
174
- uploaded, MODELS["EMG"], GEMINI_API_KEY
175
- )
176
- st.success(f"**{human.upper()}**\n\nConfidence: {conf:.2%}")
177
- if gnote:
178
- st.markdown("### 🧠 Gemini Insight")
179
- st.write(gnote)
180
- elif not GEMINI_API_KEY:
181
- st.info("Gemini key missing – no explanation.")
182
-
183
- elif sig == "VAG" and st.button("Run Diagnostic", key=f"run_{sig}"):
184
- label, human, conf, gnote = predict_vag_from_features(
185
- uploaded, MODELS["VAG"], GEMINI_API_KEY
186
- )
187
- st.success(f"**{label}**\n\nConfidence: {conf:.2%}")
188
- if gnote:
189
- st.markdown("### 🧠 Gemini Insight")
190
- st.write(gnote)
191
- elif not GEMINI_API_KEY:
192
- st.info("Gemini key missing – no explanation.")
193
  else:
194
  st.info("πŸ“€ Upload a file to begin analysis")
195
 
 
93
  "_Note: Do not upload `.mp3`, `.flac`, or stereo filesβ€”they may fail to process properly._"
94
  )
95
 
 
 
 
 
 
 
 
 
 
 
96
  uploaded = st.file_uploader(
97
  f"Upload {sig} file",
98
  type=FILE_TYPES[sig],
99
+ key=f"upload_{sig}"
 
100
  )
101
+
102
+
103
+ if sig == "ECG" and uploaded and st.button("Run Diagnostic", key=f"run_{sig}"):
104
+ label, human, conf, gnote = analyze_signal(
105
+ uploaded, MODELS["ECG"], GEMINI_API_KEY, signal_type="ECG"
106
+ )
107
+ st.success(f"**{label} – {human}**\n\nConfidence: {conf:.2%}")
108
+ if gnote:
109
+ st.markdown("### 🧠 Gemini Insight")
110
+ st.write(gnote)
111
+ elif not GEMINI_API_KEY:
112
+ st.info("Gemini key missing – no explanation.")
113
+
114
+
115
+ elif sig == "PCG" and uploaded and st.button("Run Diagnostic", key=f"run_{sig}"):
116
+ label, human, conf, gnote = analyze_pcg_signal(
117
+ uploaded, MODELS["PCG"], GEMINI_API_KEY
118
+ )
119
+ st.success(f"**{label}**\n\nConfidence: {conf:.2%}")
120
+ if gnote:
121
+ st.markdown("### 🧠 Gemini Insight")
122
+ st.write(gnote)
123
+ elif not GEMINI_API_KEY:
124
+ st.info("Gemini key missing – no explanation.")
125
+
126
+ elif sig == "EMG" and uploaded and st.button("Run Diagnostic", key=f"run_{sig}"):
127
+ human, conf, gnote = analyze_emg_signal(
128
+ uploaded, MODELS["EMG"], GEMINI_API_KEY
129
+ )
130
+ st.success(f"**{human.upper()}**\n\nConfidence: {conf:.2%}")
131
+ if gnote:
132
+ st.markdown("### 🧠 Gemini Insight")
133
+ st.write(gnote)
134
+ elif not GEMINI_API_KEY:
135
+ st.info("Gemini key missing – no explanation.")
136
+
137
+ elif sig == "VAG" and uploaded and st.button("Run Diagnostic", key=f"run_{sig}"):
138
 
139
+ label, human, conf, gnote = predict_vag_from_features(
140
+ uploaded, MODELS["VAG"], GEMINI_API_KEY
141
+ )
142
+ st.success(f"**{label}**\n\nConfidence: {conf:.2%}")
143
+ if gnote:
144
+ st.markdown("### 🧠 Gemini Insight")
145
+ st.write(gnote)
146
+ elif not GEMINI_API_KEY:
147
+ st.info("Gemini key missing – no explanation.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  else:
149
  st.info("πŸ“€ Upload a file to begin analysis")
150