TeaCareAI is a full-stack intelligence platform tailored for tea farmers and agronomists, specifically designed to address tea leaf diseases in Sri Lanka and beyond.
By taking an ordinary smartphone picture of a tea leaf, the application leverages deeply trained vision models and Retrieval-Augmented Generation (RAG) to precisely evaluate tea leaf health, provide real-time treatment guidance, and track the recovery progress of affected fields over time.
- Leaf Verifier (
leaf_verifier.py): Pre-validates uploaded images to ensure they represent a valid tea leaf, minimizing false positives on stray photos. - Disease & Severity Identification (
tea_disease_identifier.py): Employs an Ultralytics YOLO (PyTorch) model (tea_disease_identifier_weight.pt) to detect the specific disease (e.g., Blister Blight, Pestalotiopsis) and calculate the percentage of leaf infection/severity.
- RAG Engine (
treatment_recommendations.py): Uses a local Vector Database (ChromaDB + SentenceTransformersBAAI/bge-small-en-v1.5) mapped to a localized treatment repository. - Natural Language Explanations: Uses Ollama running
llama3.1:8bright on the edge to turn agriculture knowledge into actionable advice for the farmer—working entirely offline if needed.
- Post-treatment Tracking (
recovery_tracker.py): Associates scans using a unique chat/scan barcode. Uses a TensorFlow/Keras Neural Network (recovery_model.h5) to analyze sequential data and deduce whether a plant's health is "Improving," "Deteriorating," "Stable," or "New." - Field Management: Geo-tags and tracks crop elevation, tea variety, and plant age for aggregate analytics across the property.
The project relies on a modular Flask backend interfaced with independent machine learning services, bound together by a robust PostgreSQL data management tier.
TeaCareAI/
├── app.py # Flask application routes
├── main.py # Entry point: runs pre-flight constraints, then launches Flask
├── controller.py # Business logic coordinating services & DB operations
├── auth.py # Session management and generic auth mechanisms
├── bootstrap.py # Creates target DB schema & primes the LLM
├── check_constraints.py # Ensures Python version, Ollama, & DB are active before startup
├── config.py # Environment variable validations & configuration objects
├── pyproject.toml / requirements.txt # Python dependencies
├── docker-compose.yml / Dockerfile # Containerization config for the stack
├── app/
│ ├── database/ # Data models, DB initializations SQL (`create_tables.sql`)
│ ├── models/ # YOLO Weights (.pt) and TF Models (.h5, .pkl scalers)
│ └── services/ # Core ML processing APIs (RAG, Inference, Tracker)
├── data/ # Raw Datasets & Chroma SQLite KB files
├── scripts/ # Model Retraining Notebooks, retriever tests (`testing.py`)
├── static/ # Frontend Assets (CSS, JS, Icons) + Image Uploads
└── templates/ # Rendered UI Views (`index.html`, `analayze.html`, etc.)
- Python: 3.11.x
- PostgreSQL: Version 14+ (Ensure a user is set up and permitted)
- Ollama: Installed and actively running locally (with the selected model pulled)
-
Clone & Virtual Environment
python -m venv .venv .\.venv\Scripts\Activate.ps1 -
Install Dependencies
python -m pip install --upgrade pip pip install -r requirements.txt
If you do have a CUDA-compatible setup, use
requirements_cuda.txtalternatives carefully and pin versions as needed for your machine. -
Environment Variables
Copy-Item .env.example .envModify the new
.envfile to match your PostgreSQL credentials (DB_USER, DB_PASSWORD, DB_HOST, DB_NAME), the OPENWEATHERMAP_API_KEY, and ensure LLM_NAME / EMBEDDING_MODEL are aligned. -
Pull Local LLM Model
ollama pull llama3.1:8b -
Initialize Database & RAG Check
python bootstrap.py
-
Start Application Server
python main.py
Access the web app at
http://localhost:5000
To spin up the entire application enclosed securely in its own environment with a managed Postgres container:
# Set DB_HOST=db in your .env before proceeding
docker compose up --buildOn the very first launch, open a terminal into the container to run the bootstrap process:
docker compose exec app python bootstrap.py- Account Handling: Users sign up (
/signup) or log in (/login) tracking device telemetry. - Fields: Users manage their geographical plots of tea via
/field/addspecifying variety and age. - Analyze Dashboard: Accessed via
/analayze, farmers upload their images.
The /scripts/ folder houses research and ops protocols:
train_model.py: Pipeline for updating the Keras recovery timeline model.report_generator.ipynb: Notebook analyzing historical dataset aggregates.retriever_correctness.py: Utility testing chroma extraction vs. expected ground truths for debugging.