This is a Django-based web application for analyzing soil data, predicting soil quality, and providing AI-driven crop suggestions. It features a user-friendly interface with a file upload system, interactive visualizations, and a chatbot powered by a reinforcement learning (RL) agent.
- Soil Quality Prediction: Uses a Random Forest Classifier to predict soil grade (0-2) based on nutrient levels (N, P, K, pH, moisture) from uploaded CSV files.
- Interactive Visualizations: Displays nutrient levels as bar charts using Plotly.
- AI Suggestions: Provides initial rule-based suggestions and adaptive crop recommendations via a Q-learning RL agent.
- Chatbot: A popup chatbot on the right side, offering real-time assistance for soil and crop queries.
- File Upload: Allows users to upload CSV files for analysis, with results displayed on a dedicated page.
- Python: 3.10.12
- Django: 5.0.4
- pandas:
- numpy:
- scikit-learn
- matplotlib:
- plotly:
- Clone the Repository:
git clone https://github.com/alexander784/Soil_Analysis.git cd soil_analysis
- Set Up a Virtual Environment:
python3 -m venv venv source venv/bin/activate
- Install Dependencies:
pip install -r requirements.txt
- Apply Migrations:
python3 manage.py makemigrations python3 manage.py migrate
- Run dev server:
python3 manage.py runserver
- Upload soil Data:
- Visit the homepage (/) to access the upload page.
- Upload a CSV file with columns: N, P, K, pH, moisture.
- Example CSV format:
N,P,K,pH,moisture 75,45,120,6.5,50
- View Results
- After uploading, you’ll be redirected to the results page showing:
- Soil grade
- A bar chart of nutrient levels.
- AI suggestions (rule-based and RL-agent-driven).
- Interact with the Chatbot
- A popup chatbot appears on the right side.
- Ask questions like "nitrogen" or "crop" to get responses based on the latest analysis.
- Analyze Another Sample
- Click "Analyze Another Sample" to return to the upload page.
Soil Prediction
- Uses
RandomForestClassifier
fromscikit-learn
with synthetic labels based on nutrient thresholds. - Trained on-the-fly with each upload (no pre-trained model).
RL Agent
- Implements Q-learning in utils.py (SoilAgent class).
- States: Soil grade and nitrogen range.
- Actions: Crop recommendations (e.g., wheat, corn).
- Add CSV input validation and error messages.
- Implement real user feedback for the RL agent.
- Enhance chatbot with NLP (e.g., integrate a model like BERT).
Feel free to fork this repository, submit issues, or create pull requests. Contributions are welcome!