Sasya-AI-Backend / trained_models /SETUP_GUIDE.md
Neel2601's picture
Sasya AI: replace farmer-ai-backend with 4-model API + Gradio UI
041a776
|
Raw
History Blame Contribute Delete
6.43 kB
# 🌾 Agricultural AI System - Complete Setup Guide
## ✅ **Model Training Status Verification**
All models have been trained and are ready:
### **Trained Models Location: `trained_models/`**
- ✅ **Whisper Multilingual**: `whisper_multilingual/` (9 Indian languages)
- ✅ **TinyLlama Agricultural**: `tinyllama_agricultural/` (Q&A chatbot)
- ✅ **EfficientNet Crop Classification**: `efficientnet_crop_classification/`
- ✅ **Disease Detection**: `disease_detection/` (EfficientNet-V2 — train and place checkpoint here)
- ✅ **Market Prediction Models**: `market_prediction/` (3 ML models)
### **Pre-trained Models Location: `models/`**
- ✅ **NLLB Translation**: `models/translation/nllb_600m/` (Multi-language translation)
---
## 🚀 **Complete System Setup**
### **1. Backend API Setup**
#### **Install Backend Dependencies**
```bash
cd backend
pip install -r requirements.txt
```
#### **Start Backend Server**
```bash
python api_complete.py
```
**Backend will run on**: `http://localhost:8000`
**API Endpoints Available**:
- `/health` - Health check
- `/chat` - Agricultural Q&A
- `/speech-to-text` - Voice recognition
- `/text-to-speech` - Audio response generation
- `/image-diagnosis` - Disease detection
- `/crop-classification` - Crop identification
- `/market-prediction` - Price prediction
- `/translate` - Multi-language translation
---
### **2. Frontend Setup**
#### **Install Frontend Dependencies**
```bash
cd Frontend
npm install
# or
pnpm install
```
#### **Start Frontend Development Server**
```bash
npm run dev
# or
pnpm dev
```
**Frontend will run on**: `http://localhost:3000`
---
## 🔧 **System Architecture**
### **Backend (FastAPI)**
- **File**: `backend/api_complete.py`
- **Port**: 8000
- **Features**:
- All trained models loaded on startup
- CORS enabled for frontend connection
- GPU acceleration for inference
- Error handling and logging
### **Frontend (Next.js + React)**
- **File**: `Frontend/`
- **Port**: 3000
- **Features**:
- Modern UI with Tailwind CSS
- Real-time chat interface
- Image upload and diagnosis
- Voice input support
- Multi-language support
### **API Client**
- **File**: `Frontend/lib/api.ts`
- **Features**:
- TypeScript interfaces
- Error handling
- File upload support
- All endpoints connected
---
## 🎯 **How to Use the System**
### **1. Start Both Servers**
```bash
# Terminal 1 - Backend
cd backend
python api_complete.py
# Terminal 2 - Frontend
cd Frontend
npm run dev
```
### **2. Access the Application**
Open browser: `http://localhost:3000`
### **3. Available Features**
#### **🤖 AI Assistant**
- Ask questions in Hindi/English
- Get agricultural advice
- Real-time chat interface
#### **📸 Image Diagnosis**
- Upload plant images
- Get disease detection
- Treatment recommendations
#### **🎤 Voice Input & Output**
- **Speech-to-Text**: Speak in 9 Indian languages
- **Text-to-Speech**: AI responses as audio
- **Voice Interaction**: Complete voice-based conversation
#### **📊 Market Prediction**
- Enter crop details
- Get price predictions
- Market recommendations
#### **🌐 Translation**
- Translate between languages
- Support for Indian languages
- NLLB model integration
---
## 🔍 **Model Details**
### **1. Whisper Multilingual Speech Recognition**
- **Languages**: Bengali, Gujarati, Hindi, Kannada, Malayalam, Marathi, Odia, Tamil, Telugu
- **Training Data**: 67,072 samples
- **Use**: Voice input processing
### **2. TinyLlama Agricultural Q&A**
- **Training Data**: 50,231 agricultural Q&A pairs
- **Languages**: Hindi + English responses
- **Use**: Chat assistant
### **3. EfficientNet Vision Models**
- **Crop Classification**: Identifies crop types
- **Disease Detection**: Detects plant diseases
- **Use**: Image analysis
### **4. Market Prediction**
- **Models**: Random Forest, Gradient Boosting, Linear Regression
- **Use**: Price forecasting
### **5. NLLB Translation**
- **Model**: 600M parameters
- **Languages**: 200+ languages
- **Use**: Multi-language support
---
## 🛠️ **Troubleshooting**
### **Backend Issues**
```bash
# Check if models are loaded
curl http://localhost:8000/health
# Check GPU availability
python -c "import torch; print(torch.cuda.is_available())"
```
### **Frontend Issues**
#### **Dependency Resolution Error**
If you get `ERESOLVE unable to resolve dependency tree`:
```bash
# Clear cache and reinstall with legacy peer deps
rm -rf node_modules package-lock.json
npm install --legacy-peer-deps
```
#### **Alternative Installation**
```bash
# Use pnpm instead of npm
npm install -g pnpm
pnpm install
```
#### **Force Clean Install**
```bash
# Clear all caches
npm cache clean --force
rm -rf node_modules package-lock.json
npm install --legacy-peer-deps
```
### **Model Loading Issues**
- Ensure all trained models exist in `trained_models/`
- Check GPU memory (8GB RTX 4060 recommended)
- Verify Python dependencies are installed
---
## 📱 **System Requirements**
### **Hardware**
- **GPU**: NVIDIA RTX 4060 (8GB VRAM) or better
- **RAM**: 16GB+ recommended
- **Storage**: 10GB+ for models
### **Software**
- **Python**: 3.8+
- **Node.js**: 18+
- **CUDA**: 11.8+ (for GPU acceleration)
---
## 🎉 **Success Indicators**
### **Backend Ready**
```
INFO: Uvicorn running on http://0.0.0.0:8000
✅ All models loaded successfully!
```
### **Frontend Ready**
```
ready - started server on 0.0.0.0:3000
```
### **System Working**
- Chat responds to agricultural questions
- Image upload shows disease detection
- Voice input transcribes correctly
- All pages load without errors
---
## 🔗 **API Testing**
Test individual endpoints:
```bash
# Health check
curl http://localhost:8000/health
# Chat test
curl -X POST http://localhost:8000/chat -F "message=मेरे टमाटर में रोग है"
# Text-to-speech test
curl -X POST http://localhost:8000/text-to-speech -F "text=आपके पौधे में रोग है" -F "language=hi" --output speech.wav
# Image diagnosis test
curl -X POST http://localhost:8000/image-diagnosis -F "image_file=@plant_image.jpg"
```
---
## 📞 **Support**
If you encounter issues:
1. Check both backend and frontend logs
2. Verify all models are in correct directories
3. Ensure GPU drivers are updated
4. Check network connectivity between frontend/backend
**Your complete Agricultural AI System is now ready! 🌾🤖**