Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,31 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
|
|
|
| 4 |
asr = pipeline(task="automatic-speech-recognition",
|
| 5 |
model="./models/distil-whisper/distil-small.en")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
def transcribe_long_form(filepath):
|
| 10 |
if filepath is None:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
output
|
| 14 |
-
filepath,
|
| 15 |
-
max_new_tokens=256,
|
| 16 |
-
chunk_length_s=30,
|
| 17 |
-
batch_size=8,
|
| 18 |
-
)
|
| 19 |
-
return output["text"]
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
lines=3),
|
| 35 |
-
allow_flagging="never",
|
| 36 |
-
)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
[mic_transcribe,
|
| 41 |
-
file_transcribe],
|
| 42 |
-
["Transcribe Microphone",
|
| 43 |
-
"Transcribe Audio File"],
|
| 44 |
-
)
|
| 45 |
-
demo.launch(share=True,
|
| 46 |
-
server_port=int(os.environ['PORT1']))
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Load the ASR model
|
| 6 |
asr = pipeline(task="automatic-speech-recognition",
|
| 7 |
model="./models/distil-whisper/distil-small.en")
|
| 8 |
|
| 9 |
+
# Define the transcription function
|
|
|
|
| 10 |
def transcribe_long_form(filepath):
|
| 11 |
if filepath is None:
|
| 12 |
+
return "No audio file provided, please upload a file or record one."
|
| 13 |
+
output = asr(filepath)
|
| 14 |
+
return output['text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Set up the Gradio interface
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
with gr.Tab("Transcribe Audio"):
|
| 19 |
+
with gr.Row():
|
| 20 |
+
audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
|
| 21 |
+
submit_button = gr.Button("Transcribe")
|
| 22 |
+
transcription_output = gr.Textbox(label="Transcription", lines=3)
|
| 23 |
|
| 24 |
+
submit_button.click(
|
| 25 |
+
transcribe_long_form,
|
| 26 |
+
inputs=[audio_input],
|
| 27 |
+
outputs=[transcription_output]
|
| 28 |
+
)
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Launch the Gradio app
|
| 31 |
+
demo.launch(share=True, server_port=int(os.environ.get('PORT1', 7860))) # Default port 7860 if PORT1 is not set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|