Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,19 +44,15 @@ def get_dish_details(dish_name):
|
|
| 44 |
return dish["image"], dish["name"], dish["description"], dish["spice_level"], dish["portion_size"]
|
| 45 |
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "πΆ Mild", "π§ Small"
|
| 46 |
|
| 47 |
-
# Function to confirm an order
|
| 48 |
-
def place_order(dish_name, spice_level, portion_size):
|
| 49 |
-
return f"β
Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
|
| 50 |
-
|
| 51 |
# Create the Gradio app
|
| 52 |
with gr.Blocks() as demo:
|
| 53 |
gr.HTML("<h1 style='text-align: center;'>π Biryani Hub Menu π</h1>")
|
| 54 |
|
| 55 |
-
# JavaScript
|
| 56 |
gr.HTML("""
|
| 57 |
<script>
|
| 58 |
function selectDish(dishName) {
|
| 59 |
-
|
| 60 |
if (input) {
|
| 61 |
input.value = dishName;
|
| 62 |
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
@@ -86,10 +82,6 @@ with gr.Blocks() as demo:
|
|
| 86 |
portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="π§ Small")
|
| 87 |
close_popup = gr.Button("Close")
|
| 88 |
|
| 89 |
-
place_order_btn = gr.Button("Place Order")
|
| 90 |
-
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 91 |
-
|
| 92 |
-
# Update the displayed dishes
|
| 93 |
def update_dishes(category):
|
| 94 |
return gr.update(value=display_dishes(category))
|
| 95 |
|
|
@@ -97,7 +89,6 @@ with gr.Blocks() as demo:
|
|
| 97 |
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 98 |
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 99 |
|
| 100 |
-
# Show dish details in pop-up
|
| 101 |
selected_dish_name = gr.Textbox(visible=False)
|
| 102 |
selected_dish_name.change(
|
| 103 |
fn=lambda dish_name: (*get_dish_details(dish_name), gr.update(visible=True)),
|
|
@@ -105,15 +96,6 @@ with gr.Blocks() as demo:
|
|
| 105 |
outputs=[dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown, popup],
|
| 106 |
)
|
| 107 |
|
| 108 |
-
# Close the pop-up
|
| 109 |
close_popup.click(fn=lambda: gr.update(visible=False), outputs=popup)
|
| 110 |
|
| 111 |
-
# Place the order
|
| 112 |
-
place_order_btn.click(
|
| 113 |
-
fn=place_order,
|
| 114 |
-
inputs=[dish_name, spice_dropdown, portion_dropdown],
|
| 115 |
-
outputs=order_status,
|
| 116 |
-
)
|
| 117 |
-
|
| 118 |
demo.launch()
|
| 119 |
-
|
|
|
|
| 44 |
return dish["image"], dish["name"], dish["description"], dish["spice_level"], dish["portion_size"]
|
| 45 |
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "πΆ Mild", "π§ Small"
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Create the Gradio app
|
| 48 |
with gr.Blocks() as demo:
|
| 49 |
gr.HTML("<h1 style='text-align: center;'>π Biryani Hub Menu π</h1>")
|
| 50 |
|
| 51 |
+
# JavaScript for dish selection
|
| 52 |
gr.HTML("""
|
| 53 |
<script>
|
| 54 |
function selectDish(dishName) {
|
| 55 |
+
const input = document.querySelector('input[aria-label="selected_dish_name"]');
|
| 56 |
if (input) {
|
| 57 |
input.value = dishName;
|
| 58 |
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
|
|
| 82 |
portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="π§ Small")
|
| 83 |
close_popup = gr.Button("Close")
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
def update_dishes(category):
|
| 86 |
return gr.update(value=display_dishes(category))
|
| 87 |
|
|
|
|
| 89 |
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 90 |
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 91 |
|
|
|
|
| 92 |
selected_dish_name = gr.Textbox(visible=False)
|
| 93 |
selected_dish_name.change(
|
| 94 |
fn=lambda dish_name: (*get_dish_details(dish_name), gr.update(visible=True)),
|
|
|
|
| 96 |
outputs=[dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown, popup],
|
| 97 |
)
|
| 98 |
|
|
|
|
| 99 |
close_popup.click(fn=lambda: gr.update(visible=False), outputs=popup)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
demo.launch()
|
|
|