Spaces:
Sleeping
Sleeping
Add basic ASR demo app with t-tech/T-one model
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load the ASR model
|
6 |
+
# Using the t-tech/T-one model for automatic speech recognition
|
7 |
+
asr_pipeline = pipeline(
|
8 |
+
"automatic-speech-recognition",
|
9 |
+
model="t-tech/T-one",
|
10 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
11 |
+
device=0 if torch.cuda.is_available() else -1
|
12 |
+
)
|
13 |
+
|
14 |
+
def transcribe_audio(audio_file):
|
15 |
+
"""
|
16 |
+
Transcribe audio file using the T-one ASR model
|
17 |
+
Args:
|
18 |
+
audio_file: Audio file uploaded by user
|
19 |
+
Returns:
|
20 |
+
str: Transcribed text
|
21 |
+
"""
|
22 |
+
if audio_file is None:
|
23 |
+
return "Please upload an audio file."
|
24 |
+
|
25 |
+
try:
|
26 |
+
# Transcribe the audio
|
27 |
+
result = asr_pipeline(audio_file)
|
28 |
+
return result["text"]
|
29 |
+
except Exception as e:
|
30 |
+
return f"Error during transcription: {str(e)}"
|
31 |
+
|
32 |
+
# Create Gradio interface
|
33 |
+
with gr.Blocks(title="T-one ASR Demo") as demo:
|
34 |
+
gr.Markdown("# T-one Automatic Speech Recognition Demo")
|
35 |
+
gr.Markdown("Upload an audio file to get real-time transcription using the t-tech/T-one model.")
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
# Audio input component
|
39 |
+
audio_input = gr.Audio(
|
40 |
+
label="Upload Audio File",
|
41 |
+
type="filepath"
|
42 |
+
)
|
43 |
+
|
44 |
+
# Text output component
|
45 |
+
text_output = gr.Textbox(
|
46 |
+
label="Transcription",
|
47 |
+
placeholder="Transcribed text will appear here...",
|
48 |
+
lines=5
|
49 |
+
)
|
50 |
+
|
51 |
+
# Set up the transcription function to run when audio is uploaded
|
52 |
+
audio_input.change(
|
53 |
+
fn=transcribe_audio,
|
54 |
+
inputs=audio_input,
|
55 |
+
outputs=text_output
|
56 |
+
)
|
57 |
+
|
58 |
+
# Launch the app
|
59 |
+
if __name__ == "__main__":
|
60 |
+
demo.launch()
|