0

I am trying to display my graph using flask but all i am getting is a image placeholder. The code is working as the image is getting saved in my colab files, and the graph is correct, but it is not displaying in flask. Please help.

Flask.py:

from flask import Flask, render_template
import matplotlib.pyplot as plt
from flask import *
from flask_ngrok import run_with_ngrok
from google.colab import files
import seaborn as sns
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
app = Flask(__name__)

@app.route('/plot')
def plot():
   plt.plot(real_stock_price, color = 'red', label = 'Real price')
   plt.plot(predicted_stock_price, color = 'blue', label = 'Predicted price')
   plt.title('Google price prediction')
   plt.xlabel('Time')
   plt.ylabel('Price')
   plt.legend()
   plt.savefig('plot.png')
   return render_template('plot.html', url='plot.png')
app.run()

Plot.html:

<html>
  <body>
  <img src='plot.png' alt="Chart" height="auto" width="100%">
  </body>
</html>

Any suggestions would be amazing !

  • Possible duplicate https://stackoverflow.com/questions/23327293/flask-raises-templatenotfound-error-even-though-template-file-exists – Andrew Chisholm Jul 03 '21 at 10:00

0 Answers0