Spaces:
Build error
Build error
import gradio as gr | |
from gtts import gTTS | |
import os | |
# Menu data from the second image (hardcoded for simplicity) | |
menu = { | |
"Appetizer": ["Veg Samosas", "Cut Mirchi", "Onion", "Spinach", "Mixed Vegetable"], | |
"Pakodas": ["Veg Pakoda", "Chicken Pakoda", "Fish Pakoda"], | |
"Manchurian": ["Vegetable", "Paneer", "Chicken", "Fish", "Jhinga"], | |
"Chilly": ["Gobi", "Paneer", "Chicken", "Fish", "Shrimp"], | |
"Chef's Special": ["Murgh (Chicken)", "Gosht (Goat)", "Jhinga (Shrimp)", "Fish Fry"], | |
"Vegetarian Entree": ["Dal Fry", "Dal Makhani", "Channa Masala", "Aloo Gobi Masala", "Saag Paneer"], | |
"Chettinad": ["Egg", "Murgh (Chicken)", "Gosht (Goat)", "Jhinga (Shrimp)", "Crab"], | |
"Butter Masala": ["Chicken", "Shrimp", "Gosht (Goat)"] | |
} | |
# Function to speak a text using Google Text-to-Speech (gTTS) | |
def speak(text): | |
tts = gTTS(text=text, lang='en') | |
tts.save("output.mp3") | |
# Do not try to play the audio, just save it | |
# os.system("mpg321 output.mp3") # Removed, as it is not supported in Hugging Face | |
# Function to process the order and handle confirmation | |
def process_order(order, confirmation): | |
response = "You have ordered the following: " | |
order = order.lower() | |
# Check for matching menu items | |
ordered_items = [] | |
for category, items in menu.items(): | |
for item in items: | |
if item.lower() in order: | |
ordered_items.append(item) | |
if ordered_items: | |
response += ', '.join(ordered_items) + ". Is that correct?" | |
if confirmation.lower() == "yes": | |
speak("Thank you for your order. It will be ready shortly!") | |
return "Order confirmed. " + response | |
else: | |
speak("Please tell me again what you'd like to order.") | |
return "Order not confirmed. Please try again." | |
else: | |
speak("Sorry, I couldn't find any items matching your order. Can you try again?") | |
return "Sorry, I couldn't find any items matching your order. Can you try again?" | |
# Create Gradio interface | |
def start_assistant(order, confirmation): | |
return process_order(order, confirmation) | |
# Gradio interface setup | |
iface = gr.Interface(fn=start_assistant, inputs=["text", "text"], outputs="text", | |
live=True, | |
title="Voice Food Ordering Assistant", | |
description="Type your food order and confirm your order.") | |
# Launch the interface | |
iface.launch() | |