Sajjo commited on
Commit
45ee4ac
·
verified ·
1 Parent(s): ee22216

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
 
4
  HF_TOKEN = os.getenv('HW_Token')
5
  hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
 
6
  import gradio as gr
7
  import os
8
 
@@ -47,23 +48,27 @@ def save_audio_text(audio, text):
47
  # Debugging to print out the structure of the audio variable
48
  print("Received audio data:", audio)
49
 
50
- # Check if audio is a dictionary and contains 'data'
51
- if isinstance(audio, dict) and 'data' in audio:
52
- audio_data = audio['data']
53
- audio_path = f"/tmp/recordings/line_{reader.current_index}.wav"
54
- text_path = f"/tmp/recordings/line_{reader.current_index}.txt"
55
-
56
- with open(audio_path, "wb") as f:
57
- f.write(audio_data)
 
 
 
 
58
 
59
- with open(text_path, "w") as f:
60
- f.write(text)
61
-
62
- # Move to the next line after saving
63
- next_line = reader.forward_line()
64
- return next_line
65
- else:
66
- return "Audio data is not in the expected format."
67
 
68
  # Define the Gradio interface
69
  with gr.Blocks() as demo:
 
3
 
4
  HF_TOKEN = os.getenv('HW_Token')
5
  hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
6
+
7
  import gradio as gr
8
  import os
9
 
 
48
  # Debugging to print out the structure of the audio variable
49
  print("Received audio data:", audio)
50
 
51
+ try:
52
+ # Check if audio is a dictionary and contains 'data'
53
+ if isinstance(audio, dict) and 'data' in audio:
54
+ audio_data = audio['data']
55
+ audio_path = f"/tmp/recordings/line_{reader.current_index}.wav"
56
+ text_path = f"/tmp/recordings/line_{reader.current_index}.txt"
57
+
58
+ with open(audio_path, "wb") as f:
59
+ f.write(audio_data)
60
+
61
+ with open(text_path, "w") as f:
62
+ f.write(text)
63
 
64
+ # Move to the next line after saving
65
+ next_line = reader.forward_line()
66
+ return next_line
67
+ else:
68
+ return "Audio data is not in the expected format."
69
+ except Exception as e:
70
+ print(f"Error saving audio: {e}")
71
+ return "Error saving audio."
72
 
73
  # Define the Gradio interface
74
  with gr.Blocks() as demo: