Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,9 @@ import os
|
|
4 |
HF_TOKEN = os.getenv('HW_Token')
|
5 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
|
6 |
|
|
|
|
|
|
|
7 |
class TextFileReader:
|
8 |
def __init__(self):
|
9 |
self.lines = []
|
@@ -41,18 +44,27 @@ def save_text_lines(file):
|
|
41 |
def save_audio_text(audio, text):
|
42 |
if not os.path.exists("/tmp/recordings"):
|
43 |
os.makedirs("/tmp/recordings")
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
# Define the Gradio interface
|
58 |
with gr.Blocks() as demo:
|
@@ -70,7 +82,7 @@ with gr.Blocks() as demo:
|
|
70 |
generate_button.click(fn=update_output, inputs=file_upload, outputs=current_line)
|
71 |
|
72 |
with gr.Row():
|
73 |
-
audio_record =
|
74 |
save_button = gr.Button("Save Audio and Next Line")
|
75 |
|
76 |
save_button.click(fn=save_audio_text, inputs=[audio_record, current_line], outputs=current_line)
|
|
|
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 |
+
|
10 |
class TextFileReader:
|
11 |
def __init__(self):
|
12 |
self.lines = []
|
|
|
44 |
def save_audio_text(audio, text):
|
45 |
if not os.path.exists("/tmp/recordings"):
|
46 |
os.makedirs("/tmp/recordings")
|
47 |
+
|
48 |
+
# Debugging to print out the structure of the audio variable
|
49 |
+
print(audio)
|
50 |
+
|
51 |
+
# Check if audio is a dictionary and contains 'data'
|
52 |
+
if isinstance(audio, dict) and 'data' in audio:
|
53 |
+
audio_data = audio['data']
|
54 |
+
audio_path = f"/tmp/recordings/line_{reader.current_index}.wav"
|
55 |
+
text_path = f"/tmp/recordings/line_{reader.current_index}.txt"
|
56 |
|
57 |
+
with open(audio_path, "wb") as f:
|
58 |
+
f.write(audio_data)
|
59 |
+
|
60 |
+
with open(text_path, "w") as f:
|
61 |
+
f.write(text)
|
62 |
+
|
63 |
+
# Move to the next line after saving
|
64 |
+
next_line = reader.forward_line()
|
65 |
+
return next_line
|
66 |
+
else:
|
67 |
+
return "Audio data is not in the expected format."
|
68 |
|
69 |
# Define the Gradio interface
|
70 |
with gr.Blocks() as demo:
|
|
|
82 |
generate_button.click(fn=update_output, inputs=file_upload, outputs=current_line)
|
83 |
|
84 |
with gr.Row():
|
85 |
+
audio_record = gr.Audio(sources=["microphone","upload"], type="filepath")
|
86 |
save_button = gr.Button("Save Audio and Next Line")
|
87 |
|
88 |
save_button.click(fn=save_audio_text, inputs=[audio_record, current_line], outputs=current_line)
|