0

I am trying to deploy the variable "prediction" from FLASK to the cell with ID = prediction. The variable is correctly calculated in the app, I just cannot deploy & display it in the html table ... I would really appreciate if you could tell me how to proceed. I did the most difficult part with the model and now I cannot deploy it. Thanks in advance


import numpy as np
from flask import Flask, request, render_template
import pickle
import pandas as pd

app = Flask(__name__)
model = pickle.load(open('logreg.pkl', 'rb'))

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/predict',methods=['POST'])
def predict():

    int_features = [str(x) for x in request.form.values()]
    final_features = np.array(int_features)    
    
    df = pd.read_csv('list_last_update.csv') 
    home_team = df[df['Name']==final_features[0]]
    away_team = df[df['Name']==final_features[1]]

    
    X1 = np.array(home_team[['OVA', 'ATT']])
    
    X2 = np.array(away_team[['OVA', 'ATT']])
    
    X = np.concatenate((X1, X2), axis=None).astype(int)

    
    X = X.reshape(1, -1)
    
    
    prediction = model.predict(X)

   
    return render_template('index.html')
    
if __name__ == "__main__":
    app.run(host='0.0.0.0',port=8080)

``

<td>   
<div class="autocomplete" style="width:300px;">
<input id="away_team" type="text" name="team2" placeholder="Away Team" required="required" />
</div>
</td>

<button type="submit" class="btn btn-primary btn-block btn-large">Print team rates</button>

</form>


<td>   
<input id="prediction"  type="number" style="text-align:center"/>
</td>

<td>
<input id="draw_game_odd" type="number" style="text-align:center"/>
</td>

<td>
<input id="away_team_odd" type="number" style="text-align:center"/>
</td>
Miguel Gonzalez
  • 398
  • 1
  • 12

1 Answers1

1

You can pass the prediction variable to render_tempalte as kwarg

prediction = model.predict(X)

return render_template('index.html', prediction=prediction)

and then access/interpolate prediction inside HTML file. e.g

<div>
    {{ prediction }}
</div

Checkout jinja docs on how to interpolate/display data in HTML https://jinja.palletsprojects.com/en/2.11.x/

This SO and might help you https://stackoverflow.com/a/22181298/3358570

Talha Junaid
  • 2,351
  • 20
  • 29