Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,129 +1,127 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 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 |
-
"category": "Allergenic",
|
| 32 |
-
},
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
def filter_dishes(category):
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
with gr.Blocks() as demo:
|
| 55 |
-
gr.
|
| 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 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
#
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
inputs=[selected_dish, gr.Textbox(value=portion, visible=False)],
|
| 117 |
-
outputs=portion_image,
|
| 118 |
-
)
|
| 119 |
-
|
| 120 |
-
# Link spice level buttons to display the spice level
|
| 121 |
-
for spice_button, spice in zip(spice_buttons, ["Mild", "Medium", "Spicy"]):
|
| 122 |
-
spice_button.click(
|
| 123 |
-
fn=spice_level_selection,
|
| 124 |
-
inputs=[gr.Textbox(value=spice, visible=False)],
|
| 125 |
-
outputs=dish_name_display
|
| 126 |
-
)
|
| 127 |
-
|
| 128 |
-
# Launch the Gradio app
|
| 129 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Extended menu data with dish details
|
| 4 |
+
menu_data = [
|
| 5 |
+
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
| 7 |
+
"description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
|
| 8 |
+
"spice_level": "Medium", "portion_size": "Regular"},
|
| 9 |
+
{"name": "Chicken Biryani", "category": "HALAL",
|
| 10 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
|
| 11 |
+
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
|
| 12 |
+
"spice_level": "High", "portion_size": "Large"},
|
| 13 |
+
{"name": "Paneer Butter Masala", "category": "VEGAN",
|
| 14 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
|
| 15 |
+
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 16 |
+
"spice_level": "Mild", "portion_size": "Medium"},
|
| 17 |
+
{"name": "Beef Steak", "category": "HALAL",
|
| 18 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Beef_Steak.jpg",
|
| 19 |
+
"description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
|
| 20 |
+
"spice_level": "Medium", "portion_size": "Large"},
|
| 21 |
+
{"name": "Mushroom Soup", "category": "VEGAN",
|
| 22 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/3/3c/Mushroom_Soup.jpg",
|
| 23 |
+
"description": "Creamy mushroom soup with fresh herbs.",
|
| 24 |
+
"spice_level": "Mild", "portion_size": "Small"}
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 28 |
+
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 29 |
+
|
| 30 |
+
# Function to filter dishes based on category
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def filter_dishes(category):
|
| 32 |
+
if category == "ALL":
|
| 33 |
+
return menu_data
|
| 34 |
+
return [dish for dish in menu_data if dish["category"] == category]
|
| 35 |
+
|
| 36 |
+
# Function to display dishes with images
|
| 37 |
+
def display_dishes(category):
|
| 38 |
+
filtered_dishes = filter_dishes(category)
|
| 39 |
+
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
| 40 |
+
for dish in filtered_dishes:
|
| 41 |
+
html_content += f"""
|
| 42 |
+
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 43 |
+
padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
|
| 44 |
+
onclick='selectDish(\"{dish['name']}\")'>
|
| 45 |
+
<img src='{dish['image']}' alt='{dish['name']}'
|
| 46 |
+
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 47 |
+
<h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
|
| 48 |
+
</div>
|
| 49 |
+
"""
|
| 50 |
+
html_content += "</div>"
|
| 51 |
+
return html_content
|
| 52 |
+
|
| 53 |
+
# Function to fetch details of the selected dish
|
| 54 |
+
def get_dish_details(dish_name):
|
| 55 |
+
for dish in menu_data:
|
| 56 |
+
if dish["name"] == dish_name:
|
| 57 |
+
return dish["image"], dish["name"], dish["description"], "πΆ Medium", "π½ Medium"
|
| 58 |
+
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "N/A", "N/A"
|
| 59 |
+
|
| 60 |
+
# Function to simulate placing an order
|
| 61 |
+
def place_order(dish_name, spice_level, portion_size):
|
| 62 |
+
return f"β
Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
|
| 63 |
+
|
| 64 |
+
# Main Gradio App
|
| 65 |
with gr.Blocks() as demo:
|
| 66 |
+
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 67 |
+
|
| 68 |
+
# Buttons for category selection
|
| 69 |
+
gr.Markdown("### Select a Category")
|
| 70 |
+
with gr.Row():
|
| 71 |
+
btn_all = gr.Button("ALL")
|
| 72 |
+
btn_vegan = gr.Button("VEGAN")
|
| 73 |
+
btn_halal = gr.Button("HALAL")
|
| 74 |
+
|
| 75 |
+
# Dish display section
|
| 76 |
+
gr.Markdown("### Available Dishes")
|
| 77 |
+
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 78 |
+
|
| 79 |
+
# Dish Details Section
|
| 80 |
+
gr.Markdown("### Dish Details")
|
| 81 |
+
with gr.Row():
|
| 82 |
+
dish_image = gr.Image(label="Dish Image", height=200, width=200)
|
| 83 |
+
with gr.Column():
|
| 84 |
+
dish_name = gr.Textbox(label="Dish Name", interactive=False)
|
| 85 |
+
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 86 |
+
spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="πΆ Medium")
|
| 87 |
+
portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="π½ Medium")
|
| 88 |
+
|
| 89 |
+
# Place Order Button
|
| 90 |
+
place_order_btn = gr.Button("Place Order")
|
| 91 |
+
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 92 |
+
|
| 93 |
+
# Event: Update dish display for selected category
|
| 94 |
+
def update_dishes(category):
|
| 95 |
+
return gr.update(value=display_dishes(category))
|
| 96 |
+
|
| 97 |
+
btn_all.click(fn=lambda: update_dishes("ALL"), outputs=dish_display)
|
| 98 |
+
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 99 |
+
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 100 |
+
|
| 101 |
+
# Event: Show dish details when a dish is selected
|
| 102 |
+
def show_dish_details(dish_name):
|
| 103 |
+
image, name, description, spice, portion = get_dish_details(dish_name)
|
| 104 |
+
return image, name, description, spice, portion
|
| 105 |
+
|
| 106 |
+
# Hidden input to receive dish name from JavaScript
|
| 107 |
+
selected_dish_name = gr.Textbox(visible=False)
|
| 108 |
+
selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
|
| 109 |
+
outputs=[dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown])
|
| 110 |
+
|
| 111 |
+
# Event: Place order button
|
| 112 |
+
place_order_btn.click(fn=place_order,
|
| 113 |
+
inputs=[dish_name, spice_dropdown, portion_dropdown],
|
| 114 |
+
outputs=order_status)
|
| 115 |
+
|
| 116 |
+
# Inject JavaScript to handle clicks and pass dish names
|
| 117 |
+
gr.HTML("""
|
| 118 |
+
<script>
|
| 119 |
+
function selectDish(dishName) {
|
| 120 |
+
let input = document.querySelector('input[aria-label="selected_dish_name"]');
|
| 121 |
+
input.value = dishName;
|
| 122 |
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
| 123 |
+
}
|
| 124 |
+
</script>
|
| 125 |
+
""")
|
| 126 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
demo.launch()
|