Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from transformers import pipeline
|
4 |
|
5 |
-
# Load
|
6 |
-
|
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
|
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 |
-
|
27 |
-
result =
|
28 |
-
|
|
|
29 |
except Exception as e:
|
30 |
-
return f"Error
|
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 |
-
|
38 |
-
|
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 |
-
|
59 |
-
if __name__ == "__main__":
|
60 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from tone import StreamingCTCPipeline, read_audio
|
|
|
3 |
|
4 |
+
# Load model once at startup
|
5 |
+
pipe = StreamingCTCPipeline.from_hugging_face()
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def transcribe(audio_path):
|
8 |
+
if audio_path is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
return "Please upload an audio file."
|
|
|
10 |
try:
|
11 |
+
audio = read_audio(audio_path)
|
12 |
+
result = pipe.forward_offline(audio)
|
13 |
+
# result: list of TextPhrase with text, start_time, end_time
|
14 |
+
return "\n".join([x.text for x in result])
|
15 |
except Exception as e:
|
16 |
+
return f"Error: {str(e)}"
|
17 |
|
|
|
18 |
with gr.Blocks(title="T-one ASR Demo") as demo:
|
19 |
gr.Markdown("# T-one Automatic Speech Recognition Demo")
|
20 |
gr.Markdown("Upload an audio file to get real-time transcription using the t-tech/T-one model.")
|
21 |
+
audio_input = gr.Audio(label="Upload Audio File", type="filepath")
|
22 |
+
text_output = gr.Textbox(label="Transcription", placeholder="Transcribed text will appear here...", lines=5)
|
23 |
+
audio_input.change(transcribe, inputs=audio_input, outputs=text_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
demo.launch()
|
|
|
|