Spaces:
Sleeping
Sleeping
Diego Salinas commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,42 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import plotly.graph_objects as go
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
fig
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
iface = gr.Interface(
|
| 9 |
-
fn=
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
)
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
iface.layout(css=".output_container {width: 50%; margin: auto;}") # Centering the graph
|
| 17 |
-
|
| 18 |
iface.launch()
|
| 19 |
|
|
|
|
|
|
| 1 |
+
!pip install plotly
|
| 2 |
import gradio as gr
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
|
| 5 |
+
def plot_portfolio(long_percentage, short_percentage):
|
| 6 |
+
# Create a bar graph
|
| 7 |
+
fig = go.Figure()
|
| 8 |
|
| 9 |
+
# Add bars for long and short
|
| 10 |
+
fig.add_trace(go.Bar(x=['Long', 'Short'], y=[long_percentage, short_percentage],
|
| 11 |
+
marker_color=['blue', 'red']))
|
| 12 |
+
|
| 13 |
+
# Update layout for better presentation
|
| 14 |
+
fig.update_layout(title_text='Portfolio Composition',
|
| 15 |
+
xaxis_title='Portfolio',
|
| 16 |
+
yaxis_title='Percentage',
|
| 17 |
+
showlegend=False, # Do not display legend
|
| 18 |
+
width=500, # Adjust the width
|
| 19 |
+
height=400, # Adjust the height
|
| 20 |
+
margin=dict(l=50, r=50, b=50, t=50), # Adjust margins
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Save the graph to an image file
|
| 24 |
+
image_path = '/path/to/graph.png'
|
| 25 |
+
fig.write_image(image_path)
|
| 26 |
+
|
| 27 |
+
# Return the image path
|
| 28 |
+
return image_path
|
| 29 |
+
|
| 30 |
+
# Define the Gradio interface
|
| 31 |
iface = gr.Interface(
|
| 32 |
+
fn=plot_portfolio,
|
| 33 |
+
inputs=[gr.Slider(0, 100, default=90, label='Long (%)'),
|
| 34 |
+
gr.Slider(0, 100, default=10, label='Short (%)')],
|
| 35 |
+
outputs=[gr.Image()],
|
| 36 |
+
live=True,
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# Launch the Gradio interface
|
|
|
|
|
|
|
| 40 |
iface.launch()
|
| 41 |
|
| 42 |
+
|