Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,10 +17,16 @@ def transcribe(file):
|
|
| 17 |
#print("filename: ",file)
|
| 18 |
# print("microphone: ",microphone)
|
| 19 |
# print("uploaded file: ",file)
|
| 20 |
-
if microphone:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
file_name = file
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
try:
|
| 25 |
audio = AudioSegment.from_file(file_name)
|
| 26 |
if audio.frame_rate != 16000:
|
|
@@ -53,9 +59,17 @@ with gr.Blocks() as demo:
|
|
| 53 |
transcription = gr.Textbox(type="text", label="Transcription")
|
| 54 |
with gr.Row():
|
| 55 |
transcribe_button = gr.Button("Transcribe")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
transcribe_button.click(
|
| 58 |
-
|
| 59 |
[microphone, uploaded_audio],
|
| 60 |
transcription
|
| 61 |
)
|
|
|
|
| 17 |
#print("filename: ",file)
|
| 18 |
# print("microphone: ",microphone)
|
| 19 |
# print("uploaded file: ",file)
|
| 20 |
+
# if microphone:
|
| 21 |
+
# file_name = file
|
| 22 |
+
# elif file:
|
| 23 |
+
# file_name = file
|
| 24 |
+
if file:
|
| 25 |
file_name = file
|
| 26 |
+
|
| 27 |
+
if not file_name:
|
| 28 |
+
return "No audio file provided."
|
| 29 |
+
|
| 30 |
try:
|
| 31 |
audio = AudioSegment.from_file(file_name)
|
| 32 |
if audio.frame_rate != 16000:
|
|
|
|
| 59 |
transcription = gr.Textbox(type="text", label="Transcription")
|
| 60 |
with gr.Row():
|
| 61 |
transcribe_button = gr.Button("Transcribe")
|
| 62 |
+
|
| 63 |
+
def handle_audio(microphone, uploaded_audio):
|
| 64 |
+
if microphone:
|
| 65 |
+
return transcribe(microphone)
|
| 66 |
+
elif uploaded_audio:
|
| 67 |
+
return transcribe(uploaded_audio)
|
| 68 |
+
else:
|
| 69 |
+
return "No audio file provided."
|
| 70 |
|
| 71 |
transcribe_button.click(
|
| 72 |
+
handle_audio,
|
| 73 |
[microphone, uploaded_audio],
|
| 74 |
transcription
|
| 75 |
)
|