Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,45 +3,6 @@ import speech_recognition as sr
|
|
| 3 |
from gtts import gTTS
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Menu data
|
| 7 |
-
menu_data = [
|
| 8 |
-
{"name": "Samosa", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Potato-Samosa.jpg", "description": "A delicious potato samosa with plant-based potato, lettuce.", "price": 8.99},
|
| 9 |
-
{"name": "Chicken Biryani", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Chicken-Biryani.jpg", "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.", "price": 12.99},
|
| 10 |
-
# Other menu items are omitted for brevity
|
| 11 |
-
]
|
| 12 |
-
|
| 13 |
-
# Filter dishes by category
|
| 14 |
-
def filter_dishes(category):
|
| 15 |
-
if category == "ALL":
|
| 16 |
-
return menu_data
|
| 17 |
-
return [dish for dish in menu_data if dish["category"] == category]
|
| 18 |
-
|
| 19 |
-
# Generate dish cards with "Add" button
|
| 20 |
-
def display_dishes(category):
|
| 21 |
-
filtered_dishes = filter_dishes(category)
|
| 22 |
-
html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%; height:100%'>"
|
| 23 |
-
for dish in filtered_dishes:
|
| 24 |
-
html_content += f"""
|
| 25 |
-
<div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
|
| 26 |
-
width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 27 |
-
background-color: #f9f9f9;'>
|
| 28 |
-
<div style='flex: 1; margin-right: 20px; text-align: left;'>
|
| 29 |
-
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 30 |
-
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
| 31 |
-
<p style='font-size: 16px; color: #444; margin: 0;'>Price: {dish['price']}</p>
|
| 32 |
-
</div>
|
| 33 |
-
<div style='text-align: center;'>
|
| 34 |
-
<img src='{dish['image']}' alt='{dish['name']}'
|
| 35 |
-
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 36 |
-
<button onclick="alert('Added to cart: {dish['name']}')"
|
| 37 |
-
style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 38 |
-
border-radius: 5px; cursor: pointer;">Add</button>
|
| 39 |
-
</div>
|
| 40 |
-
</div>
|
| 41 |
-
"""
|
| 42 |
-
html_content += "</div>"
|
| 43 |
-
return html_content
|
| 44 |
-
|
| 45 |
# Voice assistant function
|
| 46 |
def voice_assistant(audio_file):
|
| 47 |
"""Handles voice input and responds dynamically."""
|
|
@@ -77,36 +38,19 @@ def voice_assistant(audio_file):
|
|
| 77 |
|
| 78 |
# Main Gradio App
|
| 79 |
with gr.Blocks() as demo:
|
| 80 |
-
gr.HTML("<h1 style='text-align: center; color: #333;'
|
| 81 |
-
|
| 82 |
-
# Buttons for category selection
|
| 83 |
-
with gr.Row():
|
| 84 |
-
btn_all = gr.Button("ALL")
|
| 85 |
-
btn_vegan = gr.Button("VEGAN")
|
| 86 |
-
btn_halal = gr.Button("HALAL")
|
| 87 |
-
|
| 88 |
-
# Dish display
|
| 89 |
-
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 90 |
-
|
| 91 |
# Voice Assistant Section
|
| 92 |
with gr.Row():
|
| 93 |
-
gr.
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
)
|
| 103 |
-
btn_vegan.click(
|
| 104 |
-
lambda: gr.update(value=display_dishes("VEGAN")),
|
| 105 |
-
outputs=dish_display
|
| 106 |
-
)
|
| 107 |
-
btn_halal.click(
|
| 108 |
-
lambda: gr.update(value=display_dishes("HALAL")),
|
| 109 |
-
outputs=dish_display
|
| 110 |
-
)
|
| 111 |
|
| 112 |
demo.launch()
|
|
|
|
| 3 |
from gtts import gTTS
|
| 4 |
import os
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Voice assistant function
|
| 7 |
def voice_assistant(audio_file):
|
| 8 |
"""Handles voice input and responds dynamically."""
|
|
|
|
| 38 |
|
| 39 |
# Main Gradio App
|
| 40 |
with gr.Blocks() as demo:
|
| 41 |
+
gr.HTML("<h1 style='text-align: center; color: #333;'>🎤 Voice Assistant</h1>")
|
| 42 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Voice Assistant Section
|
| 44 |
with gr.Row():
|
| 45 |
+
mic_button = gr.Image(
|
| 46 |
+
value="/mnt/data/Screenshot 2024-12-28 101858.jpg",
|
| 47 |
+
interactive=True,
|
| 48 |
+
label="Click to Speak"
|
| 49 |
+
)
|
| 50 |
+
mic_input = gr.Audio(type="filepath", label="Record Your Query", visible=False)
|
| 51 |
+
mic_response = gr.Audio(type="filepath", label="Response", visible=False)
|
| 52 |
+
|
| 53 |
+
# Link the microphone button to the function
|
| 54 |
+
mic_button.click(voice_assistant, inputs=[mic_input], outputs=[mic_response])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
demo.launch()
|