geethareddy commited on
Commit
adb5e2a
Β·
verified Β·
1 Parent(s): cc0332e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -13
app.py CHANGED
@@ -1,47 +1,67 @@
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
47
 
 
1
  import gradio as gr
2
  import speech_recognition as sr
3
  import torch
4
+ import os
5
  from transformers import pipeline
6
+ from gtts import gTTS
7
+ import time
8
 
9
+ # Load ASR Model (Whisper)
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
  speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=0 if device == "cuda" else -1)
12
 
13
  # Initialize Speech Recognition
14
  recognizer = sr.Recognizer()
15
 
16
+ # Function to Play Audio Prompt
17
+ def play_audio(text):
18
+ tts = gTTS(text=text, lang='en')
19
+ filename = "prompt.mp3"
20
+ tts.save(filename)
21
+ os.system(f"mpg321 {filename}" if os.name != "nt" else f"start {filename}") # Works on Linux & Windows
22
+ time.sleep(2) # Give some time for the speech to play
23
+
24
  # Function to Capture Name
25
  def capture_name(audio):
26
+ play_audio("Tell me your name")
27
  try:
28
  text = speech_to_text(audio)["text"]
29
+ return f"πŸ‘€ Name Captured: {text}", "Please provide your email address."
30
  except Exception as e:
31
+ return f"❌ Error: {str(e)}", ""
32
 
33
  # Function to Capture Email
34
  def capture_email(audio):
35
+ play_audio("Please provide your email address")
36
  try:
37
  text = speech_to_text(audio)["text"]
38
+ return f"πŸ“§ Email Captured: {text}"
39
  except Exception as e:
40
+ return f"❌ Error: {str(e)}"
41
 
42
  # Gradio Interface
43
  def gradio_interface():
44
  with gr.Blocks() as demo:
45
+ gr.Markdown("<h1 style='text-align: center;'>🍽️ AI Dining Assistant</h1>")
46
+
47
  with gr.Column():
48
+ gr.Image("/mnt/data/image.png", elem_id="header_image", show_label=False) # Upload the image you provided
49
+ gr.Markdown("<p style='text-align: center;'>Press the mic button to start...</p>")
50
+
51
+ gr.Markdown("#### 🎀 Step 1: Tell me your name")
52
+ mic_button = gr.Button("πŸŽ™οΈ Tap to Speak Your Name")
53
+ audio_input_name = gr.Audio(type="filepath", visible=False)
54
  name_output = gr.Textbox(label="Your Name:")
55
  email_prompt_output = gr.Textbox(label="Next Step:", interactive=False)
 
56
 
57
+ mic_button.click(capture_name, inputs=audio_input_name, outputs=[name_output, email_prompt_output])
58
+
59
+ gr.Markdown("#### 🎀 Step 2: Provide your email")
60
+ mic_button_email = gr.Button("πŸŽ™οΈ Tap to Speak Your Email")
61
+ audio_input_email = gr.Audio(type="filepath", visible=False)
62
  email_output = gr.Textbox(label="Your Email:")
63
+
64
+ mic_button_email.click(capture_email, inputs=audio_input_email, outputs=email_output)
65
 
66
  return demo
67