Diego Salinas commited on
Commit
f7a3061
·
verified ·
1 Parent(s): 67accf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -20,20 +20,22 @@ def create_portfolio_graph():
20
  height = bar.get_height()
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 within the Gradio workspace
24
- image_path = "/mnt/data/portfolio_chart.png"
25
- plt.savefig(image_path)
 
 
26
  plt.close()
27
 
28
- # Return the image path
29
- return image_path
30
 
31
  # Gradio Interface with Button for user interaction
32
  iface = gr.Interface(
33
  fn=create_portfolio_graph,
34
- inputs=None,
35
  outputs=gr.Image(label="Portfolio Composition Chart"),
36
- live=False
37
  )
38
 
39
  # Launch Gradio interface
@@ -50,3 +52,4 @@ iface.launch()
50
 
51
 
52
 
 
 
20
  height = bar.get_height()
21
  ax.text(bar.get_x() + bar.get_width() / 2, height, f'{percentage*100:.0f}%', ha='center', va='bottom')
22
 
23
+ # Convert the plot to a NumPy array
24
+ image_array = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
25
+ image_array = image_array.reshape(fig.canvas.get_width_height()[::-1] + (3,))
26
+
27
+ # Close the plot
28
  plt.close()
29
 
30
+ # Return the image array
31
+ return image_array
32
 
33
  # Gradio Interface with Button for user interaction
34
  iface = gr.Interface(
35
  fn=create_portfolio_graph,
36
+ inputs=gr.Button("Display Graph"),
37
  outputs=gr.Image(label="Portfolio Composition Chart"),
38
+ live=True
39
  )
40
 
41
  # Launch Gradio interface
 
52
 
53
 
54
 
55
+