Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
menu_data = [
|
| 5 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
@@ -19,7 +18,7 @@ def filter_dishes(category):
|
|
| 19 |
return menu_data
|
| 20 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 21 |
|
| 22 |
-
# Function to
|
| 23 |
def display_dishes(category):
|
| 24 |
filtered_dishes = filter_dishes(category)
|
| 25 |
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
|
@@ -27,8 +26,7 @@ def display_dishes(category):
|
|
| 27 |
html_content += f"""
|
| 28 |
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 29 |
padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
|
| 30 |
-
onclick="
|
| 31 |
-
document.querySelector('input[aria-label=\\'selected_dish\\']').dispatchEvent(new Event('input'));">
|
| 32 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 33 |
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 34 |
<h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
|
|
@@ -37,60 +35,46 @@ def display_dishes(category):
|
|
| 37 |
html_content += "</div>"
|
| 38 |
return html_content
|
| 39 |
|
| 40 |
-
# Function to fetch dish details
|
| 41 |
-
def get_dish_details(dish_name):
|
| 42 |
-
for dish in menu_data:
|
| 43 |
-
if dish["name"] == dish_name:
|
| 44 |
-
return f"""
|
| 45 |
-
<div style="text-align: center; padding: 20px; font-family: Arial, sans-serif;">
|
| 46 |
-
<img src="{dish['image']}" alt="{dish['name']}"
|
| 47 |
-
style="width: 250px; height: 150px; object-fit: cover; border-radius: 10px;">
|
| 48 |
-
<h2 style="margin-top: 20px; color: #444;">{dish['name']}</h2>
|
| 49 |
-
<p style="margin-top: 10px; font-size: 16px; color: #666;">{dish['description']}</p>
|
| 50 |
-
<button style="padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 51 |
-
border-radius: 5px; cursor: pointer;"
|
| 52 |
-
onclick="document.querySelector('button[aria-label=\\'close_popup\\']').click();">
|
| 53 |
-
Close
|
| 54 |
-
</button>
|
| 55 |
-
</div>
|
| 56 |
-
"""
|
| 57 |
-
return "<p>Dish not found!</p>"
|
| 58 |
-
|
| 59 |
# Main Gradio App
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 62 |
|
| 63 |
-
# Buttons for category
|
| 64 |
with gr.Row():
|
| 65 |
btn_all = gr.Button("ALL")
|
| 66 |
btn_vegan = gr.Button("VEGAN")
|
| 67 |
btn_halal = gr.Button("HALAL")
|
| 68 |
|
| 69 |
-
#
|
| 70 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 71 |
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
close_popup_btn = gr.Button("Close Popup", visible=False)
|
| 80 |
-
|
| 81 |
-
# Button events
|
| 82 |
btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
|
| 83 |
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 84 |
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 85 |
|
| 86 |
-
# Event to show pop-up
|
| 87 |
-
selected_dish.change(
|
| 88 |
-
lambda dish_name: gr.update(visible=True, value=get_dish_details(dish_name)),
|
| 89 |
-
inputs=selected_dish,
|
| 90 |
-
outputs=popup,
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
# Event to close pop-up
|
| 94 |
-
close_popup_btn.click(lambda: gr.update(visible=False), outputs=popup)
|
| 95 |
-
|
| 96 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
| 3 |
menu_data = [
|
| 4 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 5 |
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
|
|
| 18 |
return menu_data
|
| 19 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 20 |
|
| 21 |
+
# Function to generate dish cards
|
| 22 |
def display_dishes(category):
|
| 23 |
filtered_dishes = filter_dishes(category)
|
| 24 |
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
|
|
|
| 26 |
html_content += f"""
|
| 27 |
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 28 |
padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
|
| 29 |
+
onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}')">
|
|
|
|
| 30 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 31 |
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 32 |
<h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
|
|
|
|
| 35 |
html_content += "</div>"
|
| 36 |
return html_content
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Main Gradio App
|
| 39 |
with gr.Blocks() as demo:
|
| 40 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 41 |
|
| 42 |
+
# Buttons for category selection
|
| 43 |
with gr.Row():
|
| 44 |
btn_all = gr.Button("ALL")
|
| 45 |
btn_vegan = gr.Button("VEGAN")
|
| 46 |
btn_halal = gr.Button("HALAL")
|
| 47 |
|
| 48 |
+
# Dish display
|
| 49 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 50 |
|
| 51 |
+
# JavaScript for managing the pop-up
|
| 52 |
+
gr.HTML("""
|
| 53 |
+
<div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 54 |
+
background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
| 55 |
+
z-index: 1000; text-align: center; width: 300px;">
|
| 56 |
+
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 57 |
+
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 58 |
+
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
| 59 |
+
<button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
|
| 60 |
+
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 61 |
+
</div>
|
| 62 |
+
<script>
|
| 63 |
+
function showPopup(image, title, description) {
|
| 64 |
+
document.getElementById('popup-image').src = image;
|
| 65 |
+
document.getElementById('popup-title').textContent = title;
|
| 66 |
+
document.getElementById('popup-description').textContent = description;
|
| 67 |
+
document.getElementById('popup').style.display = 'block';
|
| 68 |
+
}
|
| 69 |
+
function closePopup() {
|
| 70 |
+
document.getElementById('popup').style.display = 'none';
|
| 71 |
+
}
|
| 72 |
+
</script>
|
| 73 |
+
""")
|
| 74 |
|
| 75 |
+
# Button click events
|
|
|
|
|
|
|
|
|
|
| 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()
|