Gaurav6047/Smart-Farmer-AI
๐ฑ 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
pip install -r requirements.txt
streamlit run main.pyโ๏ธ Deploy on Streamlit Cloud
- Upload to GitHub
- Go to https://share.streamlit.io
- Select
main.py - 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 ๐ฑ
