Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,106 +1,80 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import qrcode
|
| 3 |
-
from PIL import Image
|
| 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 |
-
preferences = gr.CheckboxGroup(["Vegan", "Halal", "Indian", "Chinese"], label="Preferences")
|
| 84 |
-
pref_button = gr.Button("Save Preferences")
|
| 85 |
-
pref_output = gr.Text(label="Preference Status")
|
| 86 |
-
pref_button.click(save_preferences, inputs=[phone_input, preferences], outputs=pref_output)
|
| 87 |
-
|
| 88 |
-
# Menu Display
|
| 89 |
-
with gr.Row():
|
| 90 |
-
menu_pref = gr.Dropdown(["ALL", "VEGAN", "HALAL"], label="Menu Type")
|
| 91 |
-
menu_button = gr.Button("Show Menu")
|
| 92 |
-
menu_output = gr.JSON(label="Menu")
|
| 93 |
-
menu_button.click(filter_menu, inputs=menu_pref, outputs=menu_output)
|
| 94 |
-
|
| 95 |
-
# Dish Details
|
| 96 |
-
with gr.Row():
|
| 97 |
-
dish_name = gr.Textbox(label="Dish Name", placeholder="Enter dish name")
|
| 98 |
-
dish_button = gr.Button("Get Dish Details")
|
| 99 |
-
dish_output = gr.JSON(label="Dish Details")
|
| 100 |
-
dish_image = gr.Image(label="Dish Image")
|
| 101 |
-
dish_button.click(dish_details, inputs=dish_name, outputs=[dish_output, dish_image])
|
| 102 |
-
|
| 103 |
-
demo.launch()
|
| 104 |
-
|
| 105 |
-
if __name__ == "__main__":
|
| 106 |
-
main()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
menu_data = [
|
| 4 |
+
{"name": "Veg Burger", "category": "VEGAN",
|
| 5 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
|
| 6 |
+
"description": "A delicious vegan burger with plant-based patty, lettuce, and tomato."},
|
| 7 |
+
{"name": "Chicken Biryani", "category": "HALAL",
|
| 8 |
+
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
|
| 9 |
+
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces."},
|
| 10 |
+
# Add more dishes here...
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
# Filter menu based on 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 JavaScript pop-up
|
| 20 |
+
def display_dishes(category):
|
| 21 |
+
filtered_dishes = filter_dishes(category)
|
| 22 |
+
html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"
|
| 23 |
+
for dish in filtered_dishes:
|
| 24 |
+
html_content += f"""
|
| 25 |
+
<div style='width: 300px; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 26 |
+
background-color: #f9f9f9; text-align: center; cursor: pointer;'
|
| 27 |
+
onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}')">
|
| 28 |
+
<img src='{dish['image']}' alt='{dish['name']}'
|
| 29 |
+
style='width: 100%; height: 150px; object-fit: cover; border-radius: 10px;'>
|
| 30 |
+
<h4 style='margin: 10px 0; color: #444;'>{dish['name']}</h4>
|
| 31 |
+
<p style='color: #666; font-size: 14px;'>{dish['description']}</p>
|
| 32 |
+
</div>
|
| 33 |
+
"""
|
| 34 |
+
html_content += "</div>"
|
| 35 |
+
return html_content
|
| 36 |
+
|
| 37 |
+
# Main Gradio App
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
+
gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
|
| 40 |
+
|
| 41 |
+
# Buttons for category selection
|
| 42 |
+
with gr.Row():
|
| 43 |
+
btn_all = gr.Button("ALL")
|
| 44 |
+
btn_vegan = gr.Button("VEGAN")
|
| 45 |
+
btn_halal = gr.Button("HALAL")
|
| 46 |
+
|
| 47 |
+
# Dish display section
|
| 48 |
+
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 49 |
+
|
| 50 |
+
# Pop-up HTML and JavaScript
|
| 51 |
+
gr.HTML("""
|
| 52 |
+
<div id="popup" style="display: none; position: fixed; left: 50%; top: 10%; transform: translate(-50%, 0);
|
| 53 |
+
background-color: white; padding: 20px; border-radius: 10px;
|
| 54 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
|
| 55 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 56 |
+
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 57 |
+
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 58 |
+
<button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
|
| 59 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 60 |
+
</div>
|
| 61 |
+
<script>
|
| 62 |
+
function showPopup(image, title, description) {
|
| 63 |
+
const popup = document.getElementById('popup');
|
| 64 |
+
document.getElementById('popup-image').src = image;
|
| 65 |
+
document.getElementById('popup-title').textContent = title;
|
| 66 |
+
document.getElementById('popup-description').textContent = description;
|
| 67 |
+
popup.style.display = 'block';
|
| 68 |
+
}
|
| 69 |
+
function closePopup() {
|
| 70 |
+
document.getElementById('popup').style.display = 'none';
|
| 71 |
+
}
|
| 72 |
+
</script>
|
| 73 |
+
""")
|
| 74 |
+
|
| 75 |
+
# Button click events for category filtering
|
| 76 |
+
btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
|
| 77 |
+
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 78 |
+
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 79 |
+
|
| 80 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|