modernai commited on
Commit
f892fb9
·
verified ·
1 Parent(s): 96741b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
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(plot_type):
6
- if plot_type == "bar_plot":
7
- # Data for the bars
8
- positions = ['Long', 'Short']
9
- percentages = [0.9, 0.1] # 90% long, 10% short
10
 
11
- data = pd.DataFrame({'Position': positions, 'Percentage': percentages})
12
 
13
- # Creating the bar plot with adjusted width and colors
14
- chart = alt.Chart(data).mark_bar().encode(
15
- x=alt.X('Position:N', axis=alt.Axis(title=None)),
16
- y=alt.Y('Percentage:Q', axis=alt.Axis(title='Percentage')),
17
- color=alt.Color('Position:N', scale=alt.Scale(range=['blue', 'red']))
18
- ).properties(width=400) # Adjust width as needed
19
 
20
- return chart
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
- button.change(create_portfolio_graph, inputs=button, outputs=[plot])
29
- demo.load(create_portfolio_graph, inputs=[button], outputs=[plot])
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
+