Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 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",
|
|
@@ -30,79 +30,86 @@ def filter_dishes(category):
|
|
| 30 |
return menu_data
|
| 31 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 32 |
|
| 33 |
-
# Function to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def get_dish_details(dish_name):
|
| 35 |
for dish in menu_data:
|
| 36 |
if dish["name"] == dish_name:
|
| 37 |
-
return (dish["image"], dish["name"], dish["description"],
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Main Gradio App
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 43 |
|
| 44 |
-
#
|
| 45 |
gr.Markdown("### Select a Category")
|
| 46 |
with gr.Row():
|
| 47 |
btn_all = gr.Button("ALL")
|
| 48 |
btn_vegan = gr.Button("VEGAN")
|
| 49 |
btn_halal = gr.Button("HALAL")
|
| 50 |
|
| 51 |
-
# Dish
|
| 52 |
gr.Markdown("### Available Dishes")
|
| 53 |
-
dish_display = gr.HTML(value="")
|
| 54 |
-
|
| 55 |
-
# Dish
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 67 |
def update_dishes(category):
|
| 68 |
-
|
| 69 |
-
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
| 70 |
-
for dish in dishes:
|
| 71 |
-
html_content += f"""
|
| 72 |
-
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 73 |
-
padding: 10px; border-radius: 10px; width: 200px;'
|
| 74 |
-
onclick='selectDish("{dish['name']}")'>
|
| 75 |
-
<img src='{dish['image']}' alt='{dish['name']}'
|
| 76 |
-
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 77 |
-
<h4 style='margin-top: 10px; font-size: 16px;'>{dish['name']}</h4>
|
| 78 |
-
</div>
|
| 79 |
-
"""
|
| 80 |
-
html_content += "</div>"
|
| 81 |
-
return html_content, gr.update(visible=False)
|
| 82 |
-
|
| 83 |
-
# Event: Show dish details when a dish is selected
|
| 84 |
-
def show_dish_details(dish_name):
|
| 85 |
-
image, name, description, spice, portion = get_dish_details(dish_name)
|
| 86 |
-
return gr.update(visible=True), image, name, description, spice, portion
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
#
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=[dish_display, dish_details])
|
| 96 |
|
| 97 |
-
#
|
| 98 |
selected_dish_name = gr.Textbox(visible=False)
|
|
|
|
|
|
|
| 99 |
selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
|
| 100 |
-
outputs=[
|
| 101 |
|
| 102 |
-
# Place
|
| 103 |
place_order_btn.click(fn=place_order, inputs=dish_name, outputs=order_status)
|
| 104 |
|
| 105 |
-
# Inject JavaScript
|
| 106 |
gr.HTML("""
|
| 107 |
<script>
|
| 108 |
function selectDish(dishName) {
|
|
@@ -113,4 +120,4 @@ with gr.Blocks() as demo:
|
|
| 113 |
""")
|
| 114 |
|
| 115 |
# Launch the app
|
| 116 |
-
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",
|
|
|
|
| 30 |
return menu_data
|
| 31 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 32 |
|
| 33 |
+
# Function to display dishes with images
|
| 34 |
+
def display_dishes(category):
|
| 35 |
+
filtered_dishes = filter_dishes(category)
|
| 36 |
+
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
| 37 |
+
for dish in filtered_dishes:
|
| 38 |
+
html_content += f"""
|
| 39 |
+
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 40 |
+
padding: 10px; border-radius: 10px; width: 200px;'
|
| 41 |
+
onclick='selectDish("{dish['name']}")'>
|
| 42 |
+
<img src='{dish['image']}' alt='{dish['name']}'
|
| 43 |
+
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 44 |
+
<h4 style='margin-top: 10px; font-size: 16px;'>{dish['name']}</h4>
|
| 45 |
+
</div>
|
| 46 |
+
"""
|
| 47 |
+
html_content += "</div>"
|
| 48 |
+
return html_content
|
| 49 |
+
|
| 50 |
+
# Function to fetch details of the selected dish
|
| 51 |
def get_dish_details(dish_name):
|
| 52 |
for dish in menu_data:
|
| 53 |
if dish["name"] == dish_name:
|
| 54 |
+
return (dish["image"], dish["name"], dish["description"],
|
| 55 |
+
dish["spice_level"], dish["portion_size"])
|
| 56 |
+
return ("https://via.placeholder.com/300x200", "Unknown Dish",
|
| 57 |
+
"No description available.", "N/A", "N/A")
|
| 58 |
+
|
| 59 |
+
# Function to simulate placing an order
|
| 60 |
+
def place_order(dish_name):
|
| 61 |
+
return f"Your order for '{dish_name}' has been placed successfully!"
|
| 62 |
|
| 63 |
# Main Gradio App
|
| 64 |
with gr.Blocks() as demo:
|
| 65 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 66 |
|
| 67 |
+
# Buttons for category selection
|
| 68 |
gr.Markdown("### Select a Category")
|
| 69 |
with gr.Row():
|
| 70 |
btn_all = gr.Button("ALL")
|
| 71 |
btn_vegan = gr.Button("VEGAN")
|
| 72 |
btn_halal = gr.Button("HALAL")
|
| 73 |
|
| 74 |
+
# Dish display section
|
| 75 |
gr.Markdown("### Available Dishes")
|
| 76 |
+
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 77 |
+
|
| 78 |
+
# Detailed Dish View
|
| 79 |
+
gr.Markdown("### Dish Details")
|
| 80 |
+
dish_image = gr.Image(label="Dish Image")
|
| 81 |
+
dish_name = gr.Textbox(label="Dish Name", interactive=False)
|
| 82 |
+
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 83 |
+
dish_spice = gr.Textbox(label="Spice Level", interactive=False)
|
| 84 |
+
dish_portion = gr.Textbox(label="Portion Size", interactive=False)
|
| 85 |
+
|
| 86 |
+
# Place Order Button
|
| 87 |
+
place_order_btn = gr.Button("Place Order")
|
| 88 |
+
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 89 |
+
|
| 90 |
+
# Event: Display dishes for selected category
|
| 91 |
def update_dishes(category):
|
| 92 |
+
return gr.update(value=display_dishes(category))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
btn_all.click(fn=lambda: update_dishes("ALL"), outputs=dish_display)
|
| 95 |
+
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 96 |
+
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 97 |
|
| 98 |
+
# Event: Show dish details
|
| 99 |
+
def show_dish_details(dish_name):
|
| 100 |
+
return get_dish_details(dish_name)
|
|
|
|
| 101 |
|
| 102 |
+
# Dummy HTML input for JS trigger
|
| 103 |
selected_dish_name = gr.Textbox(visible=False)
|
| 104 |
+
|
| 105 |
+
# Bind the selected dish name to the details display
|
| 106 |
selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
|
| 107 |
+
outputs=[dish_image, dish_name, dish_description, dish_spice, dish_portion])
|
| 108 |
|
| 109 |
+
# Event: Place Order Button
|
| 110 |
place_order_btn.click(fn=place_order, inputs=dish_name, outputs=order_status)
|
| 111 |
|
| 112 |
+
# Inject JavaScript to handle clicks and pass dish names
|
| 113 |
gr.HTML("""
|
| 114 |
<script>
|
| 115 |
function selectDish(dishName) {
|
|
|
|
| 120 |
""")
|
| 121 |
|
| 122 |
# Launch the app
|
| 123 |
+
demo.launch()
|