Spaces:
Sleeping
Sleeping
Diego Salinas commited on
Update app.py
Browse files
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 |
-
#
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
plt.close()
|
| 27 |
|
| 28 |
-
# Return the image
|
| 29 |
-
return
|
| 30 |
|
| 31 |
# Gradio Interface with Button for user interaction
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=create_portfolio_graph,
|
| 34 |
-
inputs=
|
| 35 |
outputs=gr.Image(label="Portfolio Composition Chart"),
|
| 36 |
-
live=
|
| 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 |
+
|