I am deploying my machine learning model locally and use flask for that. I have my main.html and app.py but when I try to run it in the console I get the Error message above.
I cannot find any "&" in both files which is why I cannot solve the problem.
I checked all files but could not find a char like "&" and the debug mode just raises the error which I mentioned.
This is the html form:
<!doctype html>
<html>
<style>
form {
margin: auto;
width: 35;
}
.result {
margin: auto;
width: 35;
border: 1px solid
}
</style>
<head>
<title>Sales Prediction</title>
</head>
<form action="{{url_for('main')}}" method="POST">
<fieldset>
<legend>Input values:</legend>
Week:
<input name="week" type="number" required>
<br>
<br> Grad:
<input name="grad" type="number" required>
<br>
<br> Preis:
<input name="preis" type="number" required>
<br>
<br>
<input type="submit">
</fieldset>
</form>
<br>
<div class="result" align="center">
{%if result%}
{%for variable, value in original_input.items()%}
<b>{{variable}}</b> : {{value}}
{%endfor%}
<br>
<br> Predicted number of sales :
<p style="font-size:50px">{{result}}</p>
{%endif%}
</div>
</html>
and this is the app.py:
import flask
import pickle
import pandas as pd
with open('model/model.pkl', 'rb') as f:
model = pickle.load(f)
app = flask.Flask(__name__, template_folder='templates')
@app.route('/', methods=['GET', 'POST'])
def main():
if flask.request.method == 'GET':
return(flask.render_template('main.html'))
if flask.request.method == 'POST':
week = flask.request.form['week']
grad = flask.request.form['grad']
preis = flask.request.form['preis']
input_variables = pd.DataFrame([[week, grad, preis]],
columns=['week', 'grad', 'preis'],
dtype=float)
prediction = model.predict(input_variables)[0]
return flask.render_template('main.html',
original_input={'week':week,
'grad':grad,
'preis':preis},
result=prediction,
)
if __name__ == '__main__':
app.debug = True
app.run(host = '0.0.0.0', port = 5000)
As soon as I run it in the console I get
jinja2.exceptions.TemplateSyntaxError: unexpected char '&' at 250601