Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,31 +2,26 @@ import gradio as gr
|
|
| 2 |
import altair as alt
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
-
def create_portfolio_graph(
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
percentages = [0.9, 0.1] # 90% long, 10% short
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
else:
|
| 22 |
-
return None
|
| 23 |
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
-
button = gr.Radio(label="Plot type",
|
| 26 |
-
choices=['bar_plot'], value='bar_plot')
|
| 27 |
plot = gr.Plot(label="Portfolio Composition Chart")
|
| 28 |
-
|
| 29 |
-
demo.load(create_portfolio_graph, inputs=[
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|
| 32 |
demo.launch()
|
|
@@ -44,3 +39,4 @@ if __name__ == "__main__":
|
|
| 44 |
|
| 45 |
|
| 46 |
|
|
|
|
|
|
| 2 |
import altair as alt
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
+
def create_portfolio_graph():
|
| 6 |
+
# Data for the bars
|
| 7 |
+
positions = ['Long', 'Short']
|
| 8 |
+
percentages = [0.9, 0.1] # 90% long, 10% short
|
|
|
|
| 9 |
|
| 10 |
+
data = pd.DataFrame({'Position': positions, 'Percentage': percentages})
|
| 11 |
|
| 12 |
+
# Creating the bar plot with adjusted width and colors
|
| 13 |
+
chart = alt.Chart(data).mark_bar().encode(
|
| 14 |
+
x=alt.X('Position:N', axis=alt.Axis(title=None)),
|
| 15 |
+
y=alt.Y('Percentage:Q', axis=alt.Axis(title='Percentage')),
|
| 16 |
+
color=alt.Color('Position:N', scale=alt.Scale(range=['blue', 'red']))
|
| 17 |
+
).properties(width=400) # Adjust width as needed
|
| 18 |
|
| 19 |
+
return chart
|
|
|
|
|
|
|
| 20 |
|
| 21 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
| 22 |
plot = gr.Plot(label="Portfolio Composition Chart")
|
| 23 |
+
plot.change(create_portfolio_graph, inputs=[], outputs=[plot])
|
| 24 |
+
demo.load(create_portfolio_graph, inputs=[], outputs=[plot])
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
demo.launch()
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
+
|