Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
import logging
|
3 |
from transformers import pipeline
|
4 |
-
import torch
|
5 |
|
|
|
6 |
logging.basicConfig(level=logging.INFO)
|
7 |
|
8 |
-
# Load
|
9 |
asr = pipeline(task="automatic-speech-recognition", model="openai/whisper-tiny.en")
|
10 |
|
11 |
-
|
12 |
-
|
|
|
13 |
logging.error("No audio provided.")
|
14 |
return "No audio found, please retry."
|
15 |
|
16 |
try:
|
17 |
-
logging.info("Received audio
|
18 |
-
|
19 |
-
# Hugging Face Whisper expects a 1D array or file path
|
20 |
-
output = asr(audio_array, sampling_rate=sample_rate)
|
21 |
return output["text"]
|
22 |
except Exception as e:
|
23 |
logging.error(f"Error during transcription: {str(e)}")
|
24 |
return f"Error processing the audio file: {str(e)}"
|
25 |
|
26 |
-
# Gradio
|
27 |
with gr.Blocks() as demo:
|
28 |
-
gr.Markdown("# Simple Speech Recognition App")
|
29 |
-
gr.Markdown("
|
30 |
|
31 |
-
mic = gr.Audio(label="Microphone or Upload", type="
|
32 |
-
transcribe_button = gr.Button("Transcribe Audio")
|
33 |
-
transcription = gr.Textbox(label="Transcription", lines=3, placeholder="Transcription will appear here...")
|
34 |
|
35 |
transcribe_button.click(fn=transcribe_speech, inputs=mic, outputs=transcription)
|
36 |
|
37 |
-
demo.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
import logging
|
3 |
from transformers import pipeline
|
|
|
4 |
|
5 |
+
# Set up logging
|
6 |
logging.basicConfig(level=logging.INFO)
|
7 |
|
8 |
+
# Load Whisper model (tiny version for speed)
|
9 |
asr = pipeline(task="automatic-speech-recognition", model="openai/whisper-tiny.en")
|
10 |
|
11 |
+
# Function to transcribe audio from a file path
|
12 |
+
def transcribe_speech(audio_path):
|
13 |
+
if audio_path is None:
|
14 |
logging.error("No audio provided.")
|
15 |
return "No audio found, please retry."
|
16 |
|
17 |
try:
|
18 |
+
logging.info(f"Received audio file path: {audio_path}")
|
19 |
+
output = asr(audio_path)
|
|
|
|
|
20 |
return output["text"]
|
21 |
except Exception as e:
|
22 |
logging.error(f"Error during transcription: {str(e)}")
|
23 |
return f"Error processing the audio file: {str(e)}"
|
24 |
|
25 |
+
# Gradio Interface
|
26 |
with gr.Blocks() as demo:
|
27 |
+
gr.Markdown("# π€ Simple Speech Recognition App")
|
28 |
+
gr.Markdown("Record or upload audio, then click **Transcribe Audio**")
|
29 |
|
30 |
+
mic = gr.Audio(label="ποΈ Microphone or Upload", type="filepath") # This is the key change
|
31 |
+
transcribe_button = gr.Button("π Transcribe Audio")
|
32 |
+
transcription = gr.Textbox(label="ποΈ Transcription", lines=3, placeholder="Transcription will appear here...")
|
33 |
|
34 |
transcribe_button.click(fn=transcribe_speech, inputs=mic, outputs=transcription)
|
35 |
|
36 |
+
demo.launch(share=True)
|