shivanis14
commited on
Commit
•
0c811a0
1
Parent(s):
ee58f2b
Update app.py
Browse files
app.py
CHANGED
@@ -322,7 +322,7 @@ def analyze_claims(claims, ingredients, product_name, assistant_id):
|
|
322 |
|
323 |
return claims_analysis_str
|
324 |
|
325 |
-
def generate_final_analysis(brand_name, product_name, processing_level, harmful_ingredient_analysis, claims_analysis, system_prompt):
|
326 |
global debug_mode, client
|
327 |
system_prompt_orig = """You are provided with a detailed analysis of a food product. Your task is to generate actionable insights to help the user decide whether to consume the product, at what frequency, and identify any potential harms or benefits. Consider the context of consumption to ensure the advice is personalized and practical.
|
328 |
|
@@ -354,6 +354,9 @@ Additionally, consider the following while generating insights:
|
|
354 |
user_prompt = f"""
|
355 |
Product Name: {brand_name} {product_name}
|
356 |
|
|
|
|
|
|
|
357 |
Processing Level:
|
358 |
{processing_level}
|
359 |
|
@@ -390,13 +393,13 @@ def analyze_product(product_info_raw, system_prompt):
|
|
390 |
if len(ingredients_list) > 0:
|
391 |
product_type, calories, sugar, salt, serving_size = find_product_type(product_info_from_db)
|
392 |
nutrient_analysis = analyze_nutrients(product_type, calories, sugar, salt, serving_size)
|
393 |
-
print(f"nutrient analysis is {nutrient_analysis}")
|
394 |
processing_level = analyze_processing_level(ingredients_list, brand_name, product_name, assistant1.id) if ingredients_list else ""
|
395 |
harmful_ingredient_analysis = analyze_harmful_ingredients(ingredients_list, brand_name, product_name, assistant2.id) if ingredients_list else ""
|
396 |
if len(claims_list) > 0:
|
397 |
claims_analysis = analyze_claims(claims_list, ingredients_list, product_name, assistant3.id) if claims_list else ""
|
398 |
|
399 |
-
final_analysis = generate_final_analysis(brand_name,product_name,processing_level,harmful_ingredient_analysis,claims_analysis, system_prompt)
|
400 |
return final_analysis
|
401 |
else:
|
402 |
return "I'm sorry, product information could not be extracted from the url."
|
@@ -534,11 +537,12 @@ class ProductSelector:
|
|
534 |
st.session_state.messages.append({"role": "assistant", "content": msg})
|
535 |
|
536 |
# Loop through session state keys and delete all except the key_to_keep
|
537 |
-
keys_to_keep = ["system_prompt", "messages"]
|
538 |
keys_to_delete = [key for key in st.session_state.keys() if key not in keys_to_keep]
|
539 |
|
540 |
for key in keys_to_delete:
|
541 |
del st.session_state[key]
|
|
|
542 |
else:
|
543 |
st.session_state.awaiting_selection = False
|
544 |
st.session_state.messages.append(
|
@@ -644,11 +648,12 @@ def main():
|
|
644 |
if response == "Next Product":
|
645 |
SessionState.initialize() # Reset states for next product
|
646 |
#st.session_state.welcome_msg = "What is the next product you would like me to analyze today?"
|
647 |
-
keys_to_keep = ["system_prompt", "messages"]
|
648 |
keys_to_delete = [key for key in st.session_state.keys() if key not in keys_to_keep]
|
649 |
|
650 |
for key in keys_to_delete:
|
651 |
del st.session_state[key]
|
|
|
652 |
st.rerun()
|
653 |
|
654 |
elif response: # Only add response if it's not None
|
|
|
322 |
|
323 |
return claims_analysis_str
|
324 |
|
325 |
+
def generate_final_analysis(brand_name, product_name, nutrient_analysis, processing_level, harmful_ingredient_analysis, claims_analysis, system_prompt):
|
326 |
global debug_mode, client
|
327 |
system_prompt_orig = """You are provided with a detailed analysis of a food product. Your task is to generate actionable insights to help the user decide whether to consume the product, at what frequency, and identify any potential harms or benefits. Consider the context of consumption to ensure the advice is personalized and practical.
|
328 |
|
|
|
354 |
user_prompt = f"""
|
355 |
Product Name: {brand_name} {product_name}
|
356 |
|
357 |
+
Nutrition Analysis :
|
358 |
+
{nutrient_analysis}
|
359 |
+
|
360 |
Processing Level:
|
361 |
{processing_level}
|
362 |
|
|
|
393 |
if len(ingredients_list) > 0:
|
394 |
product_type, calories, sugar, salt, serving_size = find_product_type(product_info_from_db)
|
395 |
nutrient_analysis = analyze_nutrients(product_type, calories, sugar, salt, serving_size)
|
396 |
+
print(f"DEBUG ! nutrient analysis is {nutrient_analysis}")
|
397 |
processing_level = analyze_processing_level(ingredients_list, brand_name, product_name, assistant1.id) if ingredients_list else ""
|
398 |
harmful_ingredient_analysis = analyze_harmful_ingredients(ingredients_list, brand_name, product_name, assistant2.id) if ingredients_list else ""
|
399 |
if len(claims_list) > 0:
|
400 |
claims_analysis = analyze_claims(claims_list, ingredients_list, product_name, assistant3.id) if claims_list else ""
|
401 |
|
402 |
+
final_analysis = generate_final_analysis(brand_name, product_name, nutrient_analysis, processing_level, harmful_ingredient_analysis, claims_analysis, system_prompt)
|
403 |
return final_analysis
|
404 |
else:
|
405 |
return "I'm sorry, product information could not be extracted from the url."
|
|
|
537 |
st.session_state.messages.append({"role": "assistant", "content": msg})
|
538 |
|
539 |
# Loop through session state keys and delete all except the key_to_keep
|
540 |
+
keys_to_keep = ["system_prompt", "messages", "welcome_msg"]
|
541 |
keys_to_delete = [key for key in st.session_state.keys() if key not in keys_to_keep]
|
542 |
|
543 |
for key in keys_to_delete:
|
544 |
del st.session_state[key]
|
545 |
+
st.session_state.welcome_msg = "What product would you like me to analyze next?"
|
546 |
else:
|
547 |
st.session_state.awaiting_selection = False
|
548 |
st.session_state.messages.append(
|
|
|
648 |
if response == "Next Product":
|
649 |
SessionState.initialize() # Reset states for next product
|
650 |
#st.session_state.welcome_msg = "What is the next product you would like me to analyze today?"
|
651 |
+
keys_to_keep = ["system_prompt", "messages", "welcome_msg"]
|
652 |
keys_to_delete = [key for key in st.session_state.keys() if key not in keys_to_keep]
|
653 |
|
654 |
for key in keys_to_delete:
|
655 |
del st.session_state[key]
|
656 |
+
st.session_state.welcome_msg = "What product would you like me to analyze next?"
|
657 |
st.rerun()
|
658 |
|
659 |
elif response: # Only add response if it's not None
|