- Jupyter Notebook 99.1%
- Python 0.9%
| backend | ||
| frontend | ||
| .gitignore | ||
| compose.yml | ||
| README.md | ||
🌾 Crop Yield Prediction System
An AI-powered software to predict the yield of different crops based on weather and soil conditions.
📖 Overview
This project is an advanced AI-powered application designed to assist farmers and agricultural professionals in making informed decisions by accurately predicting crop yields. By leveraging machine learning models, it analyzes various environmental factors such as weather patterns and soil conditions to forecast the expected harvest. The system comprises a user-friendly web interface (frontend) for inputting data and visualizing results, backed by a robust API (backend) that houses the predictive AI model. The entire application is containerized with Docker, ensuring easy setup, scalability, and consistent deployment across different environments.
✨ Features
- 🎯 AI-Powered Crop Yield Prediction: Utilizes advanced machine learning models to provide accurate yield forecasts.
- 🧑💻 Intuitive Web Interface: A user-friendly frontend allows for easy input of weather and soil data.
- 📊 Data-Driven Insights: Provides predictions based on comprehensive analysis of environmental conditions.
- 🌐 API-Driven Backend: A dedicated backend service exposes prediction capabilities via a RESTful API.
- 🐳 Containerized Deployment: Entire application packaged with Docker and orchestrated via Docker Compose for seamless setup and portability.
- ⚙️ Modular Architecture: Separate frontend and backend services facilitate independent development and maintenance.
🖥️ Screenshots
🛠️ Tech Stack
Frontend:
Backend (AI/ML & API):
DevOps & Containerization:
Database:
🚀 Quick Start
Follow these steps to get the Crop Yield Prediction system up and running on your local machine.
Prerequisites
Before you begin, ensure you have the following installed:
- Git: For cloning the repository.
- Docker: For containerizing the application services.
- Docker Compose: For orchestrating the multi-container application.
Installation
-
Clone the repository
git clone https://github.com/shrishjay/Crop-Yeild-Prediction.git cd Crop-Yeild-Prediction -
Build and start the services The
compose.ymlfile will build the necessary Docker images and start both the frontend and backend services.docker compose up --buildThis command will:
- Build the Docker image for the
frontendservice. - Build the Docker image for the
backend(AI/ML) service. - Start both services, making them accessible on their configured ports.
- Build the Docker image for the
-
Environment setup (if applicable for specific services) Individual services (frontend/backend) might require
.envfiles for configuration, usually based on an.env.examplefile within their respective directories.# Example for backend service, if it has .env.example cp backend/.env.example backend/.env # Configure variables inside backend/.env # Example for frontend service, if it has .env.example cp frontend/.env.example frontend/.env # Configure variables inside frontend/.envNote: The
compose.ymlmight also pass environment variables directly to containers, reducing the need for.envfiles in some cases. -
Database setup (if applicable) If a database service is included or configured by
compose.yml, it will be set up automatically. For manual database migrations or setup, you might need to execute commands within the backend container.# Example: Running migrations in the backend container # docker compose exec backend python manage.py migrate -
Open your browser Once the services are up, the frontend application should be accessible. Visit
http://localhost:[detected_frontend_port](e.g.,http://localhost:3000orhttp://localhost:80).
📁 Project Structure
Crop-Yeild-Prediction/
├── .gitignore # Specifies intentionally untracked files to ignore
├── backend/ # Contains the Python backend code and AI/ML models
│ ├── Dockerfile # Dockerfile for building the backend service image
│ ├── requirements.txt# Python dependencies
│ ├── main.py # Main entry point for the backend API
│ └── models/ # Directory for trained ML models, if applicable
├── compose.yml # Docker Compose configuration file for multi-service setup
└── frontend/ # Contains the web application's frontend code
├── Dockerfile # Dockerfile for building the frontend service image
├── package.json # Frontend dependencies and scripts (for Node.js ecosystem)
├── src/ # Source code for the frontend application
└── public/ # Static assets for the frontend
⚙️ Configuration
Environment Variables
Both frontend and backend services might rely on environment variables for sensitive data (API keys, database credentials) or configuration settings.
| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| FRONTEND_API_URL | Base URL for the backend API from the frontend. | http://backend:5000 | Yes |
| BACKEND_PORT | Port on which the backend service listens. | 5000 | Yes |
| DATABASE_URL | Connection string for the database. | sqlite:///db.sqlite | No |
| API_KEY | Example API key for external services. | None | No |
Configuration Files
compose.yml: Defines the services, networks, and volumes for the Dockerized application.backend/Dockerfile: Instructions for building the backend Docker image.frontend/Dockerfile: Instructions for building the frontend Docker image.backend/requirements.txt: Lists Python dependencies for the backend.frontend/package.json: Lists Node.js dependencies and scripts for the frontend.
🔧 Development
For focused development on individual services outside of the full Docker Compose setup, you can follow these general steps:
Backend Development (Python)
- Navigate into the
backenddirectory:cd backend - Install Python dependencies:
pip install -r requirements.txt - Run the backend development server:
python main.py(or similar command depending on the framework, e.g.,flask runoruvicorn main:app --reload).
Frontend Development (JavaScript Framework)
- Navigate into the
frontenddirectory:cd frontend - Install Node.js dependencies:
npm install(oryarn install,pnpm install) - Start the frontend development server:
npm run dev(oryarn dev,pnpm dev,npm start).
Available Scripts (within package.json for frontend, Makefile or similar for backend)
| Command (Frontend) | Description |
|--------------------|-------------|
| npm run dev | Starts the development server with hot-reloading. |
| npm run build | Compiles the application for production deployment. |
| npm test | Runs unit and integration tests. |
🧪 Testing
To run tests for the application:
# Example: Run backend tests
docker compose exec backend pytest
# Example: Run frontend tests
docker compose exec frontend npm test
Note: Specific test commands depend on the testing frameworks configured within the backend and frontend services.
🚀 Deployment
The compose.yml file is designed for both local development and can serve as a foundation for production deployments.
Production Build
To create optimized production builds for the individual services:
# Example for frontend (run from within the frontend container or local setup)
cd frontend
npm run build
# Example for backend (Docker build is typically optimized by default)
Deployment Options
- Docker Compose: The provided
compose.ymlcan be used to deploy the application on a single server with Docker. - Container Orchestration: For larger-scale deployments, the Docker images built by
docker compose buildcan be deployed to Kubernetes, AWS ECS, Google Cloud Run, or other container orchestration platforms.
📚 API Reference
The backend service provides a RESTful API for interacting with the crop yield prediction model.
Base URL
http://localhost:[backend_port]/api/v1
Endpoints
POST /predict
Submits weather and soil data to get a crop yield prediction.
Parameters:
| Name | Type | Description | Required |
|------|------|-------------|----------|
| temperature | number | Average temperature in Celsius. | Yes |
| humidity | number | Average relative humidity in percentage. | Yes |
| rainfall | number | Total rainfall in mm. | Yes |
| soil_type | string | Type of soil (e.g., "loamy", "sandy"). | Yes |
| crop_type | string | Type of crop for prediction. | Yes |
Example Request:
POST /predict
Content-Type: application/json
{
"temperature": 25.5,
"humidity": 70,
"rainfall": 1200,
"soil_type": "loamy",
"crop_type": "wheat"
}
Example Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"crop_type": "wheat",
"predicted_yield": 5.2,
"unit": "tons/hectare"
}
🤝 Contributing
We welcome contributions to enhance the Crop Yield Prediction System! Please follow these guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Implement your changes, ensuring they adhere to the project's coding standards.
- Write comprehensive tests for your changes.
- Commit your changes with clear, descriptive messages.
- Push your branch and open a Pull Request.
Please see our Contributing Guide for more detailed instructions.
Development Setup for Contributors
Ensure you have Docker and Docker Compose installed. You can run docker compose up --build to get the entire environment running. For individual service development, refer to the "Development" section above.
📄 License
This project is licensed under the LICENSE_NAME - see the LICENSE file for details.
🙏 Acknowledgments
- Built upon the powerful capabilities of Python and its machine learning ecosystem.
- Powered by modern web technologies for an interactive user experience.
- Containerized with Docker and Docker Compose for robust deployment.
- Inspired by the need for data-driven agriculture.
📞 Support & Contact
- 📧 Email: [contact@example.com]
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
⭐ Star this repo if you find it helpful!
Made with ❤️ by shrishjay