|
from transformers import pipeline |
|
import gradio as gr |
|
import os |
|
|
|
|
|
asr = pipeline(task="automatic-speech-recognition", model="openai/whisper-small") |
|
|
|
|
|
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'] |
|
|
|
|
|
css = """ |
|
body { font-family: Arial, sans-serif; } |
|
button { background-color: #4CAF50; color: white; border: none; padding: 10px 20px; } |
|
""" |
|
|
|
|
|
with gr.Blocks(css=css) as demo: |
|
gr.Markdown("### Audio Transcription Service") |
|
gr.Markdown("Upload an audio file or use your microphone to record one. Then press the 'Transcribe' button to see the transcription.") |
|
with gr.Tab("Transcribe Audio"): |
|
with gr.Row(): |
|
audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Upload or Record Audio") |
|
submit_button = gr.Button("Transcribe") |
|
transcription_output = gr.Textbox(label="Transcription", lines=10, placeholder="Your transcription will appear here...") |
|
|
|
submit_button.click( |
|
transcribe_long_form, |
|
inputs=[audio_input], |
|
outputs=[transcription_output] |
|
) |
|
|
|
|
|
demo.launch(share=True, server_port=int(os.environ.get('PORT1', 7860))) |
|
|