How inflixop/smart-agriculture-advisory-system works
Purpose and Entry Points
This repository delivers a local Smart Agriculture Advisory System that recommends a crop from soil and weather inputs. The deployable entry point is app.py; its browser interface is templates/index.html with styling in static/styles.css. Exploratory/training workflows are preserved in Smart_Agriculture_System.ipynb and knn-model.ipynb.
Web Application Boundary
app.py is the application controller: it accepts user-supplied nitrogen, phosphorus, potassium, temperature, humidity, pH, and rainfall values, invokes a persisted model, and returns a recommendation to the rendered UI. templates/index.html is the presentation/input boundary, while static/styles.css supplies client-side appearance. No separate API service, database, or authentication layer is present in the repository tree.
Feature Contract and Dataset
Crop_recommendation.csv defines the model-facing tabular contract: seven numeric agronomic/environmental features and the target crop label. The same ordered feature set must be maintained from form extraction in app.py through model inference; model artifacts cannot safely accept reordered or differently transformed inputs.
Model Training and Experimentation
Smart_Agriculture_System.ipynb is the primary analysis/model-development artifact described by the README, covering preprocessing, classifier evaluation, and prediction exploration. knn-model.ipynb indicates a parallel KNN experiment. These notebooks are offline development stages rather than application runtime dependencies, but they define how the CSV data becomes serialized inference artifacts.
Persisted Inference Artifacts
Three binary artifacts are checked into the repository: smart-agriculture.joblib, knn_model.joblib, and smart-agripkl.pkl. They separate model training from request-time prediction and require compatible Python ML-library serialization versions at runtime. The README identifies Random Forest as the selected deployment model, while the KNN artifact provides an alternate or experimental classifier; app.py is the source of truth for which artifact is loaded.
Primary Control Flow
A user opens the HTML form (templates/index.html), submits soil/weather values to app.py, and the server converts those values into the model’s expected feature vector. The loaded serialized classifier (smart-agriculture.joblib, smart-agripkl.pkl, or knn_model.joblib) predicts a crop label, which app.py passes back into the rendered response. The browser displays that recommendation using templates/index.html and static/styles.css.
Runtime and Infrastructure
The runtime is Python, expected to be managed through Conda per README.md, with Jupyter used for notebook-based training/analysis. package.json exists but no JavaScript source, build pipeline, or Node service is visible, so it is not a core execution path based on the tree. The only identified external data source is the Kaggle Crop Recommendation Dataset, materialized locally as Crop_recommendation.csv; inference itself appears local and does not depend on external services.
Main entry points: app.py Application controller · Smart_Agriculture_System.ipynb Primary model development · index.html Crop input form · Crop_recommendation.csv Crop recommendation data
Components 12
Offline model development
Notebook-based analysis and training.
- Crop recommendation data · Seven ordered numeric features plus crop label.
Crop_recommendation.csv - Primary model development · Preprocessing, evaluation, and prediction exploration.
Smart_Agriculture_System.ipynb - KNN experiment · Parallel classifier experiment.
knn-model.ipynb - Selected RF model · README-selected deployed classifier artifact.
smart-agriculture.joblib - KNN model · Alternate experimental classifier.
knn_model.joblib - Serialized model · Additional persisted inference artifact.
smart-agripkl.pkl
Local web application
Python-hosted crop recommendation flow.
- Crop input form · Collects soil and weather values and displays recommendations.
templates/index.html - UI styling
static/styles.css - Application controller · Extracts ordered features, loads the configured artifact, and renders predictions.
app.py - Ordered feature vector · Nitrogen, phosphorus, potassium, temperature, humidity, pH, and rainfall.
- Loaded classifier · Deserialized artifact selected by app.py.
- Crop recommendation · Predicted crop label returned to the rendered page.
Connections 15
- Crop recommendation data → Primary model development: training data
- Crop recommendation data → KNN experiment: training data
- Primary model development → Selected RF model: trains and serializes
- Primary model development → Serialized model: serializes
- KNN experiment → KNN model: trains and serializes
- UI styling → Crop input form: styles
- Crop input form → Application controller: submits seven inputs
- Application controller → Ordered feature vector: extracts in contract order
- Ordered feature vector → Loaded classifier: predicts with
- Selected RF model → Loaded classifier: possible loaded artifact · app.py determines the actual artifact.
- KNN model → Loaded classifier: possible loaded artifact · app.py determines the actual artifact.
- Serialized model → Loaded classifier: possible loaded artifact · app.py determines the actual artifact.
- Loaded classifier → Crop recommendation: predicts crop label
- Crop recommendation → Application controller: returned for rendering
- Application controller → Crop input form: renders result