Disease recognition model deploy with Flask

parent b482a890
This diff is collapsed.
from flask import Flask , render_template, request
from keras.models import load_model
from tensorflow import keras
from keras.preprocessing import image
import numpy as np
app = Flask(__name__)
dic = {0 : 'Healthy', 1 : 'Sigatoka'}
model = load_model('diseases_model.h5')
model.make_predict_function()
def predict_label(img_path):
i = image.load_img(img_path, target_size = (100,100))
i = image.img_to_array(i)/255.0
i = i.reshape(1, 100, 100, 3)
#p = model.predict_classes(i)
predict_x=model.predict(i)
p=np.argmax(predict_x,axis=1)
return dic[p[0]]
@app.route("/", methods=['GET', 'POST'])
def home():
return render_template("index.html")
@app.route("/submit", methods = ['GET', 'POST'])
def predict():
if request.method == 'POST':
img = request.files['my_image']
img_path = "images/" + img.filename
img.save(img_path)
p = predict_label(img_path)
return render_template("index.html", prediction = p, img_path = img_path)
if __name__ == "__main__":
app.run(debug=True)
# @app.route("/sub", methods = ["POST"])
# def submit():
# if request.method == "POST":
# name = request.form["username"]
# return render_template("sub.html" , n = name )
<!doctype html>
<html lang="en">
<head>
<title>Image Classification</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<h1>Plant quality prediction</h1>
<br><br>
<form action="/submit" method="post" enctype="multipart/form-data">
<div >
<label for="pwd">Upload Your Image :</label>
<div>
<input type="file" placeholder="Hours Studied" name="my_image" id="pwd">
</div>
</div>
<div >
<div >
<button type="submit" >Submit</button>
</div>
</div>
</form>
{% if prediction %}
<img src="{{img_path}}" height="400px" width="400px">
<h2> Your Prediction : <i> {{prediction}} </i></h2>
{% endif %}
</div>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>submit page</title>
</head>
<body>
<h4>{{ n }}</h4>
</body>
</html>
\ 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