Spaces:
Runtime error
Runtime error
DSatishchandra
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,105 @@
|
|
|
|
|
|
|
|
1 |
import pyttsx3
|
2 |
-
import speech_recognition as sr
|
3 |
-
from transformers import pipeline
|
4 |
-
from gtts import gTTS
|
5 |
-
import os
|
6 |
|
7 |
-
|
8 |
-
tts = gTTS(text)
|
9 |
-
tts.save("response.mp3")
|
10 |
-
os.system("mpg321 response.mp3")
|
11 |
-
|
12 |
-
# Initialize Text-to-Speech engine
|
13 |
engine = pyttsx3.init()
|
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 |
-
speak("Hello! How can I assist you today?")
|
52 |
-
|
53 |
-
while True:
|
54 |
-
user_input = listen()
|
55 |
-
if user_input:
|
56 |
-
if 'exit' in user_input.lower():
|
57 |
-
speak("Goodbye!")
|
58 |
-
break
|
59 |
-
response = respond_to_query(user_input)
|
60 |
-
speak(response)
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import datetime
|
3 |
+
from fuzzywuzzy import fuzz
|
4 |
import pyttsx3
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
# Initialize TTS engine
|
|
|
|
|
|
|
|
|
|
|
7 |
engine = pyttsx3.init()
|
8 |
|
9 |
+
# Menu with Indian dishes and prices
|
10 |
+
menu = {
|
11 |
+
"Starters": {
|
12 |
+
"Paneer Tikka": 150.0,
|
13 |
+
"Samosa": 20.0,
|
14 |
+
"Pakora": 50.0
|
15 |
+
},
|
16 |
+
"Main Course": {
|
17 |
+
"Butter Chicken": 350.0,
|
18 |
+
"Paneer Butter Masala": 300.0,
|
19 |
+
"Dal Makhani": 200.0,
|
20 |
+
"Veg Biryani": 180.0,
|
21 |
+
"Chicken Biryani": 220.0
|
22 |
+
},
|
23 |
+
"Breads": {
|
24 |
+
"Tandoori Roti": 20.0,
|
25 |
+
"Butter Naan": 30.0,
|
26 |
+
"Stuffed Paratha": 50.0
|
27 |
+
},
|
28 |
+
"Desserts": {
|
29 |
+
"Gulab Jamun": 40.0,
|
30 |
+
"Rasgulla": 35.0,
|
31 |
+
"Kheer": 60.0
|
32 |
+
},
|
33 |
+
"Drinks": {
|
34 |
+
"Masala Chai": 15.0,
|
35 |
+
"Lassi": 50.0,
|
36 |
+
"Buttermilk": 20.0
|
37 |
+
}
|
38 |
+
}
|
39 |
|
40 |
+
# Function to wish the user based on the time of day
|
41 |
+
def wish_user():
|
42 |
+
hour = int(datetime.datetime.now().hour)
|
43 |
+
if hour >= 0 and hour < 12:
|
44 |
+
return "Good Morning! How can I help you today?"
|
45 |
+
elif hour >= 12 and hour < 18:
|
46 |
+
return "Good Afternoon! What would you like to order?"
|
47 |
+
else:
|
48 |
+
return "Good Evening! Hope you're doing well!"
|
49 |
+
|
50 |
+
# Function to recognize and process the command
|
51 |
+
def recognize_command(command):
|
52 |
+
if not command:
|
53 |
+
return "Sorry, I couldn't process your request. Please try again."
|
54 |
+
|
55 |
+
for category, items in menu.items():
|
56 |
+
for item in items:
|
57 |
+
if fuzz.partial_ratio(command.lower(), item.lower()) > 80:
|
58 |
+
return f"Got it! {item} has been added to your order."
|
59 |
+
|
60 |
+
if "menu" in command.lower():
|
61 |
+
menu_text = "Here is the menu for the restaurant:\n"
|
62 |
+
for category, items in menu.items():
|
63 |
+
menu_text += f"\n{category}:\n"
|
64 |
+
for item, price in items.items():
|
65 |
+
menu_text += f" - {item}: ₹{price}\n"
|
66 |
+
return menu_text
|
67 |
+
|
68 |
+
if "price" in command.lower():
|
69 |
+
return "Which item would you like to know the price for? (Type the item name)"
|
70 |
|
71 |
+
if "exit" in command.lower() or "bye" in command.lower():
|
72 |
+
return "Thank you for visiting! Have a great day!"
|
73 |
+
|
74 |
+
return "Sorry, I didn't understand that. Could you please repeat?"
|
75 |
+
|
76 |
+
# Function to provide the price of an item
|
77 |
+
def provide_price(item):
|
78 |
+
for category, items in menu.items():
|
79 |
+
if item in items:
|
80 |
+
price = items[item]
|
81 |
+
return f"The price for {item} is ₹{price}."
|
82 |
+
return f"Sorry, {item} is not available in the menu."
|
83 |
+
|
84 |
+
# Gradio interface functions
|
85 |
+
def assistant_response(command):
|
86 |
+
if "price for" in command.lower():
|
87 |
+
item = command.lower().replace("price for", "").strip()
|
88 |
+
return provide_price(item)
|
89 |
+
return recognize_command(command)
|
90 |
+
|
91 |
+
# Gradio Interface
|
92 |
+
interface = gr.Interface(
|
93 |
+
fn=assistant_response,
|
94 |
+
inputs=gr.Textbox(lines=2, placeholder="Type your request here..."),
|
95 |
+
outputs="text",
|
96 |
+
title="Restaurant Voice Assistant",
|
97 |
+
description="Interact with the restaurant assistant! Ask for the menu, prices, or place orders."
|
98 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
if __name__ == "__main__":
|
101 |
+
wish_message = wish_user()
|
102 |
+
print(wish_message)
|
103 |
+
engine.say(wish_message)
|
104 |
+
engine.runAndWait()
|
105 |
+
interface.launch()
|