Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,39 @@
|
|
| 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 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
}
|
| 41 |
-
.menu-item:hover {
|
| 42 |
-
background-color: #f0f0f0;
|
| 43 |
-
}
|
| 44 |
-
.menu-container {
|
| 45 |
-
margin-top: 20px;
|
| 46 |
-
}
|
| 47 |
-
""") as demo:
|
| 48 |
-
gr.Markdown("# Menu")
|
| 49 |
-
|
| 50 |
-
# Popup display area
|
| 51 |
-
popup_output = gr.Markdown("### Select an item to view details.")
|
| 52 |
-
|
| 53 |
-
# Display the menu items
|
| 54 |
-
with gr.Column(elem_id="menu-container"):
|
| 55 |
-
for item in menu_items:
|
| 56 |
-
with gr.Row(elem_classes=["menu-item"]):
|
| 57 |
-
# Display item name with a clickable action
|
| 58 |
-
button = gr.Button(item["name"], elem_id=f"{item['name']}-button")
|
| 59 |
-
button.click(
|
| 60 |
-
fn=show_popup,
|
| 61 |
-
inputs=[],
|
| 62 |
-
outputs=popup_output,
|
| 63 |
-
_js=f"() => ['{item['name']}', '{item['description']}']"
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
# Popup section to show details
|
| 67 |
-
gr.Markdown("## Selected Item Details")
|
| 68 |
-
gr.Box(popup_output)
|
| 69 |
-
|
| 70 |
-
return demo
|
| 71 |
-
|
| 72 |
-
# Render the app
|
| 73 |
-
demo = render_menu()
|
| 74 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from components.cards import create_food_card
|
| 3 |
+
from components.data import FOOD_DATA
|
| 4 |
+
|
| 5 |
+
# Function to display the food card when an item is selected
|
| 6 |
+
def display_card(food_name):
|
| 7 |
+
if food_name in FOOD_DATA:
|
| 8 |
+
return create_food_card(food_name)
|
| 9 |
+
else:
|
| 10 |
+
return "<p>No data available for the selected item.</p>"
|
| 11 |
+
|
| 12 |
+
# List of food items
|
| 13 |
+
food_items = list(FOOD_DATA.keys())
|
| 14 |
+
|
| 15 |
+
# Gradio app interface
|
| 16 |
+
with gr.Blocks(css="styles.css") as app:
|
| 17 |
+
gr.Markdown("# 🍽️ Indian & Chinese Food Nutritional Information App")
|
| 18 |
+
gr.Markdown(
|
| 19 |
+
"""
|
| 20 |
+
### Explore Popular Dishes 🍛
|
| 21 |
+
Select a dish from the dropdown menu to see its image, nutritional facts, and portion size.
|
| 22 |
+
"""
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
with gr.Row():
|
| 26 |
+
with gr.Column(scale=1):
|
| 27 |
+
food_dropdown = gr.Dropdown(
|
| 28 |
+
label="Select a Dish",
|
| 29 |
+
choices=food_items,
|
| 30 |
+
value=food_items[0],
|
| 31 |
+
)
|
| 32 |
+
with gr.Column(scale=2):
|
| 33 |
+
display_area = gr.HTML(value=create_food_card(food_items[0]))
|
| 34 |
+
|
| 35 |
+
# Event to update card content when a food item is selected
|
| 36 |
+
food_dropdown.change(display_card, inputs=food_dropdown, outputs=display_area)
|
| 37 |
+
|
| 38 |
+
# Launch the app
|
| 39 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|