Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,10 @@ import gradio as gr
|
|
6 |
import spaces
|
7 |
from transformers import pipeline
|
8 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
|
|
|
|
|
|
|
|
9 |
|
10 |
DEFAULT_MODEL_NAME = "distil-whisper/distil-large-v3"
|
11 |
BATCH_SIZE = 8
|
@@ -140,6 +144,23 @@ def handle_upload_audio(audio_path,model_name,old_transcription=''):
|
|
140 |
(text,transcription_time_output)=transcribe(audio_path,model_name)
|
141 |
return text+'\n\n'+old_transcription, transcription_time_output
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
graudio=gr.Audio(type="filepath",show_download_button=True)
|
144 |
grmodel_textbox=gr.Textbox(
|
145 |
label="Model Name",
|
@@ -172,7 +193,20 @@ demo = gr.Blocks()
|
|
172 |
|
173 |
|
174 |
with demo:
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
with gr.Row():
|
178 |
refresh_button = gr.Button("Refresh Status") # Create a refresh button
|
|
|
6 |
import spaces
|
7 |
from transformers import pipeline
|
8 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
9 |
+
import base64
|
10 |
+
import requests
|
11 |
+
|
12 |
+
|
13 |
|
14 |
DEFAULT_MODEL_NAME = "distil-whisper/distil-large-v3"
|
15 |
BATCH_SIZE = 8
|
|
|
144 |
(text,transcription_time_output)=transcribe(audio_path,model_name)
|
145 |
return text+'\n\n'+old_transcription, transcription_time_output
|
146 |
|
147 |
+
def handle_base64_audio(base64_data, model_name, old_transcription=''):
|
148 |
+
# Decode base64 data and save it as a temporary audio file
|
149 |
+
binary_data = base64.b64decode(base64_data)
|
150 |
+
audio_path = "temp_audio.wav"
|
151 |
+
with open(audio_path, "wb") as f:
|
152 |
+
f.write(binary_data)
|
153 |
+
|
154 |
+
# Transcribe the audio file
|
155 |
+
(text, transcription_time_output) = transcribe(audio_path, model_name)
|
156 |
+
|
157 |
+
# Remove the temporary audio file
|
158 |
+
import os
|
159 |
+
os.remove(audio_path)
|
160 |
+
|
161 |
+
return text + '\n\n' + old_transcription, transcription_time_output
|
162 |
+
|
163 |
+
|
164 |
graudio=gr.Audio(type="filepath",show_download_button=True)
|
165 |
grmodel_textbox=gr.Textbox(
|
166 |
label="Model Name",
|
|
|
193 |
|
194 |
|
195 |
with demo:
|
196 |
+
gr.TabbedInterface(
|
197 |
+
[
|
198 |
+
mf_transcribe,
|
199 |
+
gr.Interface(
|
200 |
+
fn=handle_base64_audio,
|
201 |
+
inputs=[
|
202 |
+
gr.Textbox(label="Base64 Audio Data URL", placeholder="Enter the base64 audio data URL"),
|
203 |
+
grmodel_textbox,
|
204 |
+
],
|
205 |
+
outputs=groutputs,
|
206 |
+
),
|
207 |
+
],
|
208 |
+
["Audio", "Base64 Audio Data URL"],
|
209 |
+
)
|
210 |
|
211 |
with gr.Row():
|
212 |
refresh_button = gr.Button("Refresh Status") # Create a refresh button
|