| |
|
|
| |
| |
| from transformers import pipeline |
| import os |
| import openai |
| import requests |
| import json |
| from openai import OpenAI |
| openai.organization = "org-5Z0c3Uk1VG7t3TsczN6M4FCi" |
| |
| openai.api_key_path ="./key.txt" |
|
|
| def askGPT(prompt="what can I make with potato?"): |
|
|
| client = OpenAI( |
| base_url='http://localhost:11434/v1/', |
|
|
| |
| api_key='ollama', |
| ) |
|
|
| chat_completion = client.chat.completions.create( |
| messages=[ |
| { |
| 'role': 'user', |
| 'content': prompt, |
| } |
| ], |
| model='llama3', |
| ) |
|
|
| result = chat_completion.choices[0].message.content |
| |
| return result |
|
|
| '''def askGPT(prompt="what can I make with potato?"): |
| response = openai.ChatCompletion.create( |
| model="gpt-3.5-turbo", |
| messages=[ |
| { |
| "role": "system", |
| "content":prompt |
| }, |
| { |
| "role": "user", |
| "content": "" |
| } ], |
| temperature=1, |
| max_tokens=256, |
| top_p=1, |
| frequency_penalty=0, |
| presence_penalty=0 |
| ) |
| result = response["choices"][0]["message"]["content"] |
| return result''' |
|
|
| def classifyImage(image): |
| pipe = pipeline("image-classification", model="microsoft/resnet-50") |
| result = pipe(image) |
| return result[0]['label'] |
|
|
| def analyze_nutrition(ingredients): |
| |
| endpoint = "https://api.edamam.com/api/nutrition-data" |
| |
| app_id = "26722303" |
| app_key = "44f19a04e17d83e91706e4047804e690" |
| processed_ingredients = set() |
| food_dict= {} |
|
|
| for ingredient in ingredients: |
| if ingredient in processed_ingredients: |
| continue |
| |
| params = { |
| "app_id": app_id, |
| "app_key": app_key, |
| "ingr": ingredient |
| } |
| try: |
| |
| response = requests.get(endpoint, params=params) |
|
|
| |
| if response.status_code == 200: |
| |
| data = response.json() |
|
|
| food_dict[ingredient] = { |
| 'Calories': str(data['calories']) + "kcal", |
| 'Calories from Protein': str(data['totalNutrientsKCal']['PROCNT_KCAL']['quantity']) + "kcal", |
| 'Calories from Fat': str(data['totalNutrientsKCal']['FAT_KCAL']['quantity']) + "kcal", |
| 'Calories from Carbohydrates': str(data['totalNutrientsKCal']['CHOCDF_KCAL']['quantity']) + "kcal", |
| 'Grams in Protein': str(data['totalNutrients']['PROCNT']['quantity']) + "g", |
| 'Grams in Carbohydrates': str(data['totalNutrients']['CHOCDF']['quantity']) +"g" |
| } |
|
|
| processed_ingredients.add(ingredient) |
| else: |
| print("Error for", ingredient, ":", response.status_code) |
|
|
| except requests.exceptions.RequestException as e: |
| print("Error for", ingredient, ":", e) |
| return food_dict |
|
|
|
|
| |
| |
|
|
| |
| |
|
|