File size: 1,040 Bytes
202afe1 fe7eb34 f28ce48 202afe1 f28ce48 202afe1 9e88205 202afe1 f28ce48 fe7eb34 f28ce48 fe7eb34 f28ce48 fe7eb34 f28ce48 fe7eb34 f28ce48 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from transformers import pipeline
import gradio as gr
import os
# Load the ASR model
asr = pipeline(task="automatic-speech-recognition",
model="distil-whisper/distil-small.en")
# Define the transcription function
def transcribe_long_form(filepath):
if filepath is None:
return "No audio file provided, please upload a file or record one."
output = asr(filepath)
return output['text']
# Set up the Gradio interface
with gr.Blocks() as demo:
with gr.Tab("Transcribe Audio"):
with gr.Row():
audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
submit_button = gr.Button("Transcribe")
transcription_output = gr.Textbox(label="Transcription", lines=3)
submit_button.click(
transcribe_long_form,
inputs=[audio_input],
outputs=[transcription_output]
)
# Launch the Gradio app
demo.launch(share=True, server_port=int(os.environ.get('PORT1', 7860))) # Default port 7860 if PORT1 is not set
|