How adarshh9/nutriai works
Project Type and Purpose
• Full-stack web application for personalized nutrition recommendations
• Combines multiple AI subsystems (Knowledge Graph, GNN, Text Retrieval, LLM explanations, RL cache) behind a Flask frontend
File Structure
• core/Flask – Flask app entrypoint (main.py, app.py), configurations, templates (HTML)
• core/kg_inference – Knowledge graph loader & query logic, CSV/PKL data
• core/gnn_inference – Pretrained GNN model and inference code
• core/text_Retrieval – FAISS index and text-retrieval logic
• core/*.ipynb – Notebooks (development/experimentation)
• dataset/ – Raw CSV/Excel nutritional and food-disease data
• experiments/ – Prototype apps and scripts (not part of production)
README Insights
• Emphasis on multi-model aggregation, scientific evidence retrieval, LLM explanation, RL-based caching, and visualization
Main Components
A. User Interface (Web UI)
– Flask routes & HTML templates (index.html, results.html, cache.html)
B. Flask Web Server (Orchestrator)
– Receives HTTP requests, normalizes input, coordinates subcomponents
C. Knowledge Graph Module
– core/kg_inference/kg.py, data files (kg_data.csv, nutrient_data.csv, etc.)
D. Graph Neural Network Module
– core/gnn_inference/gnn.py, model checkpoint (gnn_model.pt)
E. Text Retrieval Module
– core/text_Retrieval/tr.py, FAISS index, metadata
F. LLM Explanation Service
– Groq LLama-3-70B API client
G. Reinforcement Learning Cache
– Q-learning code, persistence (nutriai_cache.json)
H. Visualization Component
I. Data Sources & Storage
– dataset folder, PKL/CSV/Excel files
J. External Services
– Groq API, optional data stores for persistence
Interactions and Data Flow
1. User → (HTTP) → Flask
2. Flask → [KG module] → KG results
3. Flask → [GNN module] → Novel predictions
4. Flask → [Text Retrieval] → Evidence snippets
5. Flask aggregates → Intermediate “Results”
6. Flask → [RL Cache] checks for explanation
• Cache hit → retrieve explanation
• Cache miss → call Groq API → receive explanation → feed back to RL cache
7. Flask → [Visualization] when requested → generate graph
8. Flask → Format full response → HTML/JSON → UI → User
Architectural Patterns and Principles
• Modular separation of concerns (KG, GNN, TextR, LLM, Cache, Viz)
• Central orchestrator (Flask) following an MVC-like flow
• Data-driven modules reading from common dataset store
• Asynchronous or parallel calls to inference modules (for performance)
• RL-based dynamic caching for optimization