Spaces:
Running
Running
Prathamesh Sable
commited on
Commit
·
0f54ea3
1
Parent(s):
534624d
moved environment variables to common file
Browse files- db/database.py +1 -9
- env.py +77 -0
- main.py +2 -5
- routers/analysis.py +1 -4
- routers/product.py +2 -8
- services/ingredientFinderAgent.py +4 -10
- services/productAnalyzerAgent.py +4 -8
- utils/agent_tools.py +2 -14
- utils/external_api_utils.py +1 -5
- utils/ingredient_utils.py +1 -4
- utils/vuforia_utils.py +1 -7
db/database.py
CHANGED
|
@@ -2,16 +2,8 @@ import os
|
|
| 2 |
from sqlalchemy import create_engine
|
| 3 |
from sqlalchemy.ext.declarative import declarative_base
|
| 4 |
from sqlalchemy.orm import sessionmaker
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
|
| 7 |
-
|
| 8 |
-
load_dotenv()
|
| 9 |
-
|
| 10 |
-
# Get database URL from environment variable
|
| 11 |
-
DATABASE_URL = os.getenv(
|
| 12 |
-
"DATABASE_URL",
|
| 13 |
-
"postgresql://postgres:password@localhost:5432/food_ingredients"
|
| 14 |
-
)
|
| 15 |
|
| 16 |
# Create engine
|
| 17 |
engine = create_engine(DATABASE_URL)
|
|
|
|
| 2 |
from sqlalchemy import create_engine
|
| 3 |
from sqlalchemy.ext.declarative import declarative_base
|
| 4 |
from sqlalchemy.orm import sessionmaker
|
|
|
|
| 5 |
|
| 6 |
+
from env import DATABASE_URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Create engine
|
| 9 |
engine = create_engine(DATABASE_URL)
|
env.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
|
| 4 |
+
# Load environment variables from .env file
|
| 5 |
+
load_dotenv()
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Environment variables for FoodAnalyzer-API
|
| 9 |
+
PORT = int(os.getenv("PORT", 8000))
|
| 10 |
+
|
| 11 |
+
# JWT Secret Key
|
| 12 |
+
SECRET_KEY = os.getenv("SECRET_KEY", "09d8f7a6b5c4e3d2f1a0b9c8d7e6f5a4")
|
| 13 |
+
ALGORITHM = os.getenv("ALGORITHM", "HS256")
|
| 14 |
+
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 30))
|
| 15 |
+
|
| 16 |
+
# Hugging Face Transformers API key not required
|
| 17 |
+
# HUGGING_FACE_API_KEY = os.getenv("HUGGING_FACE_API_KEY", None)
|
| 18 |
+
# OpenAI API key not required
|
| 19 |
+
# OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", None)
|
| 20 |
+
|
| 21 |
+
# API keys and model names for different LLMs here
|
| 22 |
+
# for google ai studio
|
| 23 |
+
LLM_API_KEY = os.getenv("LLM_API_KEY", None)
|
| 24 |
+
LLM_MODEL_NAME = os.getenv("LLM_MODEL_NAME", "gemini-2.0-flash")
|
| 25 |
+
|
| 26 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", None)
|
| 27 |
+
GOOGLE_CSE_ID = os.getenv("GOOGLE_CSE_ID", None)
|
| 28 |
+
|
| 29 |
+
USDA_API_KEY = os.getenv("USDA_API_KEY", "DEMO_KEY")
|
| 30 |
+
|
| 31 |
+
# pg db url
|
| 32 |
+
DATABASE_URL = os.getenv("DATABASE_URL", None)
|
| 33 |
+
|
| 34 |
+
# Vuforia keys
|
| 35 |
+
VUFORIA_SERVER_ACCESS_KEY = os.getenv("VUFORIA_SERVER_ACCESS_KEY", None)
|
| 36 |
+
VUFORIA_SERVER_SECRET_KEY = os.getenv("VUFORIA_SERVER_SECRET_KEY", None)
|
| 37 |
+
VUFORIA_TARGET_DATABASE_NAME = os.getenv("VUFORIA_TARGET_DATABASE_NAME", "FoodAnalyzer_BE_PROJ")
|
| 38 |
+
VUFORIA_TARGET_DATABASE_ID = os.getenv("VUFORIA_TARGET_DATABASE_ID", "FoodAnalyzer_BE_PROJ")
|
| 39 |
+
|
| 40 |
+
# langsmith keys optional
|
| 41 |
+
LANGSMITH_TRACING = os.getenv("LANGSMITH_TRACING", True)
|
| 42 |
+
LANGSMITH_ENDPOINT = os.getenv("LANGSMITH_ENDPOINT", "https://api.smith.langchain.com")
|
| 43 |
+
LANGSMITH_API_KEY = os.getenv("LANGSMITH_API_KEY", None)
|
| 44 |
+
LANGSMITH_PROJECT = os.getenv("LANGSMITH_PROJECT", None)
|
| 45 |
+
|
| 46 |
+
# app settings
|
| 47 |
+
PARALLEL_RATE_LIMIT = int(os.getenv("PARALLEL_RATE_LIMIT", 10))
|
| 48 |
+
|
| 49 |
+
# Rate limiting configuration in seconds
|
| 50 |
+
PUBCHEM_TIMEOUT = int(os.getenv("PUBCHEM_TIMEOUT", 2))
|
| 51 |
+
PUBCHEM_MAX_RETRIES = int(os.getenv("PUBCHEM_MAX_RETRIES", 2))
|
| 52 |
+
|
| 53 |
+
# Delay in seconds
|
| 54 |
+
DUCKDUCKGO_RATE_LIMIT_DELAY = int(os.getenv("DUCKDUCKGO_RATE_LIMIT_DELAY", 2))
|
| 55 |
+
DUCKDUCKGO_MAX_RETRIES = int(os.getenv("DUCKDUCKGO_MAX_RETRIES", 2))
|
| 56 |
+
|
| 57 |
+
# fake response for testing
|
| 58 |
+
SEND_FAKE_TARGET = os.getenv("SEND_FAKE_TARGET", False) == "true"
|
| 59 |
+
FAKE_TARGET_IMAGE_NAME = os.getenv("FAKE_TARGET_IMAGE_NAME", "detected_Snack_0.13_db8318a668504073ad5fd0677187d305.jpg")
|
| 60 |
+
|
| 61 |
+
# Define Required Environment Variables and show error if not set
|
| 62 |
+
required_env_vars = {
|
| 63 |
+
"LLM_API_KEY":LLM_API_KEY,
|
| 64 |
+
"GOOGLE_API_KEY":GOOGLE_API_KEY,
|
| 65 |
+
"GOOGLE_CSE_ID":GOOGLE_CSE_ID,
|
| 66 |
+
"USDA_API_KEY":USDA_API_KEY,
|
| 67 |
+
"DATABASE_URL":DATABASE_URL,
|
| 68 |
+
"VUFORIA_SERVER_ACCESS_KEY":VUFORIA_SERVER_ACCESS_KEY,
|
| 69 |
+
"VUFORIA_SERVER_SECRET_KEY":VUFORIA_SERVER_SECRET_KEY,
|
| 70 |
+
"VUFORIA_TARGET_DATABASE_NAME":VUFORIA_TARGET_DATABASE_NAME,
|
| 71 |
+
"VUFORIA_TARGET_DATABASE_ID":VUFORIA_TARGET_DATABASE_ID,
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
# Check if all required environment variables are set
|
| 75 |
+
for var in required_env_vars.keys():
|
| 76 |
+
if required_env_vars[var] is None:
|
| 77 |
+
raise ValueError(f"Environment variable {var} is not set. Please set it in the .env file.")
|
main.py
CHANGED
|
@@ -6,16 +6,13 @@ from routers.auth import router as auth_router
|
|
| 6 |
from routers.analysis import router as analysis_router
|
| 7 |
from routers.history import router as history_router
|
| 8 |
from routers.product import router as product_router
|
| 9 |
-
from dotenv import load_dotenv
|
| 10 |
import os
|
| 11 |
import uvicorn
|
| 12 |
from pathlib import Path
|
| 13 |
import tensorflow as tf
|
| 14 |
import tensorflow_hub as hub
|
|
|
|
| 15 |
|
| 16 |
-
load_dotenv()
|
| 17 |
-
# Load environment variables from .env file
|
| 18 |
-
PORT = os.getenv("PORT", 8000)
|
| 19 |
|
| 20 |
# Define the templates directory
|
| 21 |
templates = Jinja2Templates(directory="templates")
|
|
@@ -47,7 +44,7 @@ async def log_requests(request: Request, call_next):
|
|
| 47 |
request._body = body_content
|
| 48 |
response = await call_next(request)
|
| 49 |
print(f"Request: {request.method} {request.url}")
|
| 50 |
-
print(f"Data: {body_content}")
|
| 51 |
print(f"Headers: {request.headers}")
|
| 52 |
return response
|
| 53 |
|
|
|
|
| 6 |
from routers.analysis import router as analysis_router
|
| 7 |
from routers.history import router as history_router
|
| 8 |
from routers.product import router as product_router
|
|
|
|
| 9 |
import os
|
| 10 |
import uvicorn
|
| 11 |
from pathlib import Path
|
| 12 |
import tensorflow as tf
|
| 13 |
import tensorflow_hub as hub
|
| 14 |
+
from env import PORT
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Define the templates directory
|
| 18 |
templates = Jinja2Templates(directory="templates")
|
|
|
|
| 44 |
request._body = body_content
|
| 45 |
response = await call_next(request)
|
| 46 |
print(f"Request: {request.method} {request.url}")
|
| 47 |
+
print(f"Data: {body_content}"[:100])
|
| 48 |
print(f"Headers: {request.headers}")
|
| 49 |
return response
|
| 50 |
|
routers/analysis.py
CHANGED
|
@@ -13,7 +13,6 @@ from interfaces.productModels import ProductIngredientsRequest
|
|
| 13 |
from logger_manager import log_info, log_error
|
| 14 |
from db.database import get_db,SessionLocal
|
| 15 |
from db.repositories import IngredientRepository
|
| 16 |
-
from dotenv import load_dotenv
|
| 17 |
from langsmith import traceable
|
| 18 |
from services.auth_service import get_current_user
|
| 19 |
from services.ingredientFinderAgent import IngredientInfoAgentLangGraph
|
|
@@ -22,10 +21,8 @@ from utils.db_utils import ingredient_db_to_pydantic
|
|
| 22 |
from utils.ingredient_utils import process_single_ingredient
|
| 23 |
|
| 24 |
# Load environment variables
|
| 25 |
-
|
| 26 |
|
| 27 |
-
# Get rate limit from environment variable or use default
|
| 28 |
-
PARALLEL_RATE_LIMIT = int(os.getenv("PARALLEL_RATE_LIMIT", 10))
|
| 29 |
log_info(f"Using parallel rate limit of {PARALLEL_RATE_LIMIT}")
|
| 30 |
|
| 31 |
# Create a semaphore to limit concurrent API calls
|
|
|
|
| 13 |
from logger_manager import log_info, log_error
|
| 14 |
from db.database import get_db,SessionLocal
|
| 15 |
from db.repositories import IngredientRepository
|
|
|
|
| 16 |
from langsmith import traceable
|
| 17 |
from services.auth_service import get_current_user
|
| 18 |
from services.ingredientFinderAgent import IngredientInfoAgentLangGraph
|
|
|
|
| 21 |
from utils.ingredient_utils import process_single_ingredient
|
| 22 |
|
| 23 |
# Load environment variables
|
| 24 |
+
from env import PARALLEL_RATE_LIMIT
|
| 25 |
|
|
|
|
|
|
|
| 26 |
log_info(f"Using parallel rate limit of {PARALLEL_RATE_LIMIT}")
|
| 27 |
|
| 28 |
# Create a semaphore to limit concurrent API calls
|
routers/product.py
CHANGED
|
@@ -20,7 +20,6 @@ from db.database import get_db
|
|
| 20 |
from fastapi import Depends
|
| 21 |
from db.repositories import ProductRepository, IngredientRepository
|
| 22 |
|
| 23 |
-
from dotenv import load_dotenv
|
| 24 |
|
| 25 |
|
| 26 |
from services.ingredients import IngredientService
|
|
@@ -30,13 +29,8 @@ from utils.vuforia_utils import add_target_to_vuforia, UPLOADED_IMAGES_DIR
|
|
| 30 |
from utils.fetch_data import fetch_product_data_from_api
|
| 31 |
import uuid
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
VUFORIA_SERVER_ACCESS_KEY = os.getenv("VUFORIA_SERVER_ACCESS_KEY")
|
| 37 |
-
VUFORIA_SERVER_SECRET_KEY = os.getenv("VUFORIA_SERVER_SECRET_KEY")
|
| 38 |
-
VUFORIA_TARGET_DATABASE_NAME = os.getenv("VUFORIA_TARGET_DATABASE_NAME")
|
| 39 |
-
VUFORIA_TARGET_DATABASE_ID = os.getenv("VUFORIA_TARGET_DATABASE_ID")
|
| 40 |
|
| 41 |
router = APIRouter()
|
| 42 |
|
|
|
|
| 20 |
from fastapi import Depends
|
| 21 |
from db.repositories import ProductRepository, IngredientRepository
|
| 22 |
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
from services.ingredients import IngredientService
|
|
|
|
| 29 |
from utils.fetch_data import fetch_product_data_from_api
|
| 30 |
import uuid
|
| 31 |
|
| 32 |
+
# import environment variables
|
| 33 |
+
from env import VUFORIA_SERVER_ACCESS_KEY,VUFORIA_SERVER_SECRET_KEY,VUFORIA_TARGET_DATABASE_NAME,VUFORIA_TARGET_DATABASE_ID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
router = APIRouter()
|
| 36 |
|
services/ingredientFinderAgent.py
CHANGED
|
@@ -3,7 +3,6 @@ from functools import partial
|
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
import traceback
|
| 6 |
-
from dotenv import load_dotenv
|
| 7 |
from typing import Dict, Any
|
| 8 |
|
| 9 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
@@ -14,9 +13,7 @@ from logger_manager import log_debug, log_error, log_info, log_warning
|
|
| 14 |
from utils.agent_tools import search_local_db,search_web,search_wikipedia,search_open_food_facts,search_usda,search_pubchem
|
| 15 |
|
| 16 |
# Load environment variables from .env file
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
def create_summary_from_source(source: Dict[str, Any]) -> str:
|
| 22 |
"""Create a meaningful summary from source data."""
|
|
@@ -94,12 +91,9 @@ def analyze_ingredient(state: IngredientState) -> IngredientState:
|
|
| 94 |
Returns:
|
| 95 |
Updated state with analysis results
|
| 96 |
"""
|
| 97 |
-
# Get API key and model from environment
|
| 98 |
-
api_key = os.getenv("GOOGLE_API_KEY")
|
| 99 |
-
model_name = os.getenv("LLM_MODEL_NAME", "gemini-1.5-pro")
|
| 100 |
|
| 101 |
# Basic validation
|
| 102 |
-
if not
|
| 103 |
log_error("No Google API key found in environment variables")
|
| 104 |
new_state = state.copy()
|
| 105 |
new_state["result"] = {
|
|
@@ -114,8 +108,8 @@ def analyze_ingredient(state: IngredientState) -> IngredientState:
|
|
| 114 |
# Initialize LLM
|
| 115 |
try:
|
| 116 |
llm = ChatGoogleGenerativeAI(
|
| 117 |
-
|
| 118 |
-
model=
|
| 119 |
temperature=0.3, # Lower temperature for more factual responses
|
| 120 |
# convert_system_message_to_human=True
|
| 121 |
)
|
|
|
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
import traceback
|
|
|
|
| 6 |
from typing import Dict, Any
|
| 7 |
|
| 8 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
|
|
| 13 |
from utils.agent_tools import search_local_db,search_web,search_wikipedia,search_open_food_facts,search_usda,search_pubchem
|
| 14 |
|
| 15 |
# Load environment variables from .env file
|
| 16 |
+
from env import GOOGLE_API_KEY, LLM_MODEL_NAME
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def create_summary_from_source(source: Dict[str, Any]) -> str:
|
| 19 |
"""Create a meaningful summary from source data."""
|
|
|
|
| 91 |
Returns:
|
| 92 |
Updated state with analysis results
|
| 93 |
"""
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# Basic validation
|
| 96 |
+
if not GOOGLE_API_KEY:
|
| 97 |
log_error("No Google API key found in environment variables")
|
| 98 |
new_state = state.copy()
|
| 99 |
new_state["result"] = {
|
|
|
|
| 108 |
# Initialize LLM
|
| 109 |
try:
|
| 110 |
llm = ChatGoogleGenerativeAI(
|
| 111 |
+
google_GOOGLE_API_KEY=GOOGLE_API_KEY,
|
| 112 |
+
model=LLM_MODEL_NAME,
|
| 113 |
temperature=0.3, # Lower temperature for more factual responses
|
| 114 |
# convert_system_message_to_human=True
|
| 115 |
)
|
services/productAnalyzerAgent.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
import os
|
| 2 |
from typing import List, Dict, Any, Optional
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
from langchain_core.messages import HumanMessage
|
| 5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
from logger_manager import log_error, log_info
|
| 7 |
from interfaces.ingredientModels import IngredientAnalysisResult
|
| 8 |
|
| 9 |
# Load environment variables
|
| 10 |
-
|
| 11 |
|
| 12 |
async def analyze_product_ingredients(
|
| 13 |
ingredients_data: List[IngredientAnalysisResult],
|
|
@@ -19,13 +18,10 @@ async def analyze_product_ingredients(
|
|
| 19 |
"""
|
| 20 |
log_info(f"Analyzing product with {len(ingredients_data)} ingredients")
|
| 21 |
|
| 22 |
-
# Initialize LLM
|
| 23 |
-
api_key = os.getenv("LLM_API_KEY")
|
| 24 |
-
model_name = os.getenv("LLM_MODEL_NAME", "gemini-2.0-flash")
|
| 25 |
-
|
| 26 |
llm = ChatGoogleGenerativeAI(
|
| 27 |
-
|
| 28 |
-
model=
|
| 29 |
temperature=0.2 # Lower temperature for more factual responses
|
| 30 |
)
|
| 31 |
|
|
|
|
| 1 |
import os
|
| 2 |
from typing import List, Dict, Any, Optional
|
|
|
|
| 3 |
from langchain_core.messages import HumanMessage
|
| 4 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 5 |
from logger_manager import log_error, log_info
|
| 6 |
from interfaces.ingredientModels import IngredientAnalysisResult
|
| 7 |
|
| 8 |
# Load environment variables
|
| 9 |
+
from env import LLM_API_KEY, LLM_MODEL_NAME
|
| 10 |
|
| 11 |
async def analyze_product_ingredients(
|
| 12 |
ingredients_data: List[IngredientAnalysisResult],
|
|
|
|
| 18 |
"""
|
| 19 |
log_info(f"Analyzing product with {len(ingredients_data)} ingredients")
|
| 20 |
|
| 21 |
+
# Initialize LLM
|
|
|
|
|
|
|
|
|
|
| 22 |
llm = ChatGoogleGenerativeAI(
|
| 23 |
+
google_LLM_API_KEY=LLM_API_KEY,
|
| 24 |
+
model=LLM_MODEL_NAME,
|
| 25 |
temperature=0.2 # Lower temperature for more factual responses
|
| 26 |
)
|
| 27 |
|
utils/agent_tools.py
CHANGED
|
@@ -2,12 +2,10 @@ import asyncio
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
import pandas as pd
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
|
| 7 |
from typing import Dict, Any
|
| 8 |
# modular
|
| 9 |
from logger_manager import log_error, log_info, log_warning
|
| 10 |
-
from dotenv import load_dotenv
|
| 11 |
|
| 12 |
import aiohttp
|
| 13 |
import time
|
|
@@ -20,7 +18,7 @@ from langchain_core.tools import tool
|
|
| 20 |
|
| 21 |
|
| 22 |
# Load environment variables from .env file
|
| 23 |
-
|
| 24 |
|
| 25 |
# Load Scraped Database
|
| 26 |
SCRAPED_DB_PATH = "data/Food_Aditives_E_numbers.csv" # Ensure this file exists
|
|
@@ -32,15 +30,6 @@ else:
|
|
| 32 |
log_warning("Scraped database not found!")
|
| 33 |
|
| 34 |
|
| 35 |
-
# Define a rate limit (adjust as needed)
|
| 36 |
-
PUBCHEM_TIMEOUT = float(os.getenv("PUBCHEM_TIMEOUT", "2.0")) # seconds
|
| 37 |
-
PUBCHEM_MAX_RETRIES = int(os.getenv("PUBCHEM_MAX_RETRIES", "3")) # Max retries
|
| 38 |
-
|
| 39 |
-
# Rate limiting configuration
|
| 40 |
-
DUCKDUCKGO_RATE_LIMIT_DELAY = float(os.getenv("DUCKDUCKGO_RATE_LIMIT_DELAY", "2.0")) # Delay in seconds
|
| 41 |
-
DUCKDUCKGO_MAX_RETRIES = int(os.getenv("DUCKDUCKGO_MAX_RETRIES", "3")) # Max retries
|
| 42 |
-
|
| 43 |
-
|
| 44 |
# Define tool functions
|
| 45 |
@tool("search_local_db")
|
| 46 |
def search_local_db(ingredient: str) -> Dict[str, Any]:
|
|
@@ -98,12 +87,11 @@ def search_usda(ingredient: str) -> Dict[str, Any]:
|
|
| 98 |
|
| 99 |
try:
|
| 100 |
usda_api = "https://api.nal.usda.gov/fdc/v1"
|
| 101 |
-
usda_api_key = os.getenv("USDA_API_KEY", "DEMO_KEY") # Use DEMO_KEY if not provided
|
| 102 |
|
| 103 |
# Search for the ingredient
|
| 104 |
search_url = f"{usda_api}/foods/search"
|
| 105 |
params = {
|
| 106 |
-
"api_key":
|
| 107 |
"query": ingredient,
|
| 108 |
"dataType": ["Foundation", "SR Legacy", "Branded"],
|
| 109 |
"pageSize": 5
|
|
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
|
| 6 |
from typing import Dict, Any
|
| 7 |
# modular
|
| 8 |
from logger_manager import log_error, log_info, log_warning
|
|
|
|
| 9 |
|
| 10 |
import aiohttp
|
| 11 |
import time
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
# Load environment variables from .env file
|
| 21 |
+
from env import PUBCHEM_MAX_RETRIES, PUBCHEM_TIMEOUT,DUCKDUCKGO_MAX_RETRIES,DUCKDUCKGO_RATE_LIMIT_DELAY,USDA_API_KEY
|
| 22 |
|
| 23 |
# Load Scraped Database
|
| 24 |
SCRAPED_DB_PATH = "data/Food_Aditives_E_numbers.csv" # Ensure this file exists
|
|
|
|
| 30 |
log_warning("Scraped database not found!")
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Define tool functions
|
| 34 |
@tool("search_local_db")
|
| 35 |
def search_local_db(ingredient: str) -> Dict[str, Any]:
|
|
|
|
| 87 |
|
| 88 |
try:
|
| 89 |
usda_api = "https://api.nal.usda.gov/fdc/v1"
|
|
|
|
| 90 |
|
| 91 |
# Search for the ingredient
|
| 92 |
search_url = f"{usda_api}/foods/search"
|
| 93 |
params = {
|
| 94 |
+
"api_key": USDA_API_KEY,
|
| 95 |
"query": ingredient,
|
| 96 |
"dataType": ["Foundation", "SR Legacy", "Branded"],
|
| 97 |
"pageSize": 5
|
utils/external_api_utils.py
CHANGED
|
@@ -2,12 +2,8 @@ import requests
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
from logger_manager import log_info, log_error
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
VUFORIA_SERVER_ACCESS_KEY = os.getenv("VUFORIA_SERVER_ACCESS_KEY")
|
| 10 |
-
VUFORIA_SERVER_SECRET_KEY = os.getenv("VUFORIA_SERVER_SECRET_KEY")
|
| 11 |
|
| 12 |
def get_vuforia_auth_headers():
|
| 13 |
"""
|
|
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
from logger_manager import log_info, log_error
|
|
|
|
| 5 |
|
| 6 |
+
from env import VUFORIA_SERVER_ACCESS_KEY, VUFORIA_SERVER_SECRET_KEY
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def get_vuforia_auth_headers():
|
| 9 |
"""
|
utils/ingredient_utils.py
CHANGED
|
@@ -6,17 +6,14 @@ from db.repositories import IngredientRepository
|
|
| 6 |
from interfaces.ingredientModels import IngredientAnalysisResult
|
| 7 |
from logger_manager import log_error, log_info
|
| 8 |
from services.ingredientFinderAgent import IngredientInfoAgentLangGraph
|
| 9 |
-
from dotenv import load_dotenv
|
| 10 |
from langsmith import traceable
|
| 11 |
import pytz
|
| 12 |
|
| 13 |
from utils.db_utils import ingredient_db_to_pydantic
|
| 14 |
|
| 15 |
# Load environment variables
|
| 16 |
-
|
| 17 |
|
| 18 |
-
# Get rate limit from environment variable or use default
|
| 19 |
-
PARALLEL_RATE_LIMIT = int(os.getenv("PARALLEL_RATE_LIMIT", 10))
|
| 20 |
|
| 21 |
# Create a semaphore to limit concurrent API calls
|
| 22 |
llm_semaphore = asyncio.Semaphore(PARALLEL_RATE_LIMIT)
|
|
|
|
| 6 |
from interfaces.ingredientModels import IngredientAnalysisResult
|
| 7 |
from logger_manager import log_error, log_info
|
| 8 |
from services.ingredientFinderAgent import IngredientInfoAgentLangGraph
|
|
|
|
| 9 |
from langsmith import traceable
|
| 10 |
import pytz
|
| 11 |
|
| 12 |
from utils.db_utils import ingredient_db_to_pydantic
|
| 13 |
|
| 14 |
# Load environment variables
|
| 15 |
+
from env import PARALLEL_RATE_LIMIT
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Create a semaphore to limit concurrent API calls
|
| 19 |
llm_semaphore = asyncio.Semaphore(PARALLEL_RATE_LIMIT)
|
utils/vuforia_utils.py
CHANGED
|
@@ -3,19 +3,13 @@ from logger_manager import log_info, log_error
|
|
| 3 |
from PIL import Image
|
| 4 |
import os
|
| 5 |
from pathlib import Path
|
| 6 |
-
from dotenv import load_dotenv
|
| 7 |
import requests
|
| 8 |
-
load_dotenv()
|
| 9 |
|
| 10 |
UPLOADED_IMAGES_DIR = "uploaded_images"
|
| 11 |
if not os.path.exists(UPLOADED_IMAGES_DIR):
|
| 12 |
os.makedirs(UPLOADED_IMAGES_DIR)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
VUFORIA_SERVER_ACCESS_KEY = os.getenv("VUFORIA_SERVER_ACCESS_KEY")
|
| 16 |
-
VUFORIA_SERVER_SECRET_KEY = os.getenv("VUFORIA_SERVER_SECRET_KEY")
|
| 17 |
-
VUFORIA_TARGET_DATABASE_NAME = os.getenv("VUFORIA_TARGET_DATABASE_NAME")
|
| 18 |
-
VUFORIA_TARGET_DATABASE_ID = os.getenv("VUFORIA_TARGET_DATABASE_ID")
|
| 19 |
|
| 20 |
def get_vuforia_auth_headers():
|
| 21 |
"""
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import os
|
| 5 |
from pathlib import Path
|
|
|
|
| 6 |
import requests
|
|
|
|
| 7 |
|
| 8 |
UPLOADED_IMAGES_DIR = "uploaded_images"
|
| 9 |
if not os.path.exists(UPLOADED_IMAGES_DIR):
|
| 10 |
os.makedirs(UPLOADED_IMAGES_DIR)
|
| 11 |
|
| 12 |
+
from env import VUFORIA_SERVER_ACCESS_KEY, VUFORIA_SERVER_SECRET_KEY, VUFORIA_TARGET_DATABASE_NAME, VUFORIA_TARGET_DATABASE_ID
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def get_vuforia_auth_headers():
|
| 15 |
"""
|