Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import speech_recognition as sr
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
def gradio_interface():
|
| 27 |
with gr.Blocks() as demo:
|
| 28 |
-
gr.Markdown("### Welcome to Biryani Hub")
|
| 29 |
-
|
| 30 |
with gr.Column():
|
| 31 |
gr.Markdown("#### Step 1: Tell me your name")
|
| 32 |
-
audio_input_name = gr.Audio(
|
| 33 |
name_output = gr.Textbox(label="Your Name:")
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
gr.
|
| 39 |
-
audio_input_email = gr.Audio(source="microphone", type="filepath", label="Speak your email")
|
| 40 |
email_output = gr.Textbox(label="Your Email:")
|
| 41 |
-
|
| 42 |
-
# Step 2: Capture Email
|
| 43 |
audio_input_email.change(capture_email, inputs=audio_input_email, outputs=email_output)
|
| 44 |
|
| 45 |
return demo
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import speech_recognition as sr
|
| 3 |
+
import torch
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
+
# Load ASR model (Whisper)
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=0 if device == "cuda" else -1)
|
| 9 |
+
|
| 10 |
+
# Initialize Speech Recognition
|
| 11 |
+
recognizer = sr.Recognizer()
|
| 12 |
+
|
| 13 |
+
# Function to Capture Name
|
| 14 |
+
def capture_name(audio):
|
| 15 |
+
try:
|
| 16 |
+
text = speech_to_text(audio)["text"]
|
| 17 |
+
return f"Name Captured: {text}", "Please provide your email address."
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error: {str(e)}", ""
|
| 20 |
+
|
| 21 |
+
# Function to Capture Email
|
| 22 |
+
def capture_email(audio):
|
| 23 |
+
try:
|
| 24 |
+
text = speech_to_text(audio)["text"]
|
| 25 |
+
return f"Email Captured: {text}"
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Error: {str(e)}"
|
| 28 |
+
|
| 29 |
+
# Gradio Interface
|
| 30 |
def gradio_interface():
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("### 🎙️ Welcome to Biryani Hub")
|
| 33 |
+
|
| 34 |
with gr.Column():
|
| 35 |
gr.Markdown("#### Step 1: Tell me your name")
|
| 36 |
+
audio_input_name = gr.Audio(type="filepath", label="Record your Name")
|
| 37 |
name_output = gr.Textbox(label="Your Name:")
|
| 38 |
+
email_prompt_output = gr.Textbox(label="Next Step:", interactive=False)
|
| 39 |
+
audio_input_name.change(capture_name, inputs=audio_input_name, outputs=[name_output, email_prompt_output])
|
| 40 |
+
|
| 41 |
+
gr.Markdown("#### Step 2: Provide your email")
|
| 42 |
+
audio_input_email = gr.Audio(type="filepath", label="Record your Email")
|
|
|
|
| 43 |
email_output = gr.Textbox(label="Your Email:")
|
|
|
|
|
|
|
| 44 |
audio_input_email.change(capture_email, inputs=audio_input_email, outputs=email_output)
|
| 45 |
|
| 46 |
return demo
|