Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,19 +9,15 @@ from werkzeug.exceptions import BadRequest
|
|
9 |
app = Flask(__name__)
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
|
12 |
-
# Global
|
13 |
-
cart = []
|
14 |
-
|
15 |
-
# Menu with items and their prices
|
16 |
MENU = {
|
17 |
"Biryani": {"Chicken Biryani": 150, "Veg Biryani": 120},
|
18 |
"Starters": {"Chicken Wings": 180, "Paneer Tikka": 160},
|
19 |
"Breads": {"Butter Naan": 40, "Roti": 30},
|
20 |
"Curries": {"Butter Chicken": 200, "Dal Fry": 150},
|
21 |
}
|
22 |
-
|
23 |
-
# Track ongoing suggestions for categories
|
24 |
-
suggested_category = None
|
25 |
|
26 |
# HTML Template for Frontend
|
27 |
html_code = """
|
@@ -153,7 +149,7 @@ def process_audio():
|
|
153 |
audio_data = recognizer.record(source)
|
154 |
try:
|
155 |
command = recognizer.recognize_google(audio_data)
|
156 |
-
response = process_command(command
|
157 |
except sr.UnknownValueError:
|
158 |
response = "Sorry, I could not understand. Please try again."
|
159 |
|
@@ -167,19 +163,21 @@ def process_audio():
|
|
167 |
os.unlink(temp_file.name)
|
168 |
os.unlink(converted_file.name)
|
169 |
|
170 |
-
def process_command(command
|
171 |
-
global cart, MENU
|
172 |
command = command.lower()
|
173 |
all_items = {item.lower(): (category, price) for category, items in MENU.items() for item, price in items.items()}
|
174 |
|
175 |
# Handle ongoing suggestion
|
176 |
-
if suggested_category
|
177 |
-
item
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
183 |
|
184 |
# Handle category suggestion
|
185 |
categories = {category.lower(): category for category in MENU.keys()}
|
@@ -206,4 +204,4 @@ def process_command(command, suggested_category=None):
|
|
206 |
return "Sorry, I didn't understand that. Please try again."
|
207 |
|
208 |
if __name__ == "__main__":
|
209 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
9 |
app = Flask(__name__)
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
|
12 |
+
# Global variables
|
13 |
+
cart = [] # To store items and prices
|
|
|
|
|
14 |
MENU = {
|
15 |
"Biryani": {"Chicken Biryani": 150, "Veg Biryani": 120},
|
16 |
"Starters": {"Chicken Wings": 180, "Paneer Tikka": 160},
|
17 |
"Breads": {"Butter Naan": 40, "Roti": 30},
|
18 |
"Curries": {"Butter Chicken": 200, "Dal Fry": 150},
|
19 |
}
|
20 |
+
suggested_category = None # To track ongoing category suggestions
|
|
|
|
|
21 |
|
22 |
# HTML Template for Frontend
|
23 |
html_code = """
|
|
|
149 |
audio_data = recognizer.record(source)
|
150 |
try:
|
151 |
command = recognizer.recognize_google(audio_data)
|
152 |
+
response = process_command(command)
|
153 |
except sr.UnknownValueError:
|
154 |
response = "Sorry, I could not understand. Please try again."
|
155 |
|
|
|
163 |
os.unlink(temp_file.name)
|
164 |
os.unlink(converted_file.name)
|
165 |
|
166 |
+
def process_command(command):
|
167 |
+
global cart, MENU, suggested_category
|
168 |
command = command.lower()
|
169 |
all_items = {item.lower(): (category, price) for category, items in MENU.items() for item, price in items.items()}
|
170 |
|
171 |
# Handle ongoing suggestion
|
172 |
+
if suggested_category:
|
173 |
+
if command in [item.lower() for item in MENU[suggested_category].keys()]:
|
174 |
+
item = command.title()
|
175 |
+
price = MENU[suggested_category][item]
|
176 |
+
cart.append((item, price))
|
177 |
+
total = sum(item[1] for item in cart)
|
178 |
+
cart_summary = ", ".join([f"{i[0]} (₹{i[1]})" for i in cart])
|
179 |
+
suggested_category = None # Reset category suggestion
|
180 |
+
return f"{item} added to your cart for ₹{price}. Your cart: {cart_summary}. Total: ₹{total}. Do you want to order anything else?"
|
181 |
|
182 |
# Handle category suggestion
|
183 |
categories = {category.lower(): category for category in MENU.keys()}
|
|
|
204 |
return "Sorry, I didn't understand that. Please try again."
|
205 |
|
206 |
if __name__ == "__main__":
|
207 |
+
app.run(host="0.0.0.0", port=7860)
|