End-to-end setup for the Kerala Farming RAG Chatbot + Plant Disease Detection.
- Python 3.13 (preferred; repo pycache shows 3.13)
- Git
- (Optional) Google Gemini API key for better answers
- (Alternative) Ollama installed +
ollama pull llama2 - ~6 GB free disk (models + embeddings + deps)
git clone <repo-url>
cd krishAIbackendpy -3.13 -m venv .venv
./.venv/Scripts/Activate.ps1If PowerShell blocks scripts: run (once, as admin):
Set-ExecutionPolicy RemoteSignedCreate .env (or copy from example):
GEMINI_API_KEY=your_key_here # leave blank to use Ollama llama2
If no key: ensure Ollama service running and model pulled:
ollama pull llama2Both subprojects share nearly identical requirements. Install from one list (choose the larger — disease_detection):
pip install --upgrade pip
pip install -r disease_detection/requirements.txt(First install may take several minutes: torch, sentence-transformers, chromadb.)
This uses PDFs in rag_chatbot/data/kb and persists embeddings to rag_chatbot/chroma_db.
python rag_chatbot/main.py --setup-dbRebuild (e.g., after adding PDFs):
python rag_chatbot/main.py --setup-db --force-rebuildpython flask_app.pyTest endpoints:
curl http://127.0.0.1:8000/health
curl -X POST http://127.0.0.1:8000/chat -H "Content-Type: application/json" -d '{"query":"Best paddy practices in monsoon?"}'python rag_chatbot/main.py --chatCombine build + chat:
python rag_chatbot/main.py --setup-db --chatImage model: disease_detection/model/plant_disease_cnn_scripted.pt (CPU inference).
Run analysis (uses disease_detection/chroma_db by default—point it to the one you built if needed):
python disease_detection/main.py --image disease_detection/test_images/CornCommonRust1.JPG --db-path ../rag_chatbot/chroma_dbInteractive mode:
python disease_detection/main.py --image disease_detection/test_images/PotatoHealthy2.JPG --interactive --db-path ../rag_chatbot/chroma_db| Problem | Fix |
|---|---|
| Module import errors | Ensure venv active & deps installed |
| Chatbot says DB missing | Re-run vector build step |
| Gemini errors | Check GEMINI_API_KEY and network |
| Ollama fallback fails | Start Ollama app/service; pull model |
| Slow first answer | Embedding model + DB warm-up; improves after |
- Drop new PDFs into
rag_chatbot/data/kb/ - Rebuild:
python rag_chatbot/main.py --setup-db --force-rebuild - Restart Flask server (if running)
# Health
curl http://127.0.0.1:8000/health
# Simple chat
curl -X POST http://127.0.0.1:8000/chat -H "Content-Type: application/json" -d '{"query":"Soil conservation methods"}'
# Disease detection
python disease_detection/main.py --image disease_detection/test_images/virus4.JPG --db-path ../rag_chatbot/chroma_dbflask_app.py: REST API wrapper over RAG chatbotrag_chatbot/: RAG pipeline, vector DB builder, PDFsdisease_detection/: Image classifier + RAG treatment adviser
All configured for CPU; set model_kwargs={'device':'cuda'} in build_vector_db.py & adjust torch install for GPU acceleration.
- Unify requirements into root
requirements.txt - Add Dockerfile
- Add basic pytest health tests
- Share single chroma_db between both subsystems via config
Happy farming 🌱