title: How to update an existing Python Flask web page based on form input?
body: <p>I am trying to build a prediction web application with Flask. The app should take in user input, process it through a python trained model, then display the results as a chart beside the input form. </p>
  
  <p>My code looks like this:</p>
  
  <p><strong>HTML Form:</strong></p>
  
  <pre><code>&lt;form class = "prediction-options" method = "post" action = "/prediction/results"&gt;
    &lt;!--the input fields--&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Flask app.py</strong></p>
  
  <pre><code>@app.route("/")
  def main():
      return render_template('index.html')    
  
  @app.route("/prediction/results", methods = ['POST'])
  def predict():
      input_aqi = float(request.form['aqi'])/272
      input_pm2_5 = float(request.form['pm2_5'])/224
      input_pm10 = float(request.form['pm10'])/283
      input_so2 = float(request.form['so2'])/36
      input_no2 = float(request.form['no2'])/110
      input_co = float(request.form['co'])/1.83
      input_o3 = float(request.form['o3'])/124
      input_list = [[input_aqi,input_pm2_5,input_pm10,input_so2,input_no2,input_co,input_o3]]
  
  
      output_acute_bronchitis = model_acute_bronchitis.predict(input_list)
      output_asthma = model_asthma.predict(input_list)
      output_asthmatic_bronchitis = model_asthmatic_bronchitis.predict(input_list)
      output_aurti = model_aurti.predict(input_list)
      output_bronchitis = model_bronchitis.predict(input_list)
      output_pneumonia = model_pneumonia.predict(input_list)
  
      d = collections.OrderedDict()
      d['acute_bronchitis'] = output_acute_bronchitis[0]
      d['asthma'] = output_asthma[0]
      d['asthmatic_bronchitis'] = output_asthmatic_bronchitis[0]
      d['aurti'] = output_aurti[0]
      d['bronchitis'] = output_bronchitis[0]
      d['pneumonia'] = output_pneumonia[0]
  
      prediction = jsonify(d)
      return prediction
  </code></pre>
  
  <p>Right now, I have managed to take in the user input and render the predicted results on the '/prediction/results' page. How can I get the results to show up on the '/' page? I tried to do this:</p>
  
  <pre><code>@app.route("/", methods = ['POST','GET'])
  def main():
      if request.method == 'POST':
          def predict():
             #predict function that returns prediction
      return render_template('index.html')
  </code></pre>
  
  <p>But I always get a <code>socket.error: [Errno 32] Broken pipe</code> error message. What should I do?</p>