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

cd backend
pip install -r requirements.txt

Start Backend Server

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

cd Frontend
npm install
# or
pnpm install

Start Frontend Development Server

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

# 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

# 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:

# Clear cache and reinstall with legacy peer deps
rm -rf node_modules package-lock.json
npm install --legacy-peer-deps

Alternative Installation

# Use pnpm instead of npm
npm install -g pnpm
pnpm install

Force Clean Install

# 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:

# 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! ๐ŸŒพ๐Ÿค–