Diego Salinas commited on
Commit
d851a26
·
verified ·
1 Parent(s): 14c3507

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -1,7 +1,10 @@
1
- import gradio as gr
2
  import matplotlib.pyplot as plt
3
  import numpy as np
4
 
 
 
 
5
  def create_portfolio_graph():
6
  # Data for the bars
7
  positions = ['Long', 'Short']
@@ -21,24 +24,15 @@ def create_portfolio_graph():
21
  ax.text(bar.get_x() + bar.get_width() / 2, height, f'{percentage*100:.0f}%', ha='center', va='bottom')
22
 
23
  # Save the plot as an image
24
- plt.savefig("/mnt/data/portfolio_chart.png")
 
25
  plt.close()
26
 
27
- # Return the image as a NumPy array
28
- return np.array(plt.imread("/mnt/data/portfolio_chart.png"))
29
-
30
- # Gradio Interface (with a dummy input)
31
- iface = gr.Interface(
32
- fn=create_portfolio_graph,
33
- inputs=[gr.Textbox()],
34
- outputs=gr.Image(type="numpy", label="Portfolio Composition Chart"),
35
- live=True,
36
- capture_session=True
37
- )
38
-
39
- # Launch Gradio interface
40
- iface.launch()
41
 
 
 
42
 
43
 
44
 
 
1
+ from flask import Flask, send_file
2
  import matplotlib.pyplot as plt
3
  import numpy as np
4
 
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/')
8
  def create_portfolio_graph():
9
  # Data for the bars
10
  positions = ['Long', 'Short']
 
24
  ax.text(bar.get_x() + bar.get_width() / 2, height, f'{percentage*100:.0f}%', ha='center', va='bottom')
25
 
26
  # Save the plot as an image
27
+ image_path = "static/portfolio_chart.png"
28
+ plt.savefig(image_path)
29
  plt.close()
30
 
31
+ # Return the image path
32
+ return send_file(image_path, mimetype='image/png')
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ if __name__ == '__main__':
35
+ app.run(debug=True)
36
 
37
 
38