CoolFace
Apppublic

Gaurav6047/Smart-Farmer-AI

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
App README

๐ŸŒฑ Smart Farmer AI

AI-Powered Crop Recommendation, Plant Disease Detection, Pest Detection, Fruit Classification & Scientific Fertilizer Engine

<p align="center"> <img src="assets/banner.png" width="90%" /> </p>

<p align="center"> <b>Streamlit โ€ข TFLite โ€ข YOLOv8 โ€ข RandomForest โ€ข Scientific STCR Engine</b> </p>


โญ Badges

<p align="center"> <img src="https://img.shields.io/badge/Streamlit-App-brightgreen?style=for-the-badge"> <img src="https://img.shields.io/badge/TFLite-Models-blue?style=for-the-badge"> <img src="https://img.shields.io/badge/YOLOv8-Pest Detection-orange?style=for-the-badge"> <img src="https://img.shields.io/badge/Fertilizer-STCR Engine-red?style=for-the-badge"> <img src="https://img.shields.io/badge/ML-RandomForest-yellow?style=for-the-badge"> </p>


๐Ÿ“Œ Overview

Smart Farmer AI is a full-stack agricultural intelligence system designed for real-world farmers. It integrates multiple AI models, scientific agriculture datasets, and a rule-based fertilizer engine โ€” all inside one beautiful, mobile-optimized Streamlit UI.

โœ” Photo โ†’ Disease/Pest/Fruit detection โœ” Soil data โ†’ Best Crop โ†’ Full Fertilizer Plan โœ” Works offline โœ” Lightweight + Fast โœ” Multilingual (English + Hindi)


๐Ÿง  Features


๐ŸŒฟ Plant Disease Detection

  • โ€”38-class PlantVillage TFLite model
  • โ€”CPU-optimized (5โ€“20 ms inference)
  • โ€”High accuracy + mobile-friendly
  • โ€”Full confidence score + alerts

๐Ÿ› Pest Detection (YOLOv8)

  • โ€”Custom-trained YOLOv8 model
  • โ€”Real-time detection
  • โ€”Bounding boxes + confidence
  • โ€”Works for Indian farm pests

๐ŸŽ Fruit & Vegetable Classification

  • โ€”36-class TFLite classifier
  • โ€”Preprocessed for low-power devices
  • โ€”High accuracy on common fruits/vegetables

๐Ÿ”€ Auto Image Router

Automatically routes image to:

  • โ€”Plant Disease Page
  • โ€”Pest Detection Page
  • โ€”Fruit Classification Page
  • โ€”Or Background Warning

Powered by 64ร—64 tiny CNN โ€” fast and lightweight.


๐ŸŒพ Crop Recommendation System (ML Model)

A machine learning system trained using:

  • โ€”N, P, K
  • โ€”pH
  • โ€”Rainfall
  • โ€”Temperature
  • โ€”Soil Type
  • โ€”Region Data

Model Used: RandomForestClassifier

โœ” Predicts best crop โœ” Provides confidence score โœ” Uses scaler for normalization โœ” Works offline โœ” Hindi + English support

Files:

models/crop_rf_final.pkl
models/scaler.pkl

๐Ÿงช Scientific Fertilizer Recommendation Engine

A professional-grade fertilizer engine built using:

  • โ€”STCR equations
  • โ€”Indian soil fertility thresholds
  • โ€”Micronutrient critical levels
  • โ€”Organic nutrient substitution logic
  • โ€”Legume rotation credits
  • โ€”pH + EC correction rules
  • โ€”Commercial NPK-to-bags conversion

Outputs include:

โœ” N, Pโ‚‚Oโ‚…, Kโ‚‚O (kg/ha) โœ” Organic credits deduction โœ” Urea, DAP, MOP bags โœ” Micronutrient recommendations โœ” Soil correction alerts โœ” Agronomic notes โœ” Full calculation breakdown

Uses the following datasets:

models/soil_fertility.json
models/standard_npk.csv
models/stcr_equations.json
models/organic_rules.json

๐Ÿ“ Project Structure

smart-farmer/
โ”‚โ”€โ”€ main.py
โ”‚โ”€โ”€ router.py
โ”‚โ”€โ”€ requirements.txt
โ”‚
โ”‚โ”€โ”€ pages/
โ”‚   โ”œโ”€โ”€ ๐ŸŒฟ_Plant_Disease.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ›_Pest_Detection.py
โ”‚   โ”œโ”€โ”€ ๐ŸŽ_Fruit_Classification.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ”€_Auto_Routing.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“Š_Crop_Recommendation.py
โ”‚   โ”œโ”€โ”€ ๐Ÿงช_Fertilizer_Recommendation.py
โ”‚   โ””โ”€โ”€ ๐Ÿ“˜_Fertilizer_Engine_Info.py
โ”‚
โ”‚โ”€โ”€ engine/
โ”‚   โ”œโ”€โ”€ recommender.py
โ”‚   โ”œโ”€โ”€ stcr.py
โ”‚   โ”œโ”€โ”€ organic_rules.py
โ”‚   โ”œโ”€โ”€ brand_converter.py
โ”‚   โ”œโ”€โ”€ thresholds.py
โ”‚   โ”œโ”€โ”€ loader.py
โ”‚   โ””โ”€โ”€ auto_crop.py
โ”‚
โ”‚โ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ plant_disease.tflite
โ”‚   โ”œโ”€โ”€ fruit_model.tflite
โ”‚   โ”œโ”€โ”€ pest_model.pt
โ”‚   โ”œโ”€โ”€ router_model.tflite
โ”‚   โ”œโ”€โ”€ soil_fertility.json
โ”‚   โ”œโ”€โ”€ standard_npk.csv
โ”‚   โ”œโ”€โ”€ stcr_equations.json
โ”‚   โ”œโ”€โ”€ organic_rules.json
โ”‚   โ”œโ”€โ”€ crop_rf_final.pkl
โ”‚   โ””โ”€โ”€ scaler.pkl
โ”‚
โ”‚โ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ theme.py
โ”‚   โ”œโ”€โ”€ language.py
โ”‚   โ”œโ”€โ”€ result_box.py
โ”‚   โ”œโ”€โ”€ preprocess.py
โ”‚   โ”œโ”€โ”€ postprocess.py
โ”‚   โ””โ”€โ”€ model_loader.py
โ”‚
โ””โ”€โ”€ assets/

โš™๏ธ Installation

bash
pip install -r requirements.txt
streamlit run main.py

โ˜๏ธ Deploy on Streamlit Cloud

  1. 1.Upload to GitHub
  2. 2.Go to https://share.streamlit.io
  3. 3.Select main.py
  4. 4.Deploy โ†’ Done ๐ŸŽ‰

๐Ÿ“ฑ Mobile-Optimized

โœ” Touch-friendly โœ” Responsive grid โœ” Camera input โœ” Smooth animations โœ” Dark/Light friendly


๐Ÿ”ฎ Future Enhancements

  • โ€”AI Voice Assistant (Hindi + English)
  • โ€”Offline Android App
  • โ€”Weather-aware crop planning
  • โ€”Yield prediction model
  • โ€”Auto fertilizer schedule based on NDVI

โœจ Author

Gaurav โ€” Machine Learning Engineer Building practical & intelligent AI for agriculture ๐ŸŒฑ