Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load Whisper model from Hugging Face
|
6 |
+
asr = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if torch.cuda.is_available() else -1)
|
7 |
+
|
8 |
+
# Function to transcribe audio
|
9 |
+
def transcribe(audio):
|
10 |
+
print("Received audio input.")
|
11 |
+
text = asr(audio)["text"]
|
12 |
+
return text
|
13 |
+
|
14 |
+
# Create Gradio Interface
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=transcribe,
|
17 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
18 |
+
outputs="text",
|
19 |
+
title="🎙️ Whisper Voice Recognition",
|
20 |
+
description="Speak into your mic and get real-time transcription using OpenAI's Whisper ASR."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the app
|
24 |
+
demo.launch()
|