Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,13 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# Menu data
|
| 4 |
menu_data = [
|
| 5 |
{"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},
|
| 6 |
{"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},
|
| 7 |
-
|
| 8 |
-
{"name": "Chilli Chicken", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/chilli-chicken-recipe.jpg", "description": "A spicy Indo-Chinese dish featuring fried chicken pieces tossed with peppers and chilies.", "price": 13.99},
|
| 9 |
-
{"name": "Veg Manchurian", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Veg_manchurian.jpg", "description": "Deep-fried vegetable balls tossed in a tangy and spicy Indo-Chinese sauce.", "price": 9.99},
|
| 10 |
-
{"name": "Fish Curry", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/fish_curry.jpg", "description": "A flavorful curry made with tender fish pieces simmered in a spiced coconut gravy.", "price": 14.99},
|
| 11 |
-
{"name": "Mutton Biryani", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Mutton_Biryani.jpg", "description": "Fragrant rice layered with tender mutton and aromatic spices, cooked to perfection.", "price": 15.99},
|
| 12 |
-
{"name": "Paneer Biryani", "category": "VEGETARIAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Paneer_Biryani.jpg", "description": "A delightful biryani made with marinated paneer cubes and basmati rice, infused with spices.", "price": 11.99},
|
| 13 |
-
{"name": "Onion Pakoda", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/onion-pakoda.jpg", "description": "Crispy deep-fried onion fritters, seasoned with spices, a popular tea-time snack.", "price": 5.99},
|
| 14 |
-
{"name": "Chilli Gobi", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/chilly_gobi.jpg", "description": "Crispy cauliflower florets tossed in a spicy and tangy sauce, an Indo-Chinese favorite.", "price": 9.99},
|
| 15 |
-
{"name": "Potato Samosa", "category": "VEGETARIAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Potato-Samosa.jpg", "description": "Crispy pastry filled with a spiced potato mixture, deep-fried to golden perfection.", "price": 4.99},
|
| 16 |
-
{"name": "Prawn Fry", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Pawn_Fry.jpg", "description": "Spicy and crispy fried prawns, marinated with a blend of spices and herbs.", "price": 14.99},
|
| 17 |
-
{"name": "Sukka Gosht (Goat)", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Sukka_Gosht%20(Goat).jpg", "description": "Dry goat meat preparation cooked with a medley of spices, offering a rich and hearty flavor.", "price": 16.99},
|
| 18 |
-
{"name": "Channa Masala", "category": "VEGETARIAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/channa_masala.jpg", "description": "A hearty curry made with chickpeas simmered in a spiced tomato gravy.", "price": 8.99},
|
| 19 |
-
{"name": "Vegetable Biryani", "category": "VEGAN", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Veg-Biryani-Recipe.jpg", "description": "A medley of vegetables and basmati rice cooked with aromatic spices, a vegetarian delight.", "price": 10.99},
|
| 20 |
-
{"name": "Chicken Manchurian", "category": "HALAL", "image": "https://huggingface.co/spaces/Rammohan0504/First-Project/resolve/main/pictures/Chicken_manchurian.jpg", "description": "A popular Indo-Chinese dish featuring fried chicken pieces tossed in a tangy and spicy sauce.", "price": 13.99},
|
| 21 |
-
]
|
| 22 |
-
|
| 23 |
-
extras = [
|
| 24 |
-
{"name": "Extra Raitha 4oz", "price": "$1.00"},
|
| 25 |
-
{"name": "Extra Raitha 8oz", "price": "$2.00"},
|
| 26 |
-
{"name": "Extra Salan 4oz", "price": "$1.00"},
|
| 27 |
-
{"name": "Extra Salan 8oz", "price": "$2.00"},
|
| 28 |
-
{"name": "Extra Onion", "price": "$1.00"},
|
| 29 |
-
{"name": "Extra Onion & Lemon", "price": "$2.00"},
|
| 30 |
-
{"name": "Extra Fried Onion 4oz", "price": "$2.00"},
|
| 31 |
]
|
| 32 |
|
| 33 |
# Filter dishes by category
|
|
@@ -53,7 +33,7 @@ def display_dishes(category):
|
|
| 53 |
<div style='text-align: center;'>
|
| 54 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 55 |
style='width: 150px; height: 100px; object-fit: cover; border-radius: 10px;'>
|
| 56 |
-
<button onclick="
|
| 57 |
style="margin-top: 15px; padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 58 |
border-radius: 5px; cursor: pointer;">Add</button>
|
| 59 |
</div>
|
|
@@ -62,6 +42,39 @@ def display_dishes(category):
|
|
| 62 |
html_content += "</div>"
|
| 63 |
return html_content
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# Main Gradio App
|
| 66 |
with gr.Blocks() as demo:
|
| 67 |
gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
|
|
@@ -75,50 +88,14 @@ with gr.Blocks() as demo:
|
|
| 75 |
# Dish display
|
| 76 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
gr.
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 85 |
-
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 86 |
-
<p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
<h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
|
| 91 |
-
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 92 |
-
""" + "".join([f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
|
| 93 |
-
</div>
|
| 94 |
-
|
| 95 |
-
<button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
|
| 96 |
-
style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
|
| 97 |
-
border-radius: 5px; cursor: pointer;">Add to Cart</button>
|
| 98 |
-
<button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
|
| 99 |
-
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 100 |
-
</div>
|
| 101 |
-
<script>
|
| 102 |
-
function showPopup(image, title, description, price) {
|
| 103 |
-
document.getElementById('popup-image').src = image;
|
| 104 |
-
document.getElementById('popup-title').textContent = title;
|
| 105 |
-
document.getElementById('popup-description').textContent = description;
|
| 106 |
-
document.getElementById('popup-price').textContent = "Price: " + price;
|
| 107 |
-
|
| 108 |
-
// Display the popup
|
| 109 |
-
document.getElementById('popup').style.display = 'block';
|
| 110 |
-
}
|
| 111 |
-
function closePopup() {
|
| 112 |
-
document.getElementById('popup').style.display = 'none';
|
| 113 |
-
}
|
| 114 |
-
function addToCart(dishName, spiceLevel) {
|
| 115 |
-
const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
|
| 116 |
-
alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
|
| 117 |
-
}
|
| 118 |
-
</script>
|
| 119 |
-
""")
|
| 120 |
|
| 121 |
-
#
|
| 122 |
btn_all.click(
|
| 123 |
lambda: gr.update(value=display_dishes("ALL")),
|
| 124 |
outputs=dish_display
|
|
@@ -132,4 +109,4 @@ with gr.Blocks() as demo:
|
|
| 132 |
outputs=dish_display
|
| 133 |
)
|
| 134 |
|
| 135 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
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
|
|
|
|
| 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>
|
|
|
|
| 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."""
|
| 48 |
+
recognizer = sr.Recognizer()
|
| 49 |
+
menu_keywords = {
|
| 50 |
+
"biryani": "We have Chicken Biryani, Mutton Biryani, and Veg Biryani.",
|
| 51 |
+
"starters": "Our starters include Samosa, Chicken 65, and Paneer Tikka.",
|
| 52 |
+
"drinks": "We offer refreshing drinks like Coke, Lemonade, and Iced Tea.",
|
| 53 |
+
}
|
| 54 |
+
try:
|
| 55 |
+
# Process the audio input
|
| 56 |
+
with sr.AudioFile(audio_file) as source:
|
| 57 |
+
audio = recognizer.record(source)
|
| 58 |
+
query = recognizer.recognize_google(audio).lower()
|
| 59 |
+
|
| 60 |
+
# Respond based on the query
|
| 61 |
+
for keyword, response in menu_keywords.items():
|
| 62 |
+
if keyword in query:
|
| 63 |
+
tts = gTTS(text=response, lang="en")
|
| 64 |
+
tts.save("response.mp3")
|
| 65 |
+
return "response.mp3"
|
| 66 |
+
|
| 67 |
+
# Default response
|
| 68 |
+
default_response = "I didn't catch that. Please ask about biryani, starters, or drinks."
|
| 69 |
+
tts = gTTS(text=default_response, lang="en")
|
| 70 |
+
tts.save("response.mp3")
|
| 71 |
+
return "response.mp3"
|
| 72 |
+
except Exception:
|
| 73 |
+
error_response = "Sorry, I couldn't understand your request. Please try again."
|
| 74 |
+
tts = gTTS(text=error_response, lang="en")
|
| 75 |
+
tts.save("response.mp3")
|
| 76 |
+
return "response.mp3"
|
| 77 |
+
|
| 78 |
# Main Gradio App
|
| 79 |
with gr.Blocks() as demo:
|
| 80 |
gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
|
|
|
|
| 88 |
# Dish display
|
| 89 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 90 |
|
| 91 |
+
# Voice Assistant Section
|
| 92 |
+
with gr.Row():
|
| 93 |
+
gr.Markdown("### Voice Assistant")
|
| 94 |
+
mic_input = gr.Audio(type="filepath", label="Speak Here")
|
| 95 |
+
response_output = gr.Audio(type="filepath", label="Response")
|
| 96 |
+
mic_input.change(voice_assistant, inputs=[mic_input], outputs=[response_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
# Update dishes based on category selection
|
| 99 |
btn_all.click(
|
| 100 |
lambda: gr.update(value=display_dishes("ALL")),
|
| 101 |
outputs=dish_display
|
|
|
|
| 109 |
outputs=dish_display
|
| 110 |
)
|
| 111 |
|
| 112 |
+
demo.launch()
|