How ateeb09/leaf-crop works
1. Overall shape
- This repository is a hybrid ML advisory system with two runtime entry points: a Streamlit dashboard for interactive local use and a Flask API + static site for a more production-like deployment.
- The core business logic and model loading are centralized so both UIs can share the same predictions and advisory pipeline.
2. User-facing surfaces
- app.py is the Streamlit entry point.
- server.py is the Flask entry point, serving the API and the compiled frontend in static/.
- frontend/ appears to hold the frontend source, while static/ contains the built assets actually served by Flask.
3. Shared application core
- core.py is the main shared boundary for configuration, model loading, and prediction/advisory logic.
- This is likely where the two UIs converge before calling the ML artifacts, which keeps the presentation layer separated from inference logic.
4. Weather-driven disease risk pipeline
- The system fetches live weather from OpenWeatherMap or accepts demo weather values.
- Those environmental features feed risk_model.pkl, which is a Random Forest model for predicting crop disease outbreak risk.
- Supporting weather data and historical processing are stored in CSVs like daily_weather_processed.csv, bengaluru.csv, and satellite_dataset.csv.
5. Leaf image diagnosis pipeline
- Leaf diagnosis uses deep learning models saved as .h5 files.
- There is a generic gate model (leaf_classifier.h5) that likely determines whether the image is actually a leaf.
- If the gate passes, the system routes into crop-specific classifiers such as leaf_classifier_tomato.h5, leaf_classifier_potato.h5, etc., with matching label maps in leaf_classes_*.json.
6. Multi-crop model family
- The repository supports multiple crop-specific disease classifiers: tomato, potato, apple, grape, peach, cherry, corn/maize, strawberry, bell pepper, and a generic model.
- leaf_model.py, leaf_model_generic.py, and leaf_model_multi_crop.py suggest separate training/inference code paths for single-crop and multi-crop variants.
7. Satellite/environment estimation
- satellite_model.pkl and satellite_model_meta.json provide a second prediction branch for estimating environmental or soil-related attributes such as soil type, soil moisture, and wind speed.
- This branch complements the risk model by turning local weather into broader agronomic context.
8. Fertilizer recommendation subsystem
- fertilizer_model.pkl, fertilizer_model.py, fertilizer_dataset.csv, and fertilizer_model_meta.json form the fertilizer recommendation pipeline.
- Inputs likely combine crop identity and estimated soil/environment properties to produce a tailored fertilizer suggestion.
9. Training and data-preparation boundary
- Training and data transformation are explicitly separated from runtime through scripts like train_risk_model.py, build_real_datasets.py, and reorganize_plant_diseases_dataset.py.
- leaf_model_dataset/ contains the image training corpus for at least potato and tomato disease classes plus a non-leaf class.
10. Deployment artifacts vs source
- The .pkl and .h5 files are pre-trained runtime artifacts, while the CSVs and dataset folders are inputs used during training or baseline estimation.
- requirements.txt, requirements-web.txt, and runtime.txt define the Python/runtime environment for local or hosted execution.
11. End-to-end data flow
- A typical request starts with a city and crop selection, optionally plus a leaf image.
- The app fetches or accepts weather, runs disease-risk prediction, optionally runs image-based disease classification, estimates environment/soil properties, and then produces fertilizer and treatment guidance.
- The final output is an advisory bundle rather than a single prediction.
12. What to diagram as boundaries
- Draw clear separations between: presentation layers (app.py, server.py, frontend/, static/), shared orchestration (core.py), ML inference artifacts (*.pkl, *.h5, leaf_classes_*.json), and training/data prep scripts and datasets.
- The main external dependency worth showing is OpenWeatherMap, since live weather is a first-class input to the advisory flow.
Main entry points: core.py Core logic · leaf_model.py Leaf training · leaf_classifier.h5 Leaf gate · server.py Flask server
Components 25
Presentation
Interactive and deployed user-facing entry points
- Streamlit app · Local interactive dashboard entry point
app.py - Flask server · API and static-site serving entry point
server.py - Frontend src · Frontend application source bundled for deployment
frontend - Static site · Built frontend assets served by Flask
static
Core
Shared orchestration and prediction logic
- Core logic · Shared configuration, model loading, and advisory pipeline
core.py
ML Artifacts
Pretrained models and label maps used at runtime
- Risk model · Weather-driven disease risk predictor
risk_model.pkl - Satellite model · Estimates soil and environmental attributes
satellite_model.pkl - Satellite meta · Metadata for satellite/environment model outputs
satellite_model_meta.json - Fertilizer model · Produces fertilizer suggestions from crop and context inputs
fertilizer_model.pkl - Fertilizer meta · Metadata for fertilizer recommendation outputs
fertilizer_model_meta.json - Leaf gate · Generic model that checks whether an image is a leaf
leaf_classifier.h5 - Crop classifiers · Crop-specific disease classifiers for tomato, potato, apple, grape, peach, cherry, corn, strawberry, and bell pepper
- Class maps · JSON label dictionaries for leaf classifiers
leaf_classes.json
Training & Data
Scripts and datasets for building models
- Leaf dataset · Training images for leaf and disease classes
leaf_model_dataset - Leaf training · Training and inference code for leaf classifiers
leaf_model.py - Multi-crop code · Multi-crop leaf model variant and routing logic
leaf_model_multi_crop.py - Generic leaf code · Generic leaf classifier training and inference code
leaf_model_generic.py - Risk training · Builds the crop disease risk model
train_risk_model.py - Fertilizer code · Fertilizer recommendation implementation
fertilizer_model.py - Satellite code · Satellite/environment model implementation
satellite_model.py - Weather data · Processed weather history used for modeling
daily_weather_processed.csv - Bengaluru data · City-level weather sample or baseline dataset
bengaluru.csv - Satellite data · Dataset for environmental estimation modeling
satellite_dataset.csv - Fertilizer data · Training dataset for fertilizer recommendations
fertilizer_dataset.csv
External
Live third-party dependency
- OpenWeatherMap · Live weather source used as a first-class input
Connections 22
- Streamlit app → Core logic: shared logic · Streamlit dashboard delegates prediction and advice generation
- Flask server → Core logic: shared logic · Flask API uses the shared orchestration layer
- Flask server → Static site: serves · Flask serves the compiled frontend assets
- Frontend src → Static site: builds to · Frontend source is packaged into static assets
- Core logic → OpenWeatherMap: fetches weather · Retrieves live weather for advisory inputs
- Core logic → Risk model: predicts risk · Runs the weather-driven disease risk model
- Core logic → Satellite model: estimates context · Infers soil and environmental attributes
- Core logic → Satellite meta: reads metadata · Uses model metadata to interpret outputs
- Core logic → Fertilizer model: recommends fertilizer · Generates fertilizer guidance from crop and context
- Core logic → Fertilizer meta: reads metadata · Uses metadata for fertilizer output interpretation
- Core logic → Leaf gate: checks image · First-stage gate for image-based diagnosis
- Core logic → Crop classifiers: routes to · Dispatches to the appropriate crop-specific classifier
- Core logic → Class maps: maps classes · Converts classifier outputs into human-readable labels
- Leaf training → Leaf gate: trains · Training code for the generic gate model
- Leaf training → Crop classifiers: trains · Training code for crop-specific image classifiers
- Multi-crop code → Crop classifiers: variant · Multi-crop model path used for broader crop coverage
- Generic leaf code → Leaf gate: variant · Generic leaf classifier implementation
- Leaf training → Leaf dataset: uses data · Leaf training corpus for disease classification
- Risk training → Weather data: trains on · Builds the risk model from historical weather data
- Risk training → Bengaluru data: uses data · Supplemental weather dataset for training or baseline input
- Satellite code → Satellite data: trains on · Builds environmental estimation model from satellite data
- Fertilizer code → Fertilizer data: trains on · Builds fertilizer recommendation model from dataset