Spaces:
Sleeping
Sleeping
shubham5027
commited on
Commit
·
b60b805
verified
·
0
Parent(s):
initial commit
Browse files- .gitattributes +35 -0
- README.md +14 -0
- app.py +85 -0
- requirements.txt +1 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: KisanAI
|
3 |
+
emoji: 😻
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.12.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
short_description: ML based prediction system
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Load the RandomForest model
|
7 |
+
working_dir = os.path.dirname(os.path.abspath(__file__))
|
8 |
+
model = pickle.load(open(f'{working_dir}/RF_Crop.sav', 'rb'))
|
9 |
+
|
10 |
+
# Overview section content
|
11 |
+
overview_text = """
|
12 |
+
### Welcome to the Crop Recommendation App!
|
13 |
+
|
14 |
+
This application assists farmers in selecting the optimal crop to cultivate, considering soil composition
|
15 |
+
and environmental conditions. By providing information such as nitrogen, phosphorus, and
|
16 |
+
potassium levels, as well as temperature, humidity, pH, and rainfall, users receive tailored
|
17 |
+
recommendations for the most suitable crop out of a selection of 22 options.
|
18 |
+
|
19 |
+
### How to Use the App
|
20 |
+
1. Navigate to the "Crop Recommendation" section.
|
21 |
+
2. Enter the values for the soil and environmental factors in the input fields.
|
22 |
+
3. Click the "Predict" button to get the crop recommendation.
|
23 |
+
|
24 |
+
### About the Model
|
25 |
+
The recommendation is made using a Random Forest model trained on agricultural data.
|
26 |
+
This model considers various factors to predict the best crop for your field.
|
27 |
+
The model has been developed by analyzing many models like SVM, Random Forest,
|
28 |
+
Decision Tree, Logistic Regression, Gaussian Naive Bayes. Random Forest has been selected based on
|
29 |
+
the Cross Validation Accuracy & Test Accuracy.
|
30 |
+
|
31 |
+
### Benefits of Using Crop Recommendation
|
32 |
+
- **Increased Yield**: By planting the most suitable crop, you can maximize your harvest.
|
33 |
+
- **Cost Efficiency**: Avoid wasting resources on crops that are not suited to your soil and climate.
|
34 |
+
- **Sustainable Farming**: Promote better land use and reduce environmental impact.
|
35 |
+
|
36 |
+
### Contact Us
|
37 |
+
If you have any questions or feedback about the project, feel free to reach out:
|
38 |
+
- **Email**: kanchanrai2307@gmail.com
|
39 |
+
- **Github**: [kanchanrai7](https://github.com/kanchanrai7)
|
40 |
+
"""
|
41 |
+
|
42 |
+
# Define the prediction function
|
43 |
+
def predict_crop(N, P, K, temperature, humidity, pH, rainfall):
|
44 |
+
user_input = np.array([[N, P, K, temperature, humidity, pH, rainfall]])
|
45 |
+
if np.all(user_input == 0):
|
46 |
+
return "Please enter valid values."
|
47 |
+
else:
|
48 |
+
prediction = model.predict(user_input)
|
49 |
+
crop = prediction[0]
|
50 |
+
return f"Hey, you should grow **{crop}** based on your soil and environmental factors."
|
51 |
+
|
52 |
+
# Gradio UI components
|
53 |
+
def main_interface():
|
54 |
+
with gr.Blocks() as demo:
|
55 |
+
with gr.Tab("Overview"):
|
56 |
+
gr.Markdown(overview_text)
|
57 |
+
gr.Image("Images/image1.jpg", label="Healthy Crops")
|
58 |
+
gr.Image("Images/mod_comparison.png", label="Model Comparison")
|
59 |
+
|
60 |
+
with gr.Tab("Get Recommendation"):
|
61 |
+
gr.Markdown("Enter the details about your soil and environmental factors to get a crop recommendation.")
|
62 |
+
gr.Markdown("**Example Values:** [104, 18, 30, 23.6, 60.3, 6.7, 140.91] or [60, 18, 30, 23.6, 60.3, 8, 40.91]")
|
63 |
+
|
64 |
+
N = gr.Number(label="Nitrogen (N)", value=0, precision=0)
|
65 |
+
P = gr.Number(label="Phosphorus (P)", value=0, precision=0)
|
66 |
+
K = gr.Number(label="Potassium (K)", value=0, precision=0)
|
67 |
+
temperature = gr.Number(label="Temperature (°C)", value=0.0)
|
68 |
+
humidity = gr.Number(label="Humidity (%)", value=0.0)
|
69 |
+
pH = gr.Number(label="pH", value=0.0)
|
70 |
+
rainfall = gr.Number(label="Rainfall (mm)", value=0.0)
|
71 |
+
|
72 |
+
output = gr.Textbox(label="Recommendation", interactive=False)
|
73 |
+
|
74 |
+
gr.Button("Predict").click(
|
75 |
+
predict_crop,
|
76 |
+
inputs=[N, P, K, temperature, humidity, pH, rainfall],
|
77 |
+
outputs=output
|
78 |
+
)
|
79 |
+
|
80 |
+
return demo
|
81 |
+
|
82 |
+
# Run the Gradio app
|
83 |
+
if __name__ == "__main__":
|
84 |
+
app = main_interface()
|
85 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
scikit-learn==1.2.2
|