Upload 8 files
Browse files- Procfile +1 -0
- README.md +22 -0
- application.py +47 -0
- minmaxscaler.pkl +3 -0
- model.pkl +3 -0
- requirements.txt +29 -0
- runtime.txt +1 -0
- standscaler.pkl +3 -0
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: gunicorn -w 4 -b 0.0.0.0:$PORT application:application
|
README.md
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Crop Recommendation API
|
2 |
+
|
3 |
+
This project implements a crop recommendation system using a Random Forest classifier with an accuracy of 99.18%. It is deployed and accessible at [cropok-production.up.railway.api](https://cropok-production.up.railway.app).
|
4 |
+
|
5 |
+
Now, URL is not working because free trial limit is exceeded.
|
6 |
+
|
7 |
+
## Features
|
8 |
+
|
9 |
+
- Utilizes Random Forest algorithm for accurate crop recommendations.
|
10 |
+
- Converts the model into a Flask API for easy integration.
|
11 |
+
|
12 |
+
## Input Parameters
|
13 |
+
- Nitrogen
|
14 |
+
- Phosphorus
|
15 |
+
- Potassium
|
16 |
+
- Temperature
|
17 |
+
- Humidity
|
18 |
+
- Ph
|
19 |
+
|
20 |
+
## Note
|
21 |
+
|
22 |
+
The API is currently not working due to the free trial limit being exceeded. You are free to deploy and use it in your own environment.
|
application.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import numpy as np
|
3 |
+
import sklearn
|
4 |
+
import pickle
|
5 |
+
|
6 |
+
model = pickle.load(open('model.pkl', 'rb'))
|
7 |
+
sc = pickle.load(open('standscaler.pkl', 'rb'))
|
8 |
+
ms = pickle.load(open('minmaxscaler.pkl', 'rb'))
|
9 |
+
application = Flask(__name__)
|
10 |
+
|
11 |
+
@application.route('/')
|
12 |
+
def ok():
|
13 |
+
return "Running!"
|
14 |
+
|
15 |
+
@application.route('/pred', methods=['POST'])
|
16 |
+
def predict():
|
17 |
+
N = request.form['Nitrogen']
|
18 |
+
P = request.form['Phosphorus']
|
19 |
+
K = request.form['Potassium']
|
20 |
+
temp = request.form['Temperature']
|
21 |
+
humidity = request.form['Humidity']
|
22 |
+
ph = request.form['Ph']
|
23 |
+
rainfall = request.form['Rainfall']
|
24 |
+
|
25 |
+
feature_list = [N, P, K, temp, humidity, ph, rainfall]
|
26 |
+
single_pred = np.array(feature_list).reshape(1, -1)
|
27 |
+
|
28 |
+
scaled_features = ms.transform(single_pred)
|
29 |
+
final_features = sc.transform(scaled_features)
|
30 |
+
prediction = model.predict(final_features)
|
31 |
+
|
32 |
+
crop_dict = {1: "Rice", 2: "Maize", 3: "Jute", 4: "Cotton", 5: "Coconut", 6: "Papaya", 7: "Orange",
|
33 |
+
8: "Apple", 9: "Muskmelon", 10: "Watermelon", 11: "Grapes", 12: "Mango", 13: "Banana",
|
34 |
+
14: "Pomegranate", 15: "Lentil", 16: "Blackgram", 17: "Mungbean", 18: "Mothbeans",
|
35 |
+
19: "Pigeonpeas", 20: "Kidneybeans", 21: "Chickpea", 22: "Coffee"}
|
36 |
+
|
37 |
+
|
38 |
+
if prediction[0] in crop_dict:
|
39 |
+
crop = crop_dict[prediction[0]]
|
40 |
+
else:
|
41 |
+
crop = 'NOT able to recommend'
|
42 |
+
return jsonify(crop)
|
43 |
+
|
44 |
+
|
45 |
+
# python main
|
46 |
+
if __name__ == "__main__":
|
47 |
+
application.run(host='0.0.0.0', port=5000, debug=True)
|
minmaxscaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:509dcc63a697ff54794ab75b34cf7b021437682b192b93b2e19e28f61c60ab16
|
3 |
+
size 760
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e6fb0624dbcc05f5e1fd35f1a5ed6f0e2e15756fe2794584dc32b86ad124eba5
|
3 |
+
size 3502048
|
requirements.txt
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
annotated-types
|
2 |
+
anyio
|
3 |
+
blinker
|
4 |
+
click
|
5 |
+
colorama
|
6 |
+
fastapi
|
7 |
+
Flask
|
8 |
+
gunicorn
|
9 |
+
h11
|
10 |
+
idna
|
11 |
+
itsdangerous
|
12 |
+
Jinja2
|
13 |
+
joblib==1.3.0
|
14 |
+
MarkupSafe
|
15 |
+
nltk
|
16 |
+
numpy
|
17 |
+
pydantic
|
18 |
+
pydantic_core
|
19 |
+
regex
|
20 |
+
scikit-learn==1.3.0
|
21 |
+
scipy
|
22 |
+
sniffio
|
23 |
+
starlette
|
24 |
+
textblob
|
25 |
+
threadpoolctl
|
26 |
+
tqdm
|
27 |
+
typing_extensions
|
28 |
+
uvicorn
|
29 |
+
Werkzeug
|
runtime.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python-3.11.*
|
standscaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:639511bb6e216cf1f1748fa54f40483be288875502bdf19ac9b98891f2d242b1
|
3 |
+
size 617
|