Spaces:
Sleeping
Sleeping
Commit
•
f70a567
1
Parent(s):
1dd0851
Update app.py (#5)
Browse files- Update app.py (07a52fe01e01e41bb664c1f7cbd36cf449e5b86a)
Co-authored-by: Trần Thanh Tùng <[email protected]>
app.py
CHANGED
@@ -14,12 +14,17 @@ def calculate_total_calories(user_input):
|
|
14 |
for item in menu_items:
|
15 |
# Split the menu item into quantity and item name
|
16 |
parts = item.strip().split(' ', 1)
|
17 |
-
|
18 |
if len(parts) == 2:
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
else:
|
22 |
-
quantity = 1
|
23 |
item_name = item.strip()
|
24 |
|
25 |
# Calculate the similarity scores between the item name and menu item names
|
@@ -38,12 +43,18 @@ def calculate_total_calories(user_input):
|
|
38 |
# Get the closest match menu item details
|
39 |
closest_match = df_menu.loc[closest_match_index]
|
40 |
menu_name = closest_match['food']
|
41 |
-
unit = closest_match['
|
42 |
calories = closest_match['calo']
|
|
|
43 |
|
44 |
# Calculate the total calories for the current menu item
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
results.append("Tên món ăn: " + menu_name)
|
48 |
results.append("Số lượng: " + str(quantity))
|
49 |
results.append("Đơn vị: " + unit)
|
|
|
14 |
for item in menu_items:
|
15 |
# Split the menu item into quantity and item name
|
16 |
parts = item.strip().split(' ', 1)
|
17 |
+
|
18 |
if len(parts) == 2:
|
19 |
+
quantity_str = parts[0]
|
20 |
+
if quantity_str.isdigit():
|
21 |
+
quantity = int(quantity_str)
|
22 |
+
item_name = parts[1]
|
23 |
+
else:
|
24 |
+
quantity = 1
|
25 |
+
item_name = item.strip()
|
26 |
else:
|
27 |
+
quantity = 1
|
28 |
item_name = item.strip()
|
29 |
|
30 |
# Calculate the similarity scores between the item name and menu item names
|
|
|
43 |
# Get the closest match menu item details
|
44 |
closest_match = df_menu.loc[closest_match_index]
|
45 |
menu_name = closest_match['food']
|
46 |
+
unit = closest_match['unit']
|
47 |
calories = closest_match['calo']
|
48 |
+
calories_per_unit = closest_match['calo_per_unit']
|
49 |
|
50 |
# Calculate the total calories for the current menu item
|
51 |
+
unit_spec = ['ml','g','gram']
|
52 |
+
if unit in unit_spec:
|
53 |
+
item_calories = calories_per_unit * quantity
|
54 |
+
total_calories += item_calories
|
55 |
+
else:
|
56 |
+
item_calories = calories * quantity
|
57 |
+
total_calories += item_calories
|
58 |
results.append("Tên món ăn: " + menu_name)
|
59 |
results.append("Số lượng: " + str(quantity))
|
60 |
results.append("Đơn vị: " + unit)
|