Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
asr_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 9 |
-
|
| 10 |
-
# Store user details
|
| 11 |
user_data = {"name": "", "email": ""}
|
| 12 |
|
| 13 |
-
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
return
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import whisper
|
| 3 |
+
import time
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Load Whisper ASR Model
|
| 7 |
+
model = whisper.load_model("base")
|
| 8 |
|
| 9 |
+
# Store User Data
|
|
|
|
|
|
|
|
|
|
| 10 |
user_data = {"name": "", "email": ""}
|
| 11 |
|
| 12 |
+
# Function to Play Welcome Message
|
| 13 |
+
def welcome_message():
|
| 14 |
+
return "Welcome to Biryani Hub. Tell me your name."
|
| 15 |
+
|
| 16 |
+
# Function to Capture Name
|
| 17 |
+
def capture_name(audio):
|
| 18 |
+
global user_data
|
| 19 |
+
if audio is None:
|
| 20 |
+
return "No audio detected. Please try again."
|
| 21 |
+
|
| 22 |
+
# Save the audio
|
| 23 |
+
audio_path = "name.wav"
|
| 24 |
+
audio.export(audio_path, format="wav")
|
| 25 |
+
|
| 26 |
+
# Convert Speech to Text
|
| 27 |
+
result = model.transcribe(audio_path)
|
| 28 |
+
user_data["name"] = result["text"]
|
| 29 |
+
|
| 30 |
+
return f"Hello, {user_data['name']}! Please provide your email address."
|
| 31 |
+
|
| 32 |
+
# Function to Capture Email
|
| 33 |
+
def capture_email(audio):
|
| 34 |
+
global user_data
|
| 35 |
+
if audio is None:
|
| 36 |
+
return "No audio detected. Please try again."
|
| 37 |
+
|
| 38 |
+
# Save the audio
|
| 39 |
+
audio_path = "email.wav"
|
| 40 |
+
audio.export(audio_path, format="wav")
|
| 41 |
+
|
| 42 |
+
# Convert Speech to Text
|
| 43 |
+
result = model.transcribe(audio_path)
|
| 44 |
+
user_data["email"] = result["text"]
|
| 45 |
+
|
| 46 |
+
return f"Thank you, {user_data['name']}! We have saved your email: {user_data['email']}."
|
| 47 |
+
|
| 48 |
+
# Create Gradio UI
|
| 49 |
+
with gr.Blocks() as demo:
|
| 50 |
+
gr.Markdown("# 🎙️ Voice-Enabled Restaurant Menu - Biryani Hub")
|
| 51 |
+
|
| 52 |
+
# Welcome Message
|
| 53 |
+
welcome = gr.Textbox(value=welcome_message(), interactive=False)
|
| 54 |
+
|
| 55 |
+
# Step 1: Capture Name
|
| 56 |
+
gr.Markdown("### 🗣️ Step 1: Say Your Name")
|
| 57 |
+
name_input = gr.Audio(source="microphone", type="file")
|
| 58 |
+
name_output = gr.Textbox()
|
| 59 |
+
name_button = gr.Button("Submit Name")
|
| 60 |
+
|
| 61 |
+
# Step 2: Capture Email
|
| 62 |
+
gr.Markdown("### 📧 Step 2: Say Your Email")
|
| 63 |
+
email_input = gr.Audio(source="microphone", type="file")
|
| 64 |
+
email_output = gr.Textbox()
|
| 65 |
+
email_button = gr.Button("Submit Email")
|
| 66 |
+
|
| 67 |
+
# Capture Name and Email
|
| 68 |
+
name_button.click(capture_name, inputs=name_input, outputs=name_output)
|
| 69 |
+
email_button.click(capture_email, inputs=email_input, outputs=email_output)
|
| 70 |
+
|
| 71 |
+
# Launch the App
|
| 72 |
+
demo.launch()
|