I've been working on a Machine learning model for my college project lately. I've already written a keras model and saved it as hdf5 format. I've checked it running locally the saved model makes fine prediction. I want to run this model via a web application, hence I've been working on flask for the past couple of days. I've written code for flask app.py and index.html
app.py
from flask import Flask, render_template, request
from flask import request
import numpy as np
from keras.models import load_model
from sklearn.preprocessing import MinMaxScaler
from flask import jsonify
import os
import re
import sys
# init model directory
MODEL_DIR = './models'
result=''
#init Flask
app = Flask(__name__)
#load the compiled model.
print("Loading model")
model = load_model(os.path.join(MODEL_DIR, 'classifier_model.hdf5'))
scaler= MinMaxScaler(feature_range=(0,1))
#routing for home page
@app.route('/', methods=['GET','POST'])
def index():
if request.method == 'GET':
return render_template('index.html')
if request.method == 'POST':
weight=float(request.form('weight'))
height=float(request.form('height'))
gluc=float(request.form('glucose'))
bp=float(request.form('bp'))
age=float(request.form('age'))
height=height/100
bmi=weight/(height*height)
predict_data=np.array([[gluc, bp, bmi, age],[103,80,19.4,22]])
scaled_predict_data=scaler.fit_transform((predict_data))
round_predict =
model.predict_classes(scaled_predict_data,verbose=0)
res=np.array_str(round_predict[0])
return render_template('index.html', value=res)
if __name__ == '__main__':
port= int(os.environ.get('PORT',8080))
app.run(host='0.0.0.0', port=port,debug=True)
index.html
<html>
<head>
<script >
var value=
</script>
</head>>
<body>
<form method = "POST">
<p>Weight <input type = "number" name = "weight" /></p>
<p>Height(CM) <input type = "number" name = "height" /></p>
<p>Glucose(mg/dL) <input type = "number" name = "glucose" /></p>
<p>Blood Pressure <input type ="number" name = "bp" /></p>
<p>Age <input type ="number" name = "age" /></p>
<p><input type = "submit" value = "submit" /></p><br>
Output: <br>
</form>
</body>
</html>
Now when I run the app.py code, everything runs fine and index.html is rendered but when I hit the submit button I get this error message: TypeError: 'ImmutableMultiDict' object is not callable
Any help would be highly appreciated. This is my college project and the submission date has already passed. Please Help. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire