Spaces:
Sleeping
Sleeping
Commit
·
cd95449
1
Parent(s):
a2ad006
replaced recording with uploading
Browse files
app.py
CHANGED
@@ -287,68 +287,86 @@ def GenerateText(emo,gpt_tokenizer,gpt_model):
|
|
287 |
def process_file(ser_model,tokenizer,gpt_model,gpt_tokenizer):
|
288 |
emo = ""
|
289 |
button_label = "Show Helpful Tips"
|
290 |
-
|
291 |
|
292 |
-
|
293 |
-
|
294 |
|
295 |
def set_stage(stage):
|
296 |
st.session_state.stage = stage
|
297 |
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
|
353 |
txt = f"You seem to be <b>{(emo2promptMapping[emo]).capitalize()}!</b>\n Click on 'Show Helpful Tips' button to proceed further."
|
354 |
st.markdown(f"<div class='mobile-screen' style='font-size: 24px;'>{txt} </div>", unsafe_allow_html=True)
|
@@ -356,11 +374,11 @@ def process_file(ser_model,tokenizer,gpt_model,gpt_tokenizer):
|
|
356 |
# Store the value of emo in the session state
|
357 |
st.session_state.emo = emo
|
358 |
|
359 |
-
except OSError as e:
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
|
365 |
if st.session_state.stage > 0:
|
366 |
if st.button(button_label,on_click=set_stage, args=(2,)):
|
|
|
287 |
def process_file(ser_model,tokenizer,gpt_model,gpt_tokenizer):
|
288 |
emo = ""
|
289 |
button_label = "Show Helpful Tips"
|
290 |
+
# recorded = False # Initialize the recording state as False
|
291 |
|
292 |
+
# if 'stage' not in st.session_state:
|
293 |
+
# st.session_state.stage = 0
|
294 |
|
295 |
def set_stage(stage):
|
296 |
st.session_state.stage = stage
|
297 |
|
298 |
+
# # Add custom CSS styles
|
299 |
+
# st.markdown("""
|
300 |
+
# <style>
|
301 |
+
# .stRecordButton {
|
302 |
+
# width: 50px;
|
303 |
+
# height: 50px;
|
304 |
+
# border-radius: 50px;
|
305 |
+
# background-color: red;
|
306 |
+
# color: black; /* Text color */
|
307 |
+
# font-size: 16px;
|
308 |
+
# font-weight: bold;
|
309 |
+
# border: 2px solid white; /* Solid border */
|
310 |
+
# box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
311 |
+
# cursor: pointer;
|
312 |
+
# transition: background-color 0.2s;
|
313 |
+
# display: flex;
|
314 |
+
# justify-content: center;
|
315 |
+
# align-items: center;
|
316 |
+
# }
|
317 |
+
|
318 |
+
# .stRecordButton:hover {
|
319 |
+
# background-color: darkred; /* Change background color on hover */
|
320 |
+
# }
|
321 |
+
# </style>
|
322 |
+
# """, unsafe_allow_html=True)
|
323 |
+
|
324 |
+
# if st.sidebar.button("Record a 4 sec audio!", key="record_button", help="Click to start recording", on_click=set_stage, args=(1,)):
|
325 |
+
# # Your button click action here
|
326 |
+
|
327 |
+
# # Apply bold styling to the button label
|
328 |
+
# st.sidebar.markdown("<span style='font-weight: bolder;'>Record a 4 sec audio!</span>", unsafe_allow_html=True)
|
329 |
+
|
330 |
+
# # recorded = True # Set the recording state to True after recording
|
331 |
+
|
332 |
+
# # Add your audio recording code here
|
333 |
+
# output_wav_file = "output.wav"
|
334 |
+
|
335 |
+
# try:
|
336 |
+
# record_audio(output_wav_file, duration=4)
|
337 |
|
338 |
+
# # # Use a div to encapsulate the audio element and apply the border
|
339 |
+
# with st.sidebar.markdown('<div class="audio-container">', unsafe_allow_html=True):
|
340 |
+
# # Play recorded sound
|
341 |
+
# st.audio(output_wav_file, format="wav")
|
342 |
+
uploaded_file = st.file_uploader("Upload your file! It should be .wav", type=["wav"])
|
343 |
+
|
344 |
+
if uploaded_file is not None:
|
345 |
+
# Read the content of the uploaded file
|
346 |
+
audio_content = uploaded_file.read()
|
347 |
+
# Display audio file
|
348 |
+
st.audio(audio_content, format="audio/wav")
|
349 |
+
|
350 |
+
# Save the audio content to a temporary file
|
351 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
352 |
+
temp_filename = temp_file.name
|
353 |
+
#print(f'temp_filename is {temp_filename}\n')
|
354 |
+
temp_file.write(audio_content)
|
355 |
+
|
356 |
+
try:
|
357 |
+
|
358 |
+
audio_array, sr = librosa.load(preprocessWavFile(temp_filename), sr=None)
|
359 |
+
st.sidebar.markdown("<p style='font-size: 14px; font-weight: bold;'>Generating transcriptions! Please wait...</p>", unsafe_allow_html=True)
|
360 |
+
|
361 |
+
transcription = speechtoText(temp_filename)
|
362 |
+
|
363 |
+
emo = predict(audio_array,ser_model,2,tokenizer,transcription)
|
364 |
+
|
365 |
+
# Display the transcription in a textbox
|
366 |
+
st.sidebar.text_area("Transcription", transcription, height=25)
|
367 |
+
except:
|
368 |
+
st.write("Inference impossible, a problem occurred with your audio or your parameters, we apologize :(")
|
369 |
+
|
370 |
|
371 |
txt = f"You seem to be <b>{(emo2promptMapping[emo]).capitalize()}!</b>\n Click on 'Show Helpful Tips' button to proceed further."
|
372 |
st.markdown(f"<div class='mobile-screen' style='font-size: 24px;'>{txt} </div>", unsafe_allow_html=True)
|
|
|
374 |
# Store the value of emo in the session state
|
375 |
st.session_state.emo = emo
|
376 |
|
377 |
+
# except OSError as e:
|
378 |
+
# if "[Errno -9996]" in str(e) and "Invalid input device (no default output device)" in str(e):
|
379 |
+
# st.error("Recording not possible as no input device on cloud platforms. Please upload instead.")
|
380 |
+
# else:
|
381 |
+
# st.error(f"An error occurred while recording: {str(e)}")
|
382 |
|
383 |
if st.session_state.stage > 0:
|
384 |
if st.button(button_label,on_click=set_stage, args=(2,)):
|