geethareddy commited on
Commit
53fbf0b
·
verified ·
1 Parent(s): cae89b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -7
app.py CHANGED
@@ -1,13 +1,35 @@
1
  import gradio as gr
2
  import pandas as pd
3
- import pyttsx3
4
  import time
 
 
 
 
5
 
6
- # Initialize text-to-speech engine
7
  def speak_text(text):
8
- engine = pyttsx3.init()
9
- engine.say(text)
10
- engine.runAndWait()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Function to load the menu data
13
  def load_menu():
@@ -22,12 +44,16 @@ def filter_menu(preference):
22
  menu_data = load_menu()
23
  if preference == "Halal/Non-Veg":
24
  filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
 
25
  elif preference == "Vegetarian":
26
  filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
 
27
  elif preference == "Guilt-Free":
28
  filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
 
29
  else:
30
  filtered_data = menu_data
 
31
 
32
  html_content = ""
33
  for _, item in filtered_data.iterrows():
@@ -44,9 +70,9 @@ def filter_menu(preference):
44
 
45
  # Function to announce menu page entry
46
  def announce_menu():
47
- speak_text("Welcome to menu page")
48
  time.sleep(2)
49
- speak_text("Choose a preference")
50
 
51
  # Gradio App
52
  def app():
 
1
  import gradio as gr
2
  import pandas as pd
 
3
  import time
4
+ import gtts
5
+ import os
6
+ from playsound import playsound
7
+ import speech_recognition as sr
8
 
9
+ # Function to convert text to speech
10
  def speak_text(text):
11
+ tts = gtts.gTTS(text)
12
+ filename = "temp_audio.mp3"
13
+ tts.save(filename)
14
+ playsound(filename)
15
+ os.remove(filename)
16
+
17
+ # Function to recognize speech input
18
+ def recognize_speech():
19
+ recognizer = sr.Recognizer()
20
+ with sr.Microphone() as source:
21
+ print("Listening...")
22
+ try:
23
+ audio = recognizer.listen(source, timeout=5)
24
+ text = recognizer.recognize_google(audio)
25
+ print("You said:", text)
26
+ return text.lower()
27
+ except sr.UnknownValueError:
28
+ print("Could not understand audio")
29
+ return ""
30
+ except sr.RequestError:
31
+ print("Speech service is down")
32
+ return ""
33
 
34
  # Function to load the menu data
35
  def load_menu():
 
44
  menu_data = load_menu()
45
  if preference == "Halal/Non-Veg":
46
  filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
47
+ speak_text("Here are the non-vegetarian dishes")
48
  elif preference == "Vegetarian":
49
  filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
50
+ speak_text("Here are the vegetarian dishes")
51
  elif preference == "Guilt-Free":
52
  filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
53
+ speak_text("Here are the guilt-free options")
54
  else:
55
  filtered_data = menu_data
56
+ speak_text("Showing all dishes")
57
 
58
  html_content = ""
59
  for _, item in filtered_data.iterrows():
 
70
 
71
  # Function to announce menu page entry
72
  def announce_menu():
73
+ speak_text("Welcome to Biryani Hub")
74
  time.sleep(2)
75
+ speak_text("Choose a preference: All, Vegetarian, Non-Veg, or Guilt-Free")
76
 
77
  # Gradio App
78
  def app():