Skip to content

harshala334/disease-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌾 AI-Based Crop & Livestock Disease Diagnosis (WebApp)

🧠 Detect crop and livestock diseases using AI-powered image & symptom analysis. Farmers upload an image or describe symptoms → AI predicts disease → backend provides recommendations & alerts veterinarians.


🧩 System Overview

Architecture Flow

Farmer WebApp (React) → FastAPI Backend → AI Model (TensorFlow/PyTorch) → MongoDB Database → Notification Service (Email / SMS via Twilio)

Key Features

  • 🖼️ Upload crop/livestock images
  • 💬 Text-based symptom input
  • 🤖 AI model for disease classification
  • 🩺 Vet alert for critical cases
  • 📊 Admin dashboard for analytics

⚙️ Tech Stack

Component Technology
Frontend React + Tailwind CSS
Backend FastAPI (Python)
AI Model TensorFlow / PyTorch
Database MongoDB (Atlas or Local)
Notifications Twilio / EmailJS

📁 Project Structure

disease-detection/
│
├── backend/                    # FastAPI Backend
│   ├── main.py                # Application entry point
│   ├── config.py              # Configuration & settings
│   ├── database.py            # MongoDB connection
│   ├── requirements.txt       # Python dependencies
│   ├── .env.example          # Environment template
│   ├── models/               # Data models
│   │   ├── user.py
│   │   ├── disease_report.py
│   │   └── veterinarian.py
│   ├── routes/               # API endpoints
│   │   ├── auth.py          # Authentication
│   │   ├── diagnosis.py     # Disease detection
│   │   ├── admin.py         # Admin dashboard
│   │   └── veterinarians.py # Vet management
│   ├── services/             # Business logic
│   │   ├── auth.py          # JWT & authentication
│   │   └── notification.py  # Email/SMS alerts
│   └── uploads/             # Uploaded images
│
├── frontend/                  # React Frontend
│   ├── src/
│   │   ├── App.jsx           # Main component
│   │   ├── main.jsx          # Entry point
│   │   ├── pages/            # Page components
│   │   │   ├── Home.jsx
│   │   │   ├── Login.jsx
│   │   │   ├── Register.jsx
│   │   │   ├── Upload.jsx
│   │   │   ├── Results.jsx
│   │   │   ├── Dashboard.jsx
│   │   │   └── AdminDashboard.jsx
│   │   ├── components/       # Reusable UI
│   │   │   └── Navbar.jsx
│   │   ├── context/          # State management
│   │   │   └── AuthContext.jsx
│   │   └── api/             # API client
│   │       └── api.js
│   ├── package.json
│   ├── vite.config.js       # Vite config
│   └── tailwind.config.js   # Tailwind CSS
│
├── ai_model/                  # AI/ML Module
│   ├── inference.py          # Disease detection (hardcoded)
│   ├── sample_images/        # Sample disease images
│   └── README.md            # Model documentation
│
├── SETUP_GUIDE.md            # Detailed setup instructions
├── TESTING_GUIDE.md          # Testing documentation
└── README.md                 # This file

🧰 Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • MongoDB (Atlas or Local)

Installation

  1. Clone the repository

    cd /workspaces/disease-detection
  2. Backend Setup

    cd backend
    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
    cp .env.example .env
    # Edit .env with your MongoDB URL and other settings
    python main.py

    Backend runs on: http://localhost:8000

  3. Frontend Setup (New Terminal)

    cd frontend
    npm install
    npm run dev

    Frontend runs on: http://localhost:3000

  4. MongoDB Setup

    • Create free account at MongoDB Atlas
    • Create cluster and get connection string
    • Add connection string to backend/.env

📖 Detailed Guides

🎯 Quick Test

  1. Register at http://localhost:3000/register
  2. Login and go to Upload
  3. Select "tomato" as type
  4. Upload image (name it tomato_blight.jpg for testing)
  5. Add symptoms: "brown spots, wilting"
  6. View diagnosis results!

📡 Deployment

Layer Platform Purpose
Backend Render Auto deploy FastAPI server
Database MongoDB Atlas Cloud database
Frontend Vercel Deploy React web app

🧪 Example Flow

  1. Farmer opens the web app and uploads an image.
  2. The backend receives it and sends it to the AI model.
  3. The model predicts the disease.
  4. The backend stores the report and sends recommendations.
  5. A notification is sent to the nearest veterinarian if needed.
  6. Admins can view disease trends and reports through the dashboard.

🎯 Key Features Implemented

User Authentication - Register, Login, JWT-based auth
Image Upload - Multi-part form data handling
Disease Detection - 15 hardcoded diseases with pattern matching
Symptom Analysis - Text-based disease prediction
Confidence Scoring - AI confidence levels
Vet Notifications - Automatic alerts for critical cases
User Dashboard - View all diagnosis reports
Admin Dashboard - Analytics with charts & graphs
Responsive UI - Mobile-friendly design
MongoDB Integration - Cloud or local database
API Documentation - Interactive Swagger UI at /docs


🤖 AI Model Details

This version uses a hardcoded disease database instead of a trained ML model for quick testing:

  • 15 Diseases Covered:

    • 8 Crop Diseases (Tomato Blight, Wheat Rust, Rice Blast, etc.)
    • 7 Livestock Diseases (FMD, Newcastle, Mastitis, etc.)
  • Detection Method:

    • Image filename pattern matching
    • Symptom keyword matching
    • Hash-based consistent assignment
  • For Production:

    • Replace ai_model/inference.py with actual TensorFlow/PyTorch model
    • Train on real disease image datasets
    • Implement proper image preprocessing

📊 API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login and get JWT token
  • GET /api/auth/me - Get current user

Diagnosis

  • POST /api/diagnosis/detect - Upload image and detect disease
  • GET /api/diagnosis/reports - Get user's reports
  • GET /api/diagnosis/reports/{id} - Get specific report

Admin (Admin Only)

  • GET /api/admin/dashboard - Dashboard statistics
  • GET /api/admin/reports - All reports
  • GET /api/admin/analytics - Analytics data

Veterinarians

  • POST /api/veterinarians/ - Create veterinarian
  • GET /api/veterinarians/ - List veterinarians
  • GET /api/veterinarians/{id} - Get vet details

Interactive API Docs: http://localhost:8000/docs


� Security Features

  • Password hashing with bcrypt
  • JWT token authentication
  • Role-based access control (Farmer, Vet, Admin)
  • CORS configuration
  • Input validation with Pydantic

�🚀 Future Enhancements

  • Replace hardcoded detection with trained CNN model
  • Integration with weather-based disease prediction
  • Multilingual support (Marathi, Hindi, English)
  • Offline functionality using PWA
  • GIS heatmaps to identify outbreak zones
  • Mobile app (React Native)
  • Real-time chat with veterinarians
  • Blockchain for disease report verification

🐛 Troubleshooting

Backend won't start:

  • Check MongoDB connection string in .env
  • Ensure virtual environment is activated
  • Verify Python 3.8+ is installed

Frontend won't start:

  • Delete node_modules and run npm install again
  • Check Node.js version (16+ required)
  • Ensure backend is running on port 8000

Disease detection not working:

  • Name images with disease keywords (e.g., tomato_blight.jpg)
  • Add relevant symptoms
  • Check backend logs for errors

See SETUP_GUIDE.md for detailed troubleshooting.


📞 Support & Documentation


📄 License

This project is for educational purposes. Feel free to use and modify as needed.


🙏 Acknowledgments

  • FastAPI for the amazing Python web framework
  • React + Vite for the frontend
  • MongoDB for the database
  • Tailwind CSS for styling
  • Recharts for data visualization

Made with ❤️ for farmers and agriculture professionals

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages