Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,28 @@
|
|
1 |
import torch
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
#
|
7 |
-
pipe = pipeline(
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
)
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
1 |
import torch
|
2 |
from transformers import pipeline
|
3 |
+
import gradio as gr
|
4 |
|
5 |
+
# Function to transcribe audio using the OpenAI Whisper model
|
6 |
+
def transcript_audio(audio_file):
|
7 |
+
# Initialize the speech recognition pipeline
|
8 |
+
pipe = pipeline(
|
9 |
+
"automatic-speech-recognition",
|
10 |
+
model="openai/whisper-tiny.en",
|
11 |
+
chunk_length_s=30,
|
12 |
+
)
|
13 |
+
# Transcribe the audio file and return the result
|
14 |
+
result = pipe(audio_file, batch_size=8)["text"]
|
15 |
+
return result
|
16 |
|
17 |
+
# Set up Gradio interface
|
18 |
+
audio_input = gr.Audio(sources="upload", type="filepath") # Audio input
|
19 |
+
output_text = gr.Textbox() # Text output
|
20 |
|
21 |
+
# Create the Gradio interface with the function, inputs, and outputs
|
22 |
+
iface = gr.Interface(fn=transcript_audio,
|
23 |
+
inputs=audio_input, outputs=output_text,
|
24 |
+
title="Audio Transcription App",
|
25 |
+
description="Upload the audio file")
|
26 |
|
27 |
+
# Launch the Gradio app
|
28 |
+
iface.launch()
|