Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import torch | |
# Initialize the transcriber | |
def initialize_transcriber(): | |
return pipeline("automatic-speech-recognition", | |
model="vinai/PhoWhisper-medium", | |
device="cuda" if torch.cuda.is_available() else "cpu") | |
transcriber = initialize_transcriber() | |
# Function to transcribe audio | |
def transcribe_audio(audio_path): | |
try: | |
# Transcribe the audio | |
result = transcriber(audio_path) | |
transcribed_text = result["text"] | |
return transcribed_text | |
except Exception as e: | |
return f"Error during transcription: {str(e)}" | |
# Create the Gradio interface | |
interface = gr.Interface( | |
fn=transcribe_audio, | |
inputs=gr.Audio(source="microphone", type="filepath"), | |
outputs="text", | |
title="Vietnamese Speech-to-Text", | |
description="Record audio in Vietnamese and get the transcription", | |
examples=[], | |
theme=gr.themes.Soft() | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
interface.launch(share=True) |