|
|
from flask import Flask, render_template, request |
|
|
from tensorflow.keras.models import load_model |
|
|
from tensorflow.keras.preprocessing import image |
|
|
import numpy as np |
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
dic = {0 : 'happy', 2 : 'angry',1 : 'sad'} |
|
|
|
|
|
model = load_model('model.h5') |
|
|
|
|
|
model.make_predict_function() |
|
|
|
|
|
def predict_label(img_path): |
|
|
i = image.load_img(img_path, target_size=(100, 120)) |
|
|
i = image.img_to_array(i) / 255.0 |
|
|
i = i.reshape(1, 100, 120, 3) |
|
|
pred = model.predict(i) |
|
|
p = np.argmax(pred, axis=1) |
|
|
return dic[p[0]] |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/", methods=['GET', 'POST']) |
|
|
def main(): |
|
|
return render_template("app.html") |
|
|
|
|
|
@app.route("/about") |
|
|
def about_page(): |
|
|
return "Please subscribe Artificial Intelligence Hub..!!!" |
|
|
|
|
|
@app.route("/submit", methods = ['GET', 'POST']) |
|
|
def get_output(): |
|
|
if request.method == 'POST': |
|
|
img = request.files['my_image'] |
|
|
|
|
|
img_path = "static/" + img.filename |
|
|
img.save(img_path) |
|
|
|
|
|
p = predict_label(img_path) |
|
|
|
|
|
return render_template("app.html", prediction = p, img_path = img_path) |
|
|
|
|
|
|
|
|
if __name__ =='__main__': |
|
|
|
|
|
app.run(debug = True) |