diff --git a/instructions/lumi_instructions.md b/instructions/lumi_instructions.md index 8e8ee95..b284cc6 100644 --- a/instructions/lumi_instructions.md +++ b/instructions/lumi_instructions.md @@ -21,14 +21,14 @@ You are Lumi, an intelligent product nutrient analyzer. Your role is to categori - **positive_nutrient**: - List containing dictionaries, each representing a positive nutrient with the following keys: - `name`: Nutrient name - - `icon`: Icon name + - `icon`: Icon name (No emoji) - `quantity`: Nutrient quantity (e.g., "10.00 g") - `text`: Humorous analysis of the quantity (max 6 words) - `color`: Color indication based on quantity and nutrient type (#8AC449 for positive nutrients, #F8A72C for close to threshold, #DF5656 for negative nutrients) - **negative_nutrient**: - List containing dictionaries, each representing a negative nutrient with the following keys: - `name`: Nutrient name - - `icon`: Icon name + - `icon`: Icon name (No emoji) - `quantity`: Nutrient quantity (e.g., "10.00 g") - `text`: Humorous analysis of the quantity (max 6 words) - `color`: Color indication based on quantity and nutrient type (#8AC449 for positive nutrients, #F8A72C for close to threshold, #DF5656 for negative nutrients) diff --git a/metadata/food_categories.json b/metadata/food_categories.json index b17dc35..63bed3e 100644 --- a/metadata/food_categories.json +++ b/metadata/food_categories.json @@ -25,9 +25,10 @@ "Butter": ["Cocoa Butter"], "Calcium": ["Calcium Carbonate", "Calcium Pantothenate"], "Caffeine": ["Contains Caffeine", "Instant Coffee Chicory Mixture"], - "Carbohydrate": ["Carbohydrates"], + "Carbohydrates": ["Carbohydrate"], "Cocoa": ["Cocoa Mass", "Cocoa Solids", "Low-Fat Cocoa"], - "Corn": ["Corn Grits", "Corn Meal", "Corn Starch"], + "Chocolate": ["Milk Chocolate", "Chocolate Chips"], + "Corn": ["Corn Grits", "Corn Meal", "Corn Starch", "Corn Syrup"], "Cream": ["Choco Crème"], "Dal": ["Urad Dal"], "Emulsifiers": ["Emulsifier", "Emulsifier Of Vegetable"], @@ -78,7 +79,7 @@ "Spices": ["Mixed Spices"], "Sodium": ["Sodium Bicarbonate", "Sodium Carbonate"], "Stabilizers": ["Stabilizer"], - "Sugar": ["Added Sugar", "Added Sugars", "Sugars"], + "Sugars": ["Added Sugar", "Added Sugars", "Sugar"], "Sunflower-Oil": ["Refined Sunflower Oil"], "Syrup": [ "Glucose-Fructose Syrup", diff --git a/server/gemini.py b/server/gemini.py index dbcde3d..71685b6 100644 --- a/server/gemini.py +++ b/server/gemini.py @@ -14,7 +14,12 @@ # Blueprint for the ai routes ai_blueprint = Blueprint('ai', __name__) -genai.configure(api_key=GEMINI_API_KEY) # Load Gemini API key from .env +# Load the Gemini API key from the environment variables +if GEMINI_API_KEY: + print('GEMINI_API_KEY is set.') +else: + print('GEMINI_API_KEY is not set.') +genai.configure(api_key=GEMINI_API_KEY) # Generation settings to control the model's output generation_config = { @@ -107,7 +112,7 @@ def swapr(email: str, product_data: dict) -> Response: ) if database_response.status_code != 200: - runtime_error('swapr', 'Database search failed.', middleware=database_response.json(), email=email) + # runtime_error('swapr', 'Database search failed.', middleware=database_response.json(), email=email) # return jsonify({'error': 'Database search failed.'}), database_response.status_code return {'product_name': filtered_response.strip()} @@ -159,7 +164,6 @@ def savora() -> Response: # Delete the temporary file after processing os.remove(temp_path) - else: return jsonify({'error': 'Invalid message type.'}), 400 diff --git a/server/search.py b/server/search.py index f0223a7..b4ec31d 100644 --- a/server/search.py +++ b/server/search.py @@ -13,7 +13,7 @@ # Blueprint for the search routes search_blueprint = Blueprint('search', __name__) -api = openfoodfacts.API(user_agent='Mivro/1.5') # Initialize the Open Food Facts API client +api = openfoodfacts.API(user_agent='Mivro/1.0') # Initialize the Open Food Facts API client @search_blueprint.route('/barcode', methods=['POST']) def barcode() -> Response: @@ -63,16 +63,20 @@ def barcode() -> Response: 'ingredients': filter_ingredient(filtered_product_data.get('ingredients', [])), 'nova_group_name': nova_name(filtered_product_data.get('nova_group', '')), 'nutriments': lumi(filtered_product_data.get('nutriments', {})), - 'total_nutriments': len(filtered_product_data.get('nutriments', {}).get('positive_nutrient', [])) + - len(filtered_product_data.get('nutriments', {}).get('negative_nutrient', [])), 'nutriscore_grade_color': grade_color(filtered_product_data.get('nutriscore_grade', '')), 'nutriscore_assessment': score_assessment(filtered_product_data.get('nutriscore_score', None)).title(), 'health_risk': lumi(filtered_product_data.get('ingredients', [])), - 'total_health_risks': len(filtered_product_data.get('health_risk', {}).get('ingredient_warnings', [])), 'selected_images': filter_image(filtered_product_data.get('selected_images', [])), 'recommeded_product': swapr(email, filtered_product_data) }) + # Calculating derived fields outside as they're not directly provided by the API + filtered_product_data['total_nutriments'] = ( + len(filtered_product_data.get('nutriments', {}).get('positive_nutrient', [])) + + len(filtered_product_data.get('nutriments', {}).get('negative_nutrient', [])) + ) + filtered_product_data['total_health_risks'] = len(filtered_product_data.get('health_risk', {}).get('ingredient_warnings', [])) + # Store the scan history for the product barcode in Firestore database_history(email, product_barcode, filtered_product_data) return jsonify(filtered_product_data)