File size: 2,014 Bytes
575b90c
 
1277d49
cd7928d
26015c2
1277d49
 
 
 
575b90c
2303830
575b90c
cd7928d
2303830
575b90c
 
 
 
 
 
 
 
1277d49
 
575b90c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1277d49
 
575b90c
 
 
 
 
 
 
 
 
 
 
 
 
1277d49
575b90c
 
 
 
 
1277d49
575b90c
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import gradio as gr
import whisper
import torch
import os

# Suppress Torch Warnings
torch.serialization._legacy_load = torch.load  # Suppresses `torch.load` warnings

# Load Whisper Model
model = whisper.load_model("base")

# Store User Data
user_data = {"name": "", "email": ""}

# Function to Capture Name
def capture_name(audio):
    global user_data
    if audio is None:
        return "No audio detected. Please try again."

    # Save the audio
    audio_path = "name.wav"
    with open(audio_path, "wb") as f:
        f.write(audio)  # Save audio from Gradio

    # Convert Speech to Text
    result = model.transcribe(audio_path)
    user_data["name"] = result["text"]

    return f"Hello, {user_data['name']}! Please provide your email address."

# Function to Capture Email
def capture_email(audio):
    global user_data
    if audio is None:
        return "No audio detected. Please try again."

    # Save the audio
    audio_path = "email.wav"
    with open(audio_path, "wb") as f:
        f.write(audio)  # Save audio from Gradio

    # Convert Speech to Text
    result = model.transcribe(audio_path)
    user_data["email"] = result["text"]

    return f"Thank you, {user_data['name']}! We have saved your email: {user_data['email']}."

# Create Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("# 🎙️ Voice-Enabled Restaurant Menu - Biryani Hub")
    
    # Step 1: Capture Name
    gr.Markdown("### 🗣️ Step 1: Say Your Name")
    name_input = gr.Audio(type="filepath")  # FIXED!
    name_output = gr.Textbox()
    name_button = gr.Button("Submit Name")

    # Step 2: Capture Email
    gr.Markdown("### 📧 Step 2: Say Your Email")
    email_input = gr.Audio(type="filepath")  # FIXED!
    email_output = gr.Textbox()
    email_button = gr.Button("Submit Email")

    # Capture Name and Email
    name_button.click(capture_name, inputs=name_input, outputs=name_output)
    email_button.click(capture_email, inputs=email_input, outputs=email_output)

# Launch the App
demo.launch()