Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
return "
|
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:
|