modernai commited on
Commit
0248df7
·
verified ·
1 Parent(s): 166894c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -2,10 +2,14 @@ import gradio as gr
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
 
@@ -24,9 +28,13 @@ with gr.Blocks() as demo:
24
  # This is the Current Recommended Portfolio Allocation
25
  """
26
  )
 
 
 
27
  plot = gr.Plot(label="Portfolio Composition Chart")
28
- plot.change(create_portfolio_graph, inputs=[], outputs=[plot])
29
- demo.load(create_portfolio_graph, inputs=[], outputs=[title, plot])
 
30
 
31
  if __name__ == "__main__":
32
  demo.launch()
@@ -49,3 +57,4 @@ if __name__ == "__main__":
49
 
50
 
51
 
 
 
2
  import altair as alt
3
  import pandas as pd
4
 
5
+ def create_portfolio_graph(amount):
6
+ # Calculate positions based on the provided amount
7
+ long_position = 0.9 * amount
8
+ short_position = 0.1 * amount
9
+
10
  # Data for the bars
11
  positions = ['Long', 'Short']
12
+ percentages = [long_position, short_position]
13
 
14
  data = pd.DataFrame({'Position': positions, 'Percentage': percentages})
15
 
 
28
  # This is the Current Recommended Portfolio Allocation
29
  """
30
  )
31
+ total_funds_input = gr.Textbox("Type your total funds", default="100000", numeric=True)
32
+ submit_button = gr.Button("Submit")
33
+
34
  plot = gr.Plot(label="Portfolio Composition Chart")
35
+ plot.change(create_portfolio_graph, inputs=[total_funds_input, submit_button], outputs=[plot])
36
+
37
+ demo.load(create_portfolio_graph, inputs=[total_funds_input, submit_button], outputs=[title, plot])
38
 
39
  if __name__ == "__main__":
40
  demo.launch()
 
57
 
58
 
59
 
60
+