Download app.py from Subbu1304/menu: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/Subbu1304/menu/resolve/main/app.py
- Command line
-
hf download hf://spaces/Subbu1304/menu/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Subbu1304/menu/resolve/main/app.py
1.88 kB
| import gradio as gr | |
| # Food item data | |
| food_data = [ | |
| { | |
| "name": "Apple", | |
| "image": "apple.jpg", | |
| "nutrition": { | |
| "Calories": "52 kcal", | |
| "Proteins": "0.3 g", | |
| "Carbohydrates": "14 g" | |
| } | |
| }, | |
| { | |
| "name": "Banana", | |
| "image": "banana.jpg", | |
| "nutrition": { | |
| "Calories": "96 kcal", | |
| "Proteins": "1.3 g", | |
| "Carbohydrates": "27 g" | |
| } | |
| }, | |
| { | |
| "name": "Chicken Breast", | |
| "image": "chicken_breast.jpg", | |
| "nutrition": { | |
| "Calories": "165 kcal", | |
| "Proteins": "31 g", | |
| "Carbohydrates": "0 g" | |
| } | |
| }, | |
| { | |
| "name": "Rice", | |
| "image": "rice.jpg", | |
| "nutrition": { | |
| "Calories": "130 kcal", | |
| "Proteins": "2.7 g", | |
| "Carbohydrates": "28 g" | |
| } | |
| } | |
| ] | |
| # Function to show food details | |
| def food_details(food_name): | |
| # Find the food item by name | |
| food_item = next((food for food in food_data if food["name"] == food_name), None) | |
| if food_item: | |
| # Format nutrition details | |
| nutrition_details = "\n".join(f"{key}: {value}" for key, value in food_item["nutrition"].items()) | |
| return f"### {food_item['name']}\n\n**Nutrition Details:**\n\n{nutrition_details}" | |
| return "Food item not found." | |
| # Gradio Interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Food Nutrition App") | |
| # Food items gallery | |
| with gr.Row(): | |
| for food in food_data: | |
| with gr.Column(): | |
| gr.Markdown(f"### {food['name']}") | |
| food_button = gr.Button(image=food["image"]) | |
| food_button.click( | |
| food_details, | |
| inputs=gr.Textbox(value=food["name"], visible=False), | |
| outputs=gr.Markdown() | |
| ) | |
| demo.launch() | |