Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,27 +22,16 @@ menu_data = [
|
|
| 22 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 23 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 24 |
|
| 25 |
-
# Function to
|
| 26 |
-
def
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
for dish in
|
| 30 |
-
html_content += f"""
|
| 31 |
-
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 32 |
-
padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
|
| 33 |
-
onclick='selectDish("{dish['name']}")'>
|
| 34 |
-
<img src='{dish['image']}' alt='{dish['name']}'
|
| 35 |
-
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 36 |
-
<h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
|
| 37 |
-
</div>
|
| 38 |
-
"""
|
| 39 |
-
html_content += "</div>"
|
| 40 |
-
return html_content
|
| 41 |
|
| 42 |
# Function to fetch dish details
|
| 43 |
def get_dish_details(dish_name):
|
| 44 |
for dish in menu_data:
|
| 45 |
-
if dish["name"] == dish_name
|
| 46 |
return dish["image"], dish["name"], dish["description"]
|
| 47 |
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available."
|
| 48 |
|
|
@@ -53,65 +42,49 @@ def place_order(dish_name, spice_level, portion_size):
|
|
| 53 |
return "β οΈ Please select a dish before placing an order."
|
| 54 |
|
| 55 |
# Main Gradio App
|
| 56 |
-
|
| 57 |
-
gr.
|
| 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 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
place_order_btn.click(fn=place_order,
|
| 103 |
-
inputs=[dish_name, spice_dropdown, portion_dropdown],
|
| 104 |
-
outputs=order_status)
|
| 105 |
-
|
| 106 |
-
# Inject JavaScript to pass dish name dynamically
|
| 107 |
-
gr.HTML("""
|
| 108 |
-
<script>
|
| 109 |
-
function selectDish(dishName) {
|
| 110 |
-
const input = document.querySelector('input[aria-label="selected_dish_name"]');
|
| 111 |
-
input.value = dishName;
|
| 112 |
-
input.dispatchEvent(new Event('input', { bubbles: true }));
|
| 113 |
-
}
|
| 114 |
-
</script>
|
| 115 |
-
""")
|
| 116 |
-
|
| 117 |
-
demo.launch()
|
|
|
|
| 22 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 23 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 24 |
|
| 25 |
+
# Function to filter dishes by category
|
| 26 |
+
def get_dish_list(category):
|
| 27 |
+
if category == "ALL":
|
| 28 |
+
return [dish["name"] for dish in menu_data]
|
| 29 |
+
return [dish["name"] for dish in menu_data if dish["category"] == category]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Function to fetch dish details
|
| 32 |
def get_dish_details(dish_name):
|
| 33 |
for dish in menu_data:
|
| 34 |
+
if dish["name"] == dish_name:
|
| 35 |
return dish["image"], dish["name"], dish["description"]
|
| 36 |
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available."
|
| 37 |
|
|
|
|
| 42 |
return "β οΈ Please select a dish before placing an order."
|
| 43 |
|
| 44 |
# Main Gradio App
|
| 45 |
+
def gradio_app():
|
| 46 |
+
with gr.Blocks() as demo:
|
| 47 |
+
gr.HTML("<h1 style='text-align: center;'>π Biryani Hub Menu π</h1>")
|
| 48 |
+
|
| 49 |
+
# Category Selection
|
| 50 |
+
gr.Markdown("### Select a Category")
|
| 51 |
+
category_dropdown = gr.Radio(choices=["ALL", "VEGAN", "HALAL"], label="Categories", value="ALL")
|
| 52 |
+
|
| 53 |
+
# Dish Selection
|
| 54 |
+
gr.Markdown("### Select a Dish")
|
| 55 |
+
dish_selector = gr.Radio(label="Available Dishes", choices=get_dish_list("ALL"))
|
| 56 |
+
|
| 57 |
+
# Dish Details Section
|
| 58 |
+
gr.Markdown("### Dish Details")
|
| 59 |
+
with gr.Row():
|
| 60 |
+
dish_image = gr.Image(label="Dish Image", height=200, width=200)
|
| 61 |
+
with gr.Column():
|
| 62 |
+
dish_name = gr.Textbox(label="Dish Name", interactive=False)
|
| 63 |
+
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 64 |
+
spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="πΆ Medium")
|
| 65 |
+
portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="π½ Medium")
|
| 66 |
+
place_order_btn = gr.Button("Place Order")
|
| 67 |
+
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 68 |
+
|
| 69 |
+
# Update dish list dynamically
|
| 70 |
+
def update_dish_list(category):
|
| 71 |
+
return gr.update(choices=get_dish_list(category))
|
| 72 |
+
|
| 73 |
+
category_dropdown.change(fn=update_dish_list, inputs=category_dropdown, outputs=dish_selector)
|
| 74 |
+
|
| 75 |
+
# Update dish details dynamically
|
| 76 |
+
def update_dish_details(dish_name_input):
|
| 77 |
+
return get_dish_details(dish_name_input)
|
| 78 |
+
|
| 79 |
+
dish_selector.change(fn=update_dish_details, inputs=dish_selector,
|
| 80 |
+
outputs=[dish_image, dish_name, dish_description])
|
| 81 |
+
|
| 82 |
+
# Place order functionality
|
| 83 |
+
place_order_btn.click(fn=place_order,
|
| 84 |
+
inputs=[dish_name, spice_dropdown, portion_dropdown],
|
| 85 |
+
outputs=order_status)
|
| 86 |
+
|
| 87 |
+
return demo
|
| 88 |
+
|
| 89 |
+
# Launch the app
|
| 90 |
+
gradio_app().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|