repliqué el ejemplo de flask machine learning model en web de Farhad Malik y me funciono bien pero al intentar incluir librerías en las plantillas HTML me sale el error jinja2.exceptions.UndefinedError: 'pandas' is undefined, quisiera saber si alguien sabe cuál es el problema.
Este es mi .py principal
from flask import Flask, render_template, request, redirect, url_for
from sklearn.externals import joblib
import pandas as pd
import numpy as np
app = Flask('stoke_pricer')
@app.route('/')
def show_predict_stock_form():
return render_template('predictorform.html')
@app.route('/resultsform', methods=['POST', 'GET'])
def results():
form = request.form
if request.method == 'POST':
model = joblib.load('ML1Obesidad_RF.pkl')
inp = pd.DataFrame(columns=['euexfreq', 'eustreason', 'eugenhth', 'ertseat', 'eufastfdfrq'])
[...]
predicted_stock_price = model.predict_proba(inp)[0][1]
return render_template('resultsform.html', inp=inp, predicted_price=predicted_stock_price)
else:
return render_template('resultsform.html', predicted_price=request.method)
app.run("localhost", "9999", debug=True)
y este es el HTML
<!doctype html>
<html>
<head>
<title>Resultados</title>
</head>
<body>
<h3>Inputs:</h3>
<div>
{% import pandas as pd %}
{% print(pd.DataFrame.transpose(inp)) %}
</div>
<h3>Salida:</h3>
<div>Probabilidad de padecer obesidad<strong>{% print(": {:.2f}".format(predicted_price*100)) %}% </strong> </div>
</body>
</html>