Skip to content

Commit

Permalink
🛠️ [v1.0.2] Minor Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
areebahmeddd committed Oct 8, 2024
1 parent 28bd2cb commit 192f07e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions instructions/lumi_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions metadata/food_categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions server/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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()}

Expand Down Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions server/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 192f07e

Please sign in to comment.