Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,6 +56,22 @@ nutritional_data = {
|
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def optimize_nutrition_in_city(city, target_calories, target_protein, max_cost):
|
| 60 |
# Extracting cost, calories, and protein data for the selected city
|
| 61 |
costs = [nutritional_data[dish][city] for dish in nutritional_data]
|
|
@@ -112,17 +128,27 @@ def create_interface():
|
|
| 112 |
protein_target = gr.Number(label="Target Protein (g)", value=25)
|
| 113 |
cost_limit = gr.Number(label="Maximum Cost (₹)", value=300)
|
| 114 |
|
|
|
|
| 115 |
optimize_button = gr.Button("Optimize")
|
|
|
|
|
|
|
| 116 |
optimization_output = gr.Markdown(label="Optimization Results")
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
# Function to handle optimization
|
| 119 |
def run_optimization(city, target_calories, target_protein, max_cost):
|
| 120 |
return optimize_nutrition_in_city(city, target_calories, target_protein, max_cost)
|
| 121 |
|
|
|
|
| 122 |
optimize_button.click(fn=run_optimization, inputs=[city_selector, energy_target, protein_target, cost_limit], outputs=optimization_output)
|
| 123 |
|
| 124 |
gr.Row([city_selector, energy_target, protein_target, cost_limit])
|
| 125 |
-
gr.Row(
|
|
|
|
|
|
|
| 126 |
|
| 127 |
return demo
|
| 128 |
|
|
|
|
| 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_nutrition_in_city(city, target_calories, target_protein, max_cost):
|
| 76 |
# Extracting cost, calories, and protein data for the selected city
|
| 77 |
costs = [nutritional_data[dish][city] for dish in nutritional_data]
|
|
|
|
| 128 |
protein_target = gr.Number(label="Target Protein (g)", value=25)
|
| 129 |
cost_limit = gr.Number(label="Maximum Cost (₹)", value=300)
|
| 130 |
|
| 131 |
+
display_dishes_button = gr.Button("Display Available Dishes")
|
| 132 |
optimize_button = gr.Button("Optimize")
|
| 133 |
+
|
| 134 |
+
dishes_output = gr.Markdown(label="Available Dishes")
|
| 135 |
optimization_output = gr.Markdown(label="Optimization Results")
|
| 136 |
|
| 137 |
+
# Function to handle displaying dishes
|
| 138 |
+
def display_dishes(city):
|
| 139 |
+
return display_dishes_in_city(city)
|
| 140 |
+
|
| 141 |
# Function to handle optimization
|
| 142 |
def run_optimization(city, target_calories, target_protein, max_cost):
|
| 143 |
return optimize_nutrition_in_city(city, target_calories, target_protein, max_cost)
|
| 144 |
|
| 145 |
+
display_dishes_button.click(fn=display_dishes, inputs=[city_selector], outputs=dishes_output)
|
| 146 |
optimize_button.click(fn=run_optimization, inputs=[city_selector, energy_target, protein_target, cost_limit], outputs=optimization_output)
|
| 147 |
|
| 148 |
gr.Row([city_selector, energy_target, protein_target, cost_limit])
|
| 149 |
+
gr.Row(display_dishes_button, optimize_button)
|
| 150 |
+
gr.Row(dishes_output)
|
| 151 |
+
gr.Row(optimization_output)
|
| 152 |
|
| 153 |
return demo
|
| 154 |
|