import gradio as gr import pandas as pd import time import gtts import os import sounddevice as sd import numpy as np import speech_recognition as sr import tempfile import scipy.io.wavfile as wav # Function to convert text to speech def speak_text(text): tts = gtts.gTTS(text) temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav") tts.save(temp_file.name) data, samplerate = wav.read(temp_file.name) sd.play(data, samplerate) sd.wait() os.remove(temp_file.name) # Function to recognize speech input def recognize_speech(): recognizer = sr.Recognizer() with sr.Microphone() as source: print("Listening...") try: audio = recognizer.listen(source, timeout=5) text = recognizer.recognize_google(audio) print("You said:", text) return text.lower() except sr.UnknownValueError: print("Could not understand audio") return "" except sr.RequestError: print("Speech service is down") return "" # Function to load the menu data def load_menu(): menu_file = "menu.xlsx" # Ensure this file exists in the same directory try: return pd.read_excel(menu_file) except Exception as e: raise ValueError(f"Error loading menu file: {e}") # Function to filter menu items based on preference def filter_menu(preference): menu_data = load_menu() if preference == "Halal/Non-Veg": filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)] speak_text("Here are the non-vegetarian dishes") elif preference == "Vegetarian": filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)] speak_text("Here are the vegetarian dishes") elif preference == "Guilt-Free": filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)] speak_text("Here are the guilt-free options") else: filtered_data = menu_data speak_text("Showing all dishes") html_content = "" for _, item in filtered_data.iterrows(): html_content += f"""
${item['Price ($)']}
{item['Description']}