Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -110,32 +110,38 @@ elif input_mode == "Audio Upload":
|
|
110 |
|
111 |
if audio_input_mode == "Upload Audio File":
|
112 |
uploaded_file = st.file_uploader("Upload audio file (WAV, MP3, M4A, MPEG)", type=["wav", "mp3", "m4a", "mpeg"])
|
|
|
113 |
if uploaded_file:
|
114 |
st.audio(uploaded_file, format='audio/wav')
|
115 |
audio = AudioSegment.from_file(uploaded_file)
|
116 |
-
|
117 |
-
audio
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
135 |
|
136 |
elif audio_input_mode == "Record Audio":
|
137 |
-
audio =
|
138 |
-
|
|
|
139 |
st.audio(audio.tobytes(), format="audio/wav")
|
140 |
wav_io = io.BytesIO(audio.tobytes())
|
141 |
|
@@ -153,4 +159,6 @@ elif input_mode == "Audio Upload":
|
|
153 |
else:
|
154 |
st.warning("Could not extract complete information from recorded audio.")
|
155 |
except Exception as e:
|
156 |
-
st.error(f"Recording processing error: {e}")
|
|
|
|
|
|
110 |
|
111 |
if audio_input_mode == "Upload Audio File":
|
112 |
uploaded_file = st.file_uploader("Upload audio file (WAV, MP3, M4A, MPEG)", type=["wav", "mp3", "m4a", "mpeg"])
|
113 |
+
|
114 |
if uploaded_file:
|
115 |
st.audio(uploaded_file, format='audio/wav')
|
116 |
audio = AudioSegment.from_file(uploaded_file)
|
117 |
+
|
118 |
+
if audio is not None and len(audio) > 0:
|
119 |
+
wav_io = io.BytesIO()
|
120 |
+
audio.export(wav_io, format="wav")
|
121 |
+
wav_io.seek(0)
|
122 |
+
|
123 |
+
recognizer = sr.Recognizer()
|
124 |
+
with sr.AudioFile(wav_io) as source:
|
125 |
+
audio_data = recognizer.record(source)
|
126 |
+
|
127 |
+
try:
|
128 |
+
text = recognizer.recognize_google(audio_data)
|
129 |
+
st.markdown(f"**Transcribed Text:** _{text}_")
|
130 |
+
values = extract_details_from_text(text)
|
131 |
+
if all(v is not None for v in values):
|
132 |
+
diagnosis = get_prediction(*values)
|
133 |
+
st.success(f"🩺 **Predicted Diagnosis:** {diagnosis}")
|
134 |
+
else:
|
135 |
+
st.warning("Could not extract complete information from audio.")
|
136 |
+
except Exception as e:
|
137 |
+
st.error(f"Audio processing error: {e}")
|
138 |
+
else:
|
139 |
+
st.error("Uploaded audio file is empty or not valid.")
|
140 |
|
141 |
elif audio_input_mode == "Record Audio":
|
142 |
+
audio = audiorecorder("Click to record", "Recording...")
|
143 |
+
|
144 |
+
if audio is not None and len(audio) > 0: # Check if audio is not None and has length
|
145 |
st.audio(audio.tobytes(), format="audio/wav")
|
146 |
wav_io = io.BytesIO(audio.tobytes())
|
147 |
|
|
|
159 |
else:
|
160 |
st.warning("Could not extract complete information from recorded audio.")
|
161 |
except Exception as e:
|
162 |
+
st.error(f"Recording processing error: {e}")
|
163 |
+
else:
|
164 |
+
st.error("No audio recorded or audio is empty.")
|