Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -84,16 +84,17 @@ You are tasked with analyzing the contents of a food label and evaluating its he
|
|
84 |
- Give Rating in large size text
|
85 |
- Based on the corrected food label and the user's profile, assign a health rating on a scale from 1 to 10 (where 10 is the healthiest).
|
86 |
- Consider the user's dietary preferences, health goals, allergies, and activity level in your rating.
|
87 |
-
-
|
88 |
-
- If the user should avoid the food altogether, assign a rating from 1 to 4.
|
89 |
- If the user should consume the food in moderation, assign a rating from 5 to 7.
|
90 |
- If the user can consume the food frequently, assign a rating from 8 to 10.
|
91 |
|
92 |
2. Health Analysis:
|
93 |
-
|
94 |
-
- Personalized Evaluation
|
95 |
-
- Advice
|
96 |
|
|
|
97 |
Ensure that the output is free from spelling mistakes and important points or warnings are clearly communicated with bold keywords and underline relevant details.
|
98 |
"""
|
99 |
|
@@ -112,11 +113,11 @@ def analyze_food_label(image_path, email):
|
|
112 |
if user:
|
113 |
user_profile = {
|
114 |
"BMI": user.get("bmi", "Not provided"),
|
115 |
-
"Allergies":
|
116 |
-
"Health Conditions": user.get("health_conditions",
|
117 |
"Dietary Preferences": user.get("dietary_preferences", "None"),
|
118 |
"Activity Level": user.get("activity_level", "Moderate"),
|
119 |
-
"Health Goals": user.get("health_goals", "General well-being")
|
120 |
}
|
121 |
|
122 |
llama_output = analyze_with_llama_index(corrected_text, user_profile)
|
@@ -164,7 +165,7 @@ def update_product_database(ocr_text, product_type=None, consumption_frequency=N
|
|
164 |
1. Correct any spelling mistakes or grammatical errors in the OCR text.
|
165 |
2. Extract and structure the following information:
|
166 |
- Product Name
|
167 |
-
- Brand Name (look for company names following by manufactured by or owned by or
|
168 |
- Weight in Grams/ML
|
169 |
- Nutritional information: Include the serving size (e.g., "per 100g", "per 200ml") as specified on the label. If multiple serving sizes are given, use the one that provides the most comprehensive nutritional breakdown.
|
170 |
- Ingredients
|
@@ -296,7 +297,7 @@ def home():
|
|
296 |
with st.container():
|
297 |
if register():
|
298 |
st.session_state.show_steps = False
|
299 |
-
st.rerun()
|
300 |
if st.button("Close Registration Form"):
|
301 |
st.session_state.show_steps = False
|
302 |
st.rerun()
|
@@ -359,7 +360,6 @@ def register():
|
|
359 |
st.markdown('<h2 style="font-size: 2.5rem;">User Registration</h2>', unsafe_allow_html=True)
|
360 |
st.info("Password must be at least 8 characters long and contain at least one uppercase letter, one digit, and one special character.")
|
361 |
|
362 |
-
|
363 |
with st.form("registration_form"):
|
364 |
name = st.text_input("Name *", key="register_name")
|
365 |
email = st.text_input("Email *", key="register_email")
|
@@ -368,8 +368,13 @@ def register():
|
|
368 |
age = st.number_input("Age *", min_value=1, max_value=120, key="register_age")
|
369 |
height = st.number_input("Height (in cm) *", min_value=50, max_value=250, key="register_height")
|
370 |
weight = st.number_input("Weight (in kg) *", min_value=10, max_value=300, key="register_weight")
|
371 |
-
|
372 |
-
|
|
|
|
|
|
|
|
|
|
|
373 |
activity_level = st.selectbox("Activity Level", ["Low", "Moderate", "High"], key="register_activity_level")
|
374 |
dietary_preferences = st.selectbox("Dietary Preferences", ["No preference","Vegetarian", "Vegan", "Gluten-Free", "Keto", "Paleo"], key="register_dietary_preferences")
|
375 |
health_goals = st.multiselect("Health Goals", ["Lose weight", "Gain muscle", "Maintain weight", "Improve stamina", "General well-being"], key="register_health_goals")
|
@@ -390,6 +395,11 @@ def register():
|
|
390 |
st.error("Password must be at least 8 characters long, contain one uppercase letter, one special character, and one digit.")
|
391 |
else:
|
392 |
bmi = calculate_bmi(weight, height)
|
|
|
|
|
|
|
|
|
|
|
393 |
user_data = {
|
394 |
"name": name,
|
395 |
"email": email,
|
@@ -398,8 +408,8 @@ def register():
|
|
398 |
"height": height,
|
399 |
"weight": weight,
|
400 |
"bmi": bmi,
|
401 |
-
"allergies":
|
402 |
-
"health_conditions":
|
403 |
"activity_level": activity_level,
|
404 |
"dietary_preferences": dietary_preferences,
|
405 |
"health_goals": health_goals
|
@@ -407,7 +417,7 @@ def register():
|
|
407 |
customer_collection.insert_one(user_data)
|
408 |
st.success(f"Registration successful! Your BMI is {bmi}. Please log in.")
|
409 |
return True
|
410 |
-
return False
|
411 |
def validate_password_strength(password):
|
412 |
if len(password) < 8:
|
413 |
return False
|
|
|
84 |
- Give Rating in large size text
|
85 |
- Based on the corrected food label and the user's profile, assign a health rating on a scale from 1 to 10 (where 10 is the healthiest).
|
86 |
- Consider the user's dietary preferences, health goals, allergies, and activity level in your rating.
|
87 |
+
- If the food contains any ingredients to which the user is allergic (e.g., peanuts for a nut allergy), assign a health rating of **0/10** and include a clear warning and also before doing this be double sure that the food has a substance to which the user is allergic .
|
88 |
+
- If the food does not have an allergen to which the user is allergic to and yet the user should avoid the food altogether, assign a rating from 1 to 4.
|
89 |
- If the user should consume the food in moderation, assign a rating from 5 to 7.
|
90 |
- If the user can consume the food frequently, assign a rating from 8 to 10.
|
91 |
|
92 |
2. Health Analysis:
|
93 |
+
-* Detailed Breakdown*: Present a statistical breakdown of the food's nutritional content (e.g., "The food contains 2% saturated fat, 12g sugar, and 10g protein"). Ensure all terms and values are correctly spelled and reflect the accurate content of the food item.
|
94 |
+
- *Personalized Evaluation*: Explain why the food item is either good or bad for the user based on their specific health profile. Double check if there actually is an item in food to which user is allergic to. Identify any ingredients or nutritional aspects that align well or poorly with the user's dietary needs (e.g., "This food is high in sugar, which may not align with your goal of maintaining stable blood sugar levels"). **If the food contains an allergen, make sure to emphasize that.ze the risk for the user.
|
95 |
+
- *Advice*: Provide guidance on whether the user should consume this food frequently, in moderation, or avoid it altogether, considering their health goals, dietary restrictions, and any allergens. **If the food contains an allergen, recommend avoiding it entirely and issue a warning in the conclusion.
|
96 |
|
97 |
+
if you mention any of the user's allergies or health conditions or health goals dont write them in list format if there is more than one. Just write them in a string.
|
98 |
Ensure that the output is free from spelling mistakes and important points or warnings are clearly communicated with bold keywords and underline relevant details.
|
99 |
"""
|
100 |
|
|
|
113 |
if user:
|
114 |
user_profile = {
|
115 |
"BMI": user.get("bmi", "Not provided"),
|
116 |
+
"Allergies": user.get("allergies", []), # Now a list
|
117 |
+
"Health Conditions": user.get("health_conditions", []), # Now a list
|
118 |
"Dietary Preferences": user.get("dietary_preferences", "None"),
|
119 |
"Activity Level": user.get("activity_level", "Moderate"),
|
120 |
+
"Health Goals": user.get("health_goals", ["General well-being"]) # Assuming this is already a list
|
121 |
}
|
122 |
|
123 |
llama_output = analyze_with_llama_index(corrected_text, user_profile)
|
|
|
165 |
1. Correct any spelling mistakes or grammatical errors in the OCR text.
|
166 |
2. Extract and structure the following information:
|
167 |
- Product Name
|
168 |
+
- Brand Name (look for company names following by "manufactured by" or "owned by" or "produced by")
|
169 |
- Weight in Grams/ML
|
170 |
- Nutritional information: Include the serving size (e.g., "per 100g", "per 200ml") as specified on the label. If multiple serving sizes are given, use the one that provides the most comprehensive nutritional breakdown.
|
171 |
- Ingredients
|
|
|
297 |
with st.container():
|
298 |
if register():
|
299 |
st.session_state.show_steps = False
|
300 |
+
#st.rerun()
|
301 |
if st.button("Close Registration Form"):
|
302 |
st.session_state.show_steps = False
|
303 |
st.rerun()
|
|
|
360 |
st.markdown('<h2 style="font-size: 2.5rem;">User Registration</h2>', unsafe_allow_html=True)
|
361 |
st.info("Password must be at least 8 characters long and contain at least one uppercase letter, one digit, and one special character.")
|
362 |
|
|
|
363 |
with st.form("registration_form"):
|
364 |
name = st.text_input("Name *", key="register_name")
|
365 |
email = st.text_input("Email *", key="register_email")
|
|
|
368 |
age = st.number_input("Age *", min_value=1, max_value=120, key="register_age")
|
369 |
height = st.number_input("Height (in cm) *", min_value=50, max_value=250, key="register_height")
|
370 |
weight = st.number_input("Weight (in kg) *", min_value=10, max_value=300, key="register_weight")
|
371 |
+
|
372 |
+
# Modified input for allergies
|
373 |
+
allergies = st.text_area("Allergies (if any, one per line)", key="register_allergies")
|
374 |
+
|
375 |
+
# Modified input for health conditions
|
376 |
+
health_conditions = st.text_area("Health Conditions (if any, one per line)", key="register_health_conditions")
|
377 |
+
|
378 |
activity_level = st.selectbox("Activity Level", ["Low", "Moderate", "High"], key="register_activity_level")
|
379 |
dietary_preferences = st.selectbox("Dietary Preferences", ["No preference","Vegetarian", "Vegan", "Gluten-Free", "Keto", "Paleo"], key="register_dietary_preferences")
|
380 |
health_goals = st.multiselect("Health Goals", ["Lose weight", "Gain muscle", "Maintain weight", "Improve stamina", "General well-being"], key="register_health_goals")
|
|
|
395 |
st.error("Password must be at least 8 characters long, contain one uppercase letter, one special character, and one digit.")
|
396 |
else:
|
397 |
bmi = calculate_bmi(weight, height)
|
398 |
+
|
399 |
+
# Process allergies and health conditions
|
400 |
+
allergies_list = [allergy.strip() for allergy in allergies.split('\n') if allergy.strip()]
|
401 |
+
health_conditions_list = [condition.strip() for condition in health_conditions.split('\n') if condition.strip()]
|
402 |
+
|
403 |
user_data = {
|
404 |
"name": name,
|
405 |
"email": email,
|
|
|
408 |
"height": height,
|
409 |
"weight": weight,
|
410 |
"bmi": bmi,
|
411 |
+
"allergies": allergies_list,
|
412 |
+
"health_conditions": health_conditions_list,
|
413 |
"activity_level": activity_level,
|
414 |
"dietary_preferences": dietary_preferences,
|
415 |
"health_goals": health_goals
|
|
|
417 |
customer_collection.insert_one(user_data)
|
418 |
st.success(f"Registration successful! Your BMI is {bmi}. Please log in.")
|
419 |
return True
|
420 |
+
return False
|
421 |
def validate_password_strength(password):
|
422 |
if len(password) < 8:
|
423 |
return False
|