Spaces:
Runtime error
Runtime error
SonFox2920
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Initialize the transcriber
|
6 |
+
def initialize_transcriber():
|
7 |
+
return pipeline("automatic-speech-recognition",
|
8 |
+
model="vinai/PhoWhisper-medium",
|
9 |
+
device="cuda" if torch.cuda.is_available() else "cpu")
|
10 |
+
|
11 |
+
transcriber = initialize_transcriber()
|
12 |
+
|
13 |
+
# Function to transcribe audio
|
14 |
+
def transcribe_audio(audio_path):
|
15 |
+
try:
|
16 |
+
# Transcribe the audio
|
17 |
+
result = transcriber(audio_path)
|
18 |
+
transcribed_text = result["text"]
|
19 |
+
return transcribed_text
|
20 |
+
except Exception as e:
|
21 |
+
return f"Error during transcription: {str(e)}"
|
22 |
+
|
23 |
+
# Create the Gradio interface
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=transcribe_audio,
|
26 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
27 |
+
outputs="text",
|
28 |
+
title="Vietnamese Speech-to-Text",
|
29 |
+
description="Record audio in Vietnamese and get the transcription",
|
30 |
+
examples=[],
|
31 |
+
theme=gr.themes.Soft()
|
32 |
+
)
|
33 |
+
|
34 |
+
# Launch the app
|
35 |
+
if __name__ == "__main__":
|
36 |
+
interface.launch(share=True)
|