title: jinja2.exceptions.UndefinedError: 'predictions' is undefined
body: <p>I have a flask website. I was to make prediction images using the model that I build in Google Collab. In this, I have 25 classes and I took 3 classes for testing its work or not. I have already run it but when I go to the predict pages it seems to get the error '<strong>jinja2.exceptions.UndefinedError: 'predictions' is undefined</strong>' Can anyone help me. Thank u</p>
  <p>The Python Code:</p>
  <pre><code>with open('CNN.pth','rb') as file:
      model=torch.load('CNN.pth',map_location='cpu')
  
  classes=['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24']
  
  def predict(filename,model):
      img=load_img(filename,target_size=(32,32))
      img=img_to_array(img)
      img=img.reshape(1,32,32,3)
  
      img = img.astype('float32')
      img = img/255.0
      result = model.predict(img)
  
      dict_result = {}
      for i in range(25):
          dict_result[result[0][i]] = classes[i]
  
      res = result[0]
      res.sort()
      res = res[::-1]
      prob = res[:3]
  
      prob_result = []
      class_result = []
      for i in range(3):
          prob_result.append((prob[i]*100).round(2))
          class_result.append(dict_result[prob[i]])
  
      return class_result , prob_result
  
  @app.route('/predict' , methods = ['GET' , 'POST'])
  def success():
      error = ''
      target_img = os.path.join(os.getcwd() , 'static/images')
      if request.method == 'POST':
          if (request.files):
              file = request.files['file']
              if file and allowed_file(file.filename):
                  file.save(os.path.join(target_img , file.filename))
                  img_path = os.path.join(target_img , file.filename)
                  img = file.filename
  
                  class_result , prob_result = predict(img_path , model)
  
                  predictions = {
                        &quot;class1&quot;:class_result[0],
                          &quot;class2&quot;:class_result[1],
                          &quot;class3&quot;:class_result[2],
                          &quot;prob1&quot;: prob_result[0],
                          &quot;prob2&quot;: prob_result[1],
                          &quot;prob3&quot;: prob_result[2],
                  }
  
              else:
                  error = &quot;Please upload images of jpg , jpeg and png extension only&quot;
  
              if(len(error) == 0):
                  return  render_template('predict.html' , img  = img , predictions = predictions)
              else:
                  return render_template('home.html' , error = error)
  
      else:
          return render_template('home.html')
  </code></pre>
  <p>Index.html</p>
  <pre><code>&lt;tr&gt;
                  &lt;th&gt;Class&lt;/th&gt;
                  &lt;th&gt;Probability&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                &lt;th&gt;{{predictions.class1}}&lt;/th&gt;
                  &lt;th&gt;{{predictions.prob1}}&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                &lt;th&gt;{{predictions.class2}}&lt;/th&gt;
                  &lt;th&gt;{{predictions.prob2}}&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                &lt;th&gt;{{predictions.class3}}&lt;/th&gt;
                  &lt;th&gt;{{predictions.prob3}}&lt;/th&gt;
              &lt;/tr&gt;
  </code></pre>