Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,22 +56,6 @@ nutritional_data = {
|
|
| 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} (Data pulled from leading food aggregators):\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]
|
|
@@ -92,23 +76,31 @@ def optimize_dishes_for_budget(city, daily_budget):
|
|
| 92 |
result = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs')
|
| 93 |
|
| 94 |
if result.success:
|
| 95 |
-
selected_dishes = [
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
# Create the summary of the budget allocation
|
| 102 |
result_str = f"### For ₹{daily_budget:.2f}, you can have:\n"
|
| 103 |
-
for dish
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
result_str += f" - Total Energy: {nutritional_data[dish]['Energy (kcal)'] * qty:.2f} kcal\n"
|
| 109 |
-
result_str += f" - Total Protein: {nutritional_data[dish]['Protein (g)'] * qty:.2f} g\n\n"
|
| 110 |
|
| 111 |
-
result_str += f"
|
| 112 |
result_str += f"### Total Calories: {total_calories:.2f} kcal\n"
|
| 113 |
result_str += f"### Total Protein: {total_protein:.2f} g\n"
|
| 114 |
|
|
@@ -116,6 +108,22 @@ def optimize_dishes_for_budget(city, daily_budget):
|
|
| 116 |
else:
|
| 117 |
return f"No feasible solution found for ₹{daily_budget:.2f} in {city}."
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
# Gradio Interface
|
| 120 |
def create_interface():
|
| 121 |
cities = ["Chennai", "Bengaluru", "Hyderabad", "New Delhi"]
|
|
|
|
| 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]
|
|
|
|
| 76 |
result = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs')
|
| 77 |
|
| 78 |
if result.success:
|
| 79 |
+
selected_dishes = []
|
| 80 |
+
for i, qty in enumerate(result.x):
|
| 81 |
+
if qty > 0:
|
| 82 |
+
dish_name = list(nutritional_data.keys())[i]
|
| 83 |
+
selected_dishes.append({
|
| 84 |
+
"dish": dish_name,
|
| 85 |
+
"quantity": qty,
|
| 86 |
+
"cost": nutritional_data[dish_name][city] * qty,
|
| 87 |
+
"energy": nutritional_data[dish_name]["Energy (kcal)"] * qty,
|
| 88 |
+
"protein": nutritional_data[dish_name]["Protein (g)"] * qty
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
total_cost = sum(d['cost'] for d in selected_dishes)
|
| 92 |
+
total_calories = sum(d['energy'] for d in selected_dishes)
|
| 93 |
+
total_protein = sum(d['protein'] for d in selected_dishes)
|
| 94 |
|
| 95 |
# Create the summary of the budget allocation
|
| 96 |
result_str = f"### For ₹{daily_budget:.2f}, you can have:\n"
|
| 97 |
+
for dish in selected_dishes:
|
| 98 |
+
result_str += f"- **{dish['quantity']:.2f} portions of {dish['dish']}** at ₹{nutritional_data[dish['dish']][city]} per portion\n"
|
| 99 |
+
result_str += f" - Total Cost: ₹{dish['cost']:.2f}\n"
|
| 100 |
+
result_str += f" - Total Energy: {dish['energy']:.2f} kcal\n"
|
| 101 |
+
result_str += f" - Total Protein: {dish['protein']:.2f} g\n\n"
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
result_str += f"### Total Cost: ₹{total_cost:.2f}\n"
|
| 104 |
result_str += f"### Total Calories: {total_calories:.2f} kcal\n"
|
| 105 |
result_str += f"### Total Protein: {total_protein:.2f} g\n"
|
| 106 |
|
|
|
|
| 108 |
else:
|
| 109 |
return f"No feasible solution found for ₹{daily_budget:.2f} in {city}."
|
| 110 |
|
| 111 |
+
def display_dishes_in_city(city):
|
| 112 |
+
"""Displays all dishes available in the selected city with their nutritional information and cost."""
|
| 113 |
+
result_str = f"### Available Dishes in {city} (Data pulled from leading food aggregators):\n"
|
| 114 |
+
for dish, info in nutritional_data.items():
|
| 115 |
+
result_str += f"- **{dish}**\n"
|
| 116 |
+
result_str += f" - Cost: ₹{info[city]}\n"
|
| 117 |
+
result_str += f" - Energy: {info['Energy (kcal)']} kcal\n"
|
| 118 |
+
result_str += f" - Protein: {info['Protein (g)']} g\n"
|
| 119 |
+
result_str += f" - Fat: {info['Fat (g)']} g\n"
|
| 120 |
+
result_str += f" - Carbohydrate: {info['Carbohydrate (g)']} g\n"
|
| 121 |
+
result_str += f" - Fiber: {info['Fiber (g)']} g\n"
|
| 122 |
+
result_str += f" - Calcium: {info['Calcium (mg)']} mg\n"
|
| 123 |
+
result_str += f" - Iron: {info['Iron (mg)']} mg\n"
|
| 124 |
+
result_str += f" - Vitamin C: {info['Vitamin C (mg)']} mg\n\n"
|
| 125 |
+
return result_str
|
| 126 |
+
|
| 127 |
# Gradio Interface
|
| 128 |
def create_interface():
|
| 129 |
cities = ["Chennai", "Bengaluru", "Hyderabad", "New Delhi"]
|