Updated web application

parent 84890685
This diff is collapsed.
import os
from flask import Flask, request, redirect, url_for, send_from_directory, render_template
from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
from keras.models import Sequential, load_model
from werkzeug.utils import secure_filename
import numpy as np
ALLOWED_EXTENSIONS = set(['jpg', 'jpeg', 'png', 'JPG'])
IMAGE_SIZE = (224, 224)
UPLOAD_FOLDER = 'static'
img2 = load_model('model/diseases_model3.h5')
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
def predict(file):
img = load_img(file, target_size=IMAGE_SIZE)
img = img_to_array(img)/255.0
img = np.expand_dims(img, axis=0)
probs = img2.predict(img)[0]
output = {'Healthy' : probs[0],'Sigatoka': probs[1]}
return output
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/")
def template_test():
return render_template('index.html', label='', imagesource='file://null')
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(file_path)
output = predict(file_path)
return render_template("disease.html", label=output, imagesource=file_path)
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
if __name__ == "__main__":
app.run(debug=False, threaded=False)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{url_for('static',filename='bootstrap.min.css')}}">
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css"
/>
<link
href="https://api.mapbox.com/mapbox-gl-js/v2.1.1/mapbox-gl.css"
rel="stylesheet"
/>
<link rel="stylesheet" href="/public/css/style.css" />
<title>OrgiCheck</title>
<title>Disease Recognition Server</title>
<body class style="margin:10px;padding:10px">
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-8 col-md-7 col-sm-6">
<h3>Disease Recognition System</h3>
</div>
</div>
<!-- <form action="" method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
-->
</div>
<p style="margin-bottom:2cm;"></p>
<div class="row">
<div class="col-lg-4">
<div class="page-header">
<h3 id="tables">Result</h3>
</div>
<div class="bs-component">
<table class="table table-hover">
<tr class="table-active">
<!-- <th scope="col">Image</th> -->
<th scope="col">Predict</th>
</tr>
<tr>
{% if label %}
<th scope="row"> <img width="224" height="224" src="{{imagesource}}" /> </th>
</tr>
<tr>
<td> Prediction : <i> {{label }}</i></td>
{% endif %}
</tr>
</table>
</div>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<!-- Footer -->
<footer class="p-5 bg-dark text-white text-center position-relative">
<div class="container">
<p class="lead">Copyright &copy; 2021 OrgiCheck</p>
<a href="#" class="position-absolute bottom-0 end-0 p-5">
<i class="bi bi-arrow-up-circle h1"></i>
</a>
</div>
</footer>
</body>
\ No newline at end of file
This diff is collapsed.
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