Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,9 @@ MENU = {
|
|
| 20 |
"Curries": {"Butter Chicken": 200, "Dal Fry": 150},
|
| 21 |
}
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
# HTML Template for Frontend
|
| 24 |
html_code = """
|
| 25 |
<!DOCTYPE html>
|
|
@@ -128,6 +131,7 @@ def index():
|
|
| 128 |
|
| 129 |
@app.route("/process-audio", methods=["POST"])
|
| 130 |
def process_audio():
|
|
|
|
| 131 |
try:
|
| 132 |
audio_file = request.files.get("audio")
|
| 133 |
if not audio_file:
|
|
@@ -149,7 +153,7 @@ def process_audio():
|
|
| 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,28 +167,26 @@ def process_audio():
|
|
| 163 |
os.unlink(temp_file.name)
|
| 164 |
os.unlink(converted_file.name)
|
| 165 |
|
| 166 |
-
def process_command(command):
|
| 167 |
-
global cart
|
| 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 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
cart_summary = ", ".join([f"{i[0]} (₹{i[1]})" for i in cart])
|
| 187 |
-
return f"{item.title()} added to your cart for ₹{price}. Your cart: {cart_summary}. Total: ₹{total}. Do you want to order anything else?"
|
| 188 |
|
| 189 |
# Handle final order
|
| 190 |
elif "final order" in command or "submit" in command:
|
|
|
|
| 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 = """
|
| 28 |
<!DOCTYPE html>
|
|
|
|
| 131 |
|
| 132 |
@app.route("/process-audio", methods=["POST"])
|
| 133 |
def process_audio():
|
| 134 |
+
global suggested_category
|
| 135 |
try:
|
| 136 |
audio_file = request.files.get("audio")
|
| 137 |
if not audio_file:
|
|
|
|
| 153 |
audio_data = recognizer.record(source)
|
| 154 |
try:
|
| 155 |
command = recognizer.recognize_google(audio_data)
|
| 156 |
+
response = process_command(command, suggested_category)
|
| 157 |
except sr.UnknownValueError:
|
| 158 |
response = "Sorry, I could not understand. Please try again."
|
| 159 |
|
|
|
|
| 167 |
os.unlink(temp_file.name)
|
| 168 |
os.unlink(converted_file.name)
|
| 169 |
|
| 170 |
+
def process_command(command, suggested_category=None):
|
| 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 and command in [item.lower() for item in MENU[suggested_category].keys()]:
|
| 177 |
+
item = command.title()
|
| 178 |
+
price = MENU[suggested_category][item]
|
| 179 |
+
cart.append((item, price))
|
| 180 |
+
total = sum(item[1] for item in cart)
|
| 181 |
+
cart_summary = ", ".join([f"{i[0]} (₹{i[1]})" for i in cart])
|
| 182 |
+
return f"{item} added to your cart for ₹{price}. Your cart: {cart_summary}. Total: ₹{total}. Do you want to order anything else?"
|
| 183 |
+
|
| 184 |
+
# Handle category suggestion
|
| 185 |
+
categories = {category.lower(): category for category in MENU.keys()}
|
| 186 |
+
if any(cat in command for cat in categories.keys()):
|
| 187 |
+
suggested_category = categories[next(cat for cat in categories.keys() if cat in command)]
|
| 188 |
+
items = ", ".join(MENU[suggested_category].keys())
|
| 189 |
+
return f"{suggested_category.capitalize()} options are: {items}. Which one would you like?"
|
|
|
|
|
|
|
| 190 |
|
| 191 |
# Handle final order
|
| 192 |
elif "final order" in command or "submit" in command:
|