Commit 423cd88b authored by Kareshaan Logeswaran's avatar Kareshaan Logeswaran

created It20229948 back end

parent 3568634c
import joblib
from flask import Flask,request,render_template
import numpy as np
import pickle
# # Load your machine learning model
model = joblib.load('finalmodel.joblib')
# importing model
#model = pickle.load(open('finalmodel.pkl','rb'))
sc = pickle.load(open('standscaler.pkl', 'rb'))
ms = pickle.load(open('minmaxscaler.pkl', 'rb'))
# creating flask app
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
@app.route("/predict",methods=['POST'])
def predict():
N = request.form['Nitrogen']
P = request.form['Phosporus']
K = request.form['Potassium']
temp = request.form['Temperature']
humidity = request.form['Humidity']
ph = request.form['Ph']
feature_list = [N, P, K, temp, humidity, ph]
single_pred = np.array(feature_list).reshape(1, -1)
scaled_features = ms.transform(single_pred)
final_features = sc.transform(scaled_features)
prediction = model.predict(final_features)
crop_dict = {
1: "AT 354",
2: "BG 250",
3: "BG 352",
4: 'Mottaikaruppan',
5: 'Suwandel'
}
if prediction[0] in crop_dict:
crop = crop_dict[prediction[0]]
result = "{} is the best crop to be cultivated right there".format(crop)
else:
result = "Sorry, we could not determine the best crop to be cultivated with the provided data."
return render_template('index.html',result = result)
# python main
if __name__ == "__main__":
app.run(debug=True)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment