Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
# Menu data
|
| 4 |
menu_data = [
|
| 5 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
|
|
@@ -61,19 +60,30 @@ menu_data = [
|
|
| 61 |
"description": "A refreshing salad made with chickpeas, fresh vegetables, and herbs."}
|
| 62 |
]
|
| 63 |
|
| 64 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def display_dishes(category):
|
| 66 |
-
filtered_dishes =
|
| 67 |
-
html_content = "<div style='display: flex; flex-
|
| 68 |
for dish in filtered_dishes:
|
| 69 |
html_content += f"""
|
| 70 |
-
<div style='
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 74 |
-
style='width:
|
| 75 |
-
<h4 style='margin: 10px 0; color: #444;'>{dish['name']}</h4>
|
| 76 |
-
<p style='color: #666; font-size: 14px;'>{dish['description']}</p>
|
| 77 |
</div>
|
| 78 |
"""
|
| 79 |
html_content += "</div>"
|
|
@@ -81,22 +91,25 @@ def display_dishes(category):
|
|
| 81 |
|
| 82 |
# Main Gradio App
|
| 83 |
with gr.Blocks() as demo:
|
| 84 |
-
gr.HTML("<h1 style='text-align: center; color: #333;'>π
|
| 85 |
|
| 86 |
-
#
|
| 87 |
with gr.Row():
|
| 88 |
btn_all = gr.Button("ALL")
|
| 89 |
btn_vegan = gr.Button("VEGAN")
|
| 90 |
btn_halal = gr.Button("HALAL")
|
| 91 |
|
| 92 |
-
# Dish display
|
| 93 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 94 |
|
| 95 |
-
#
|
| 96 |
gr.HTML("""
|
| 97 |
-
<div id="popup" style="display: none; position: fixed;
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 101 |
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 102 |
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
|
@@ -104,49 +117,25 @@ with gr.Blocks() as demo:
|
|
| 104 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 105 |
</div>
|
| 106 |
<script>
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
const popupTitle = document.getElementById('popup-title');
|
| 112 |
-
const popupDescription = document.getElementById('popup-description');
|
| 113 |
-
|
| 114 |
-
// Update the pop-up content
|
| 115 |
-
popupImage.src = image;
|
| 116 |
-
popupTitle.textContent = title;
|
| 117 |
-
popupDescription.textContent = description;
|
| 118 |
|
| 119 |
-
//
|
| 120 |
-
const
|
| 121 |
-
|
| 122 |
-
const yOffset = 20; // Offset to place pop-up below the cursor
|
| 123 |
-
let xPos = event.pageX + xOffset;
|
| 124 |
-
let yPos = event.pageY + yOffset;
|
| 125 |
-
|
| 126 |
-
// Prevent the pop-up from going off the screen
|
| 127 |
-
if (xPos + popupWidth > window.innerWidth) {
|
| 128 |
-
xPos = window.innerWidth - popupWidth - xOffset;
|
| 129 |
-
}
|
| 130 |
-
if (yPos + popup.offsetHeight > window.innerHeight) {
|
| 131 |
-
yPos = window.innerHeight - popup.offsetHeight - yOffset;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
popup.style.left = `${xPos}px`;
|
| 135 |
-
popup.style.top = `${yPos}px`;
|
| 136 |
popup.style.display = 'block';
|
| 137 |
}
|
| 138 |
-
|
| 139 |
-
// Close the pop-up
|
| 140 |
function closePopup() {
|
| 141 |
-
|
| 142 |
-
popup.style.display = 'none';
|
| 143 |
}
|
| 144 |
</script>
|
| 145 |
""")
|
| 146 |
|
| 147 |
-
# Button
|
| 148 |
btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
|
| 149 |
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 150 |
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 151 |
|
| 152 |
-
demo.launch()
|
|
|
|
| 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",
|
|
|
|
| 60 |
"description": "A refreshing salad made with chickpeas, fresh vegetables, and herbs."}
|
| 61 |
]
|
| 62 |
|
| 63 |
+
# The rest of the code remains unchanged
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def filter_dishes(category):
|
| 67 |
+
if category == "ALL":
|
| 68 |
+
return menu_data
|
| 69 |
+
return [dish for dish in menu_data if dish["category"] == category]
|
| 70 |
+
|
| 71 |
+
# Function to generate dish cards
|
| 72 |
def display_dishes(category):
|
| 73 |
+
filtered_dishes = filter_dishes(category)
|
| 74 |
+
html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
|
| 75 |
for dish in filtered_dishes:
|
| 76 |
html_content += f"""
|
| 77 |
+
<div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
|
| 78 |
+
width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 79 |
+
background-color: #f9f9f9; cursor: pointer;'
|
| 80 |
+
onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}')">
|
| 81 |
+
<div style='flex: 1; margin-right: 20px;'>
|
| 82 |
+
<h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
|
| 83 |
+
<p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
|
| 84 |
+
</div>
|
| 85 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 86 |
+
style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
|
|
|
|
|
|
|
| 87 |
</div>
|
| 88 |
"""
|
| 89 |
html_content += "</div>"
|
|
|
|
| 91 |
|
| 92 |
# Main Gradio App
|
| 93 |
with gr.Blocks() as demo:
|
| 94 |
+
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 95 |
|
| 96 |
+
# Buttons for category selection
|
| 97 |
with gr.Row():
|
| 98 |
btn_all = gr.Button("ALL")
|
| 99 |
btn_vegan = gr.Button("VEGAN")
|
| 100 |
btn_halal = gr.Button("HALAL")
|
| 101 |
|
| 102 |
+
# Dish display
|
| 103 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 104 |
|
| 105 |
+
# JavaScript for managing the pop-up
|
| 106 |
gr.HTML("""
|
| 107 |
+
<div id="popup" style="display: none; position: fixed;cursor: pointer;-webkit-user-select: none;
|
| 108 |
+
-moz-user-select: none;
|
| 109 |
+
-ms-user-select: none;
|
| 110 |
+
user-select: none; left: 50%; transform: translate(-50%, 100%);
|
| 111 |
+
background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
| 112 |
+
z-index: 1000; text-align: center; width: 300px;">
|
| 113 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
| 114 |
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
|
| 115 |
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
|
|
|
|
| 117 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 118 |
</div>
|
| 119 |
<script>
|
| 120 |
+
function showPopup(image, title, description) {
|
| 121 |
+
document.getElementById('popup-image').src = image;
|
| 122 |
+
document.getElementById('popup-title').textContent = title;
|
| 123 |
+
document.getElementById('popup-description').textContent = description;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
// Adjust the popup to always appear at the top of the viewport
|
| 126 |
+
const popup = document.getElementById('popup');
|
| 127 |
+
popup.style.top = window.pageYOffset + 'px';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
popup.style.display = 'block';
|
| 129 |
}
|
|
|
|
|
|
|
| 130 |
function closePopup() {
|
| 131 |
+
document.getElementById('popup').style.display = 'none';
|
|
|
|
| 132 |
}
|
| 133 |
</script>
|
| 134 |
""")
|
| 135 |
|
| 136 |
+
# Button click events
|
| 137 |
btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
|
| 138 |
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 139 |
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 140 |
|
| 141 |
+
demo.launch()
|