Skip to content

Ritviks21/F2-Farm-Friend-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Farm Friend Project Banner

Farm Friend

An end-to-end Explainable AI (XAI) and economic advisory platform for Indian agriculture.

Python Version Scikit-Learn Gradio UI SHAP XAI

Live DemoProject OverviewOur JourneyKey FeaturesTech StackResults


🚀 Live Demo

Hugging Face Space

Click the badge above or follow this link to try the live application: https://huggingface.co/spaces/srits21/farm-friend-2

This system is hosted live on Hugging Face Spaces using a responsive, production-configured Gradio instance utilizing multi-threaded parallel execution protocols.


📖 Project Overview

Farm Friend is a localized, transparent "Glass Box" Machine Learning system designed to optimize macro-level agricultural choices across India. By integrating a high-accuracy regression engine with explicit Government of India Minimum Support Price (MSP) benchmarks and localized Explainable AI (XAI), the framework converts dense soil, climate, and input metrics into actionable, transparent, and multi-lingual visual insights.


Farm Friend Architectural Pipeline Flowchart
Figure 1: Full Architecture Pipeline from user UI interaction layers down to granular XAI calculation engines.


🚀 Our Journey: The Story of a Glass Box Model

Real-world AI cannot exist as an uninterpretable "Black Box" when dealing with human livelihoods like smallholder farming. Our platform evolved systematically from raw accuracy targeting to full, real-time explainability.

V1: The High-Variance Black Box - A Trust Barrier
Our first iteration focused entirely on high-dimensional model tuning. We achieved an excellent accuracy score, but the system couldn't explain *why* it made its decisions. Farmers and agricultural extension officers had no reason to trust its outputs.

💡 **Lesson Learned:** Predictive accuracy without structural explainability creates a fundamental trust gap in real-world deployment.
V2: The Lagging Oracle - The Integration Bottleneck
We integrated SHAP (Shapley Additive Explanations) to calculate localized individual feature impacts. However, calling the tree-explainer dynamically during runtime created massive lag, forcing users to wait over 8 seconds for a single form submission.

💡 **Lesson Learned:** Naive feature attribution calculations completely break UI/UX fluidity. Localized explainer pipelines must be mathematically cached or globally initialized.
V3: The Unified Advisor - Real-Time Glass Box
Our final system resolved all execution and usability bottlenecks to create a production-grade advisory engine:
  • Global SHAP Optimization: We optimized the system by pre-computing and initializing the TreeExplainer globally on app launch, cutting user response latency down from 8,000ms to <200ms.
  • Trilingual Reverse Mapping: We implemented an implicit backend translation schema to support English, Hindi (हिंदी), and Odia (ଓଡ଼ିଆ) natively, without breaking categorical encoded inputs.
  • Robust Validation Strategy: Evaluated generalization using an 80/20 random-seeded train/test allocation cross-verified against an extensive 5-Fold grid validation layout.

Data split strategy map


The Result: A reliable, split-second, transparent advisor that matches elite machine learning metrics with local community accessibility.


✨ Key Features

  • Explainable AI Engine: Leverages SHAP localized attribution to explain the exact structural impact (+/- metric tonnes) of individual environmental inputs.
  • Economic Intelligence: Integrates official Government of India MSP benchmarks (2023-24) to calculate localized total revenue directly via: $$\text{Income} = \text{Predicted Yield (t/ha)} \times \text{Area (ha)} \times 10 \times \text{MSP (₹/quintal)}$$
  • Trilingual Localization: A fully interactive, reactive user interface adapting layout labels cleanly across English, Hindi, and Odia.
  • Data-Driven Feature Alignment: Dynamically builds, fills, and drops category one-hot matrices via an exported template to avoid silent prediction crashes.

🛠️ Tech Stack

Python Scikit-Learn Gradio SHAP Pandas Joblib

📊 Results & Evaluation

Our validation study benchmarked four leading ensemble architectures across 19,295 historical records. The Random Forest Regressor demonstrated superior stability against climate anomalies:

Model Architecture $R^2$ Score RMSE (t/ha)
🌲 Random Forest (Selected) 0.9558 2.1952
🐱 CatBoost Regressor 0.9365 2.6334
🚀 XGBoost 0.9249 2.8621
⚡ LightGBM 0.9051 3.2174

Benchmarking bar plots metrics charts

Balanced Metrics Multi-Axis Breakdown

To track trade-offs across speed, training resource efficiency, and residual variance constraints, a comparative multidimensional index map was constructed:

Radar multi-axis performance chart

Granular Feature Impact Calculations

Using the globally initialized interpretability engine, localized weight effects are mapped explicitly during validation checkpoints to isolate key performance indicators:

SHAP local feature waterfall chart


Application Interface Deployment Previews

Trilingual User Interface Layout
Farm Friend Dashboard Attribute Fields

Real-Time XAI Explanations & Financial Outputs
Inference Pipeline Output Performance View


🚀 Getting Started

Click here for instructions to run this project yourself locally.
  1. Clone the Repository

    git clone [https://github.com/Ritviks21/F2-Farm-Friend-.git](https://github.com/Ritviks21/F2-Farm-Friend-.git)
    cd F2-Farm-Friend-
  2. Install Dependencies

    pip install -r requirements.txt
  3. Train the Production Model

    python src/train.py
  4. Launch the Local Web App

    python src/app.py

🤝 How to Contribute

Contributions are highly welcome! This platform is designed as an expanding tool for open-source digital agriculture systems. If you would like to expand its functionality, feel free to fork the repository and submit a Pull Request.

Primary Areas for System Enhancement

  • Expand Regional Datasets:

    • Integrate micro-level district data for Southern and Eastern coastal zones.
    • Add additional crop varieties (e.g., specific commercial spices, rubber, plantation crops) to the backend encoding script.
  • Incorporate Deep Regressors:

    • Experiment with multi-layer neural networks or localized deep tabular models to further minimize residual RMSE variance thresholds below $2.19$.
    • Expand hyperparameter sweeps utilizing automated frameworks like Optuna.
  • Enhance the UI Framework:

    • Introduce comparative visualizations (e.g., dynamic bar graphs or map charts) rendering right within the Gradio user interface layout.

🔗 Connect with Me

Your Github Your Twitter Your Hugging Face Your LinkedIn

About

An end-to-end Explainable AI (XAI) platform for Indian agriculture. Uses a Random Forest Regressor (R^2 = 0.9558) to deliver crop yield predictions, MSP-based revenue forecasting, and global SHAP breakdowns across a trilingual interface (English, Hindi, Odia).

Topics

Resources

License

Stars

Watchers

Forks

Contributors