import gradio as gr import datetime from fuzzywuzzy import fuzz import pyttsx3 # Initialize TTS engine engine = pyttsx3.init() # Menu with Indian dishes and prices menu = { "Starters": { "Paneer Tikka": 150.0, "Samosa": 20.0, "Pakora": 50.0 }, "Main Course": { "Butter Chicken": 350.0, "Paneer Butter Masala": 300.0, "Dal Makhani": 200.0, "Veg Biryani": 180.0, "Chicken Biryani": 220.0 }, "Breads": { "Tandoori Roti": 20.0, "Butter Naan": 30.0, "Stuffed Paratha": 50.0 }, "Desserts": { "Gulab Jamun": 40.0, "Rasgulla": 35.0, "Kheer": 60.0 }, "Drinks": { "Masala Chai": 15.0, "Lassi": 50.0, "Buttermilk": 20.0 } } # Function to wish the user based on the time of day def wish_user(): hour = int(datetime.datetime.now().hour) if hour >= 0 and hour < 12: return "Good Morning! How can I help you today?" elif hour >= 12 and hour < 18: return "Good Afternoon! What would you like to order?" else: return "Good Evening! Hope you're doing well!" # Function to recognize and process the command def recognize_command(command): if not command: return "Sorry, I couldn't process your request. Please try again." for category, items in menu.items(): for item in items: if fuzz.partial_ratio(command.lower(), item.lower()) > 80: return f"Got it! {item} has been added to your order." if "menu" in command.lower(): menu_text = "Here is the menu for the restaurant:\n" for category, items in menu.items(): menu_text += f"\n{category}:\n" for item, price in items.items(): menu_text += f" - {item}: ₹{price}\n" return menu_text if "price" in command.lower(): return "Which item would you like to know the price for? (Type the item name)" if "exit" in command.lower() or "bye" in command.lower(): return "Thank you for visiting! Have a great day!" return "Sorry, I didn't understand that. Could you please repeat?" # Function to provide the price of an item def provide_price(item): for category, items in menu.items(): if item in items: price = items[item] return f"The price for {item} is ₹{price}." return f"Sorry, {item} is not available in the menu." # Gradio interface functions def assistant_response(command): if "price for" in command.lower(): item = command.lower().replace("price for", "").strip() return provide_price(item) return recognize_command(command) # Gradio Interface interface = gr.Interface( fn=assistant_response, inputs=gr.Textbox(lines=2, placeholder="Type your request here..."), outputs="text", title="Restaurant Voice Assistant", description="Interact with the restaurant assistant! Ask for the menu, prices, or place orders." ) if __name__ == "__main__": wish_message = wish_user() print(wish_message) engine.say(wish_message) engine.runAndWait() interface.launch()