Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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 |
-
|
114 |
-
if uploaded
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
st.
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
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 |
|