Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,6 +56,22 @@ nutritional_data = {
|
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def optimize_dishes_for_budget(city, daily_budget):
|
| 60 |
# Extracting cost, calories, and protein data for the selected city
|
| 61 |
costs = [nutritional_data[dish][city] for dish in nutritional_data]
|
|
@@ -106,18 +122,28 @@ def create_interface():
|
|
| 106 |
city_selector = gr.Dropdown(choices=cities, label="Select City")
|
| 107 |
budget_input = gr.Number(label="Daily Budget (₹)", value=300)
|
| 108 |
|
|
|
|
| 109 |
optimize_button = gr.Button("Optimize Nutrition")
|
|
|
|
|
|
|
| 110 |
optimization_output = gr.Markdown(label="Optimization Results")
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
# Function to handle optimization
|
| 113 |
def run_optimization(city, daily_budget):
|
| 114 |
return optimize_dishes_for_budget(city, daily_budget)
|
| 115 |
|
|
|
|
| 116 |
optimize_button.click(fn=run_optimization, inputs=[city_selector, budget_input], outputs=optimization_output)
|
| 117 |
|
| 118 |
gr.Row([city_selector, budget_input])
|
| 119 |
gr.Row(optimize_button)
|
| 120 |
gr.Row(optimization_output)
|
|
|
|
|
|
|
| 121 |
|
| 122 |
return demo
|
| 123 |
|
|
|
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
+
def display_dishes_in_city(city):
|
| 60 |
+
"""Displays all dishes available in the selected city with their nutritional information and cost."""
|
| 61 |
+
result_str = f"### Available Dishes in {city}:\n"
|
| 62 |
+
for dish, info in nutritional_data.items():
|
| 63 |
+
result_str += f"- **{dish}**\n"
|
| 64 |
+
result_str += f" - Cost: ₹{info[city]}\n"
|
| 65 |
+
result_str += f" - Energy: {info['Energy (kcal)']} kcal\n"
|
| 66 |
+
result_str += f" - Protein: {info['Protein (g)']} g\n"
|
| 67 |
+
result_str += f" - Fat: {info['Fat (g)']} g\n"
|
| 68 |
+
result_str += f" - Carbohydrate: {info['Carbohydrate (g)']} g\n"
|
| 69 |
+
result_str += f" - Fiber: {info['Fiber (g)']} g\n"
|
| 70 |
+
result_str += f" - Calcium: {info['Calcium (mg)']} mg\n"
|
| 71 |
+
result_str += f" - Iron: {info['Iron (mg)']} mg\n"
|
| 72 |
+
result_str += f" - Vitamin C: {info['Vitamin C (mg)']} mg\n\n"
|
| 73 |
+
return result_str
|
| 74 |
+
|
| 75 |
def optimize_dishes_for_budget(city, daily_budget):
|
| 76 |
# Extracting cost, calories, and protein data for the selected city
|
| 77 |
costs = [nutritional_data[dish][city] for dish in nutritional_data]
|
|
|
|
| 122 |
city_selector = gr.Dropdown(choices=cities, label="Select City")
|
| 123 |
budget_input = gr.Number(label="Daily Budget (₹)", value=300)
|
| 124 |
|
| 125 |
+
show_all_dishes_button = gr.Button("Show All Available Dishes")
|
| 126 |
optimize_button = gr.Button("Optimize Nutrition")
|
| 127 |
+
|
| 128 |
+
all_dishes_output = gr.Markdown(label="All Available Dishes")
|
| 129 |
optimization_output = gr.Markdown(label="Optimization Results")
|
| 130 |
|
| 131 |
+
# Function to handle showing all dishes
|
| 132 |
+
def show_all_dishes(city):
|
| 133 |
+
return display_dishes_in_city(city)
|
| 134 |
+
|
| 135 |
# Function to handle optimization
|
| 136 |
def run_optimization(city, daily_budget):
|
| 137 |
return optimize_dishes_for_budget(city, daily_budget)
|
| 138 |
|
| 139 |
+
show_all_dishes_button.click(fn=show_all_dishes, inputs=[city_selector], outputs=all_dishes_output)
|
| 140 |
optimize_button.click(fn=run_optimization, inputs=[city_selector, budget_input], outputs=optimization_output)
|
| 141 |
|
| 142 |
gr.Row([city_selector, budget_input])
|
| 143 |
gr.Row(optimize_button)
|
| 144 |
gr.Row(optimization_output)
|
| 145 |
+
gr.Row(show_all_dishes_button)
|
| 146 |
+
gr.Row(all_dishes_output)
|
| 147 |
|
| 148 |
return demo
|
| 149 |
|