Spaces:
Build error
Build error
File size: 3,816 Bytes
ba4dd53 cae89b2 53fbf0b f69bc89 53fbf0b f69bc89 585e159 53fbf0b cae89b2 53fbf0b f69bc89 53fbf0b 9a22878 be2cb4e c0cf200 53fbf0b c0cf200 53fbf0b c0cf200 53fbf0b c0cf200 53fbf0b c0cf200 025f225 251b182 c0cf200 6ff2f86 cae89b2 53fbf0b cae89b2 53fbf0b 71f182f c68f0e6 0b1fd91 a703953 cae89b2 57462dd c457259 cae89b2 97a7284 cae89b2 75a8a77 cae89b2 b649721 bc88d8c 7980609 45bc2f8 cae89b2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
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"""
<div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
<div style="flex: 1; margin-right: 15px;">
<h3 style="margin: 0; font-size: 18px;">{item['Dish Name']}</h3>
<p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price ($)']}</p>
<p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description']}</p>
</div>
</div>
"""
return html_content
# Function to announce menu page entry
def announce_menu():
speak_text("Welcome to Biryani Hub")
time.sleep(2)
speak_text("Choose a preference: All, Vegetarian, Non-Veg, or Guilt-Free")
# Gradio App
def app():
with gr.Blocks() as demo:
gr.Markdown("### Menu Page")
announce_menu()
# Radio button for selecting preference
selected_preference = gr.Radio(
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt Free"],
value="All",
label="Choose a Preference",
)
# Output area for menu items
menu_output = gr.HTML(value=filter_menu("All"))
# Update menu dynamically based on preference
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
# Layout
gr.Row([selected_preference])
gr.Row(menu_output)
return demo
if __name__ == "__main__":
app().launch()
|