HugoHE commited on
Commit
f49ff9c
·
verified ·
1 Parent(s): a009d14

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import plotly.graph_objects as go
4
+ def compute_return(month_deposit, initial_deposit, interest_rate, years):
5
+ total = initial_deposit
6
+ actual = initial_deposit
7
+ total_values = []
8
+ actual_values = []
9
+ for i in range(years):
10
+ for j in range(12):
11
+ total += month_deposit
12
+ actual += month_deposit
13
+ total = total * (interest_rate/100 + 1)
14
+ total_values.append(total)
15
+ actual_values.append(actual)
16
+ df = pd.DataFrame([[round(total,2), actual, round((total - actual)/actual*100, 2)]], columns=["Total asset", "Actual Investment", "Percentage Return"])
17
+ # add a line plot for total asset with years
18
+ years_range = list(range(1, years+1))
19
+ fig = go.Figure()
20
+ fig.add_trace(go.Scatter(x=years_range, y=total_values, mode='lines', name='Total'))
21
+ fig.add_trace(go.Scatter(x=years_range, y=actual_values, mode='lines', name='Actual'))
22
+ fig.update_layout(title='Evolution of Actual investment and Total asset with Years', xaxis_title='Years', yaxis_title='Amount')
23
+ return df, fig
24
+
25
+ inputs = [
26
+ gr.Slider(minimum=0, maximum=2000, step=100, value=500, label="Monthly Deposit"),
27
+ gr.Slider(minimum=0, maximum=20000, step=1000, value=500, label="Initial Deposit"),
28
+ gr.Slider(minimum=0, maximum=10, step=0.5, value=1, label="Monthly Return Rate"),
29
+ gr.Slider(minimum=0, maximum=10, step=1, value=1, label="Years")
30
+ ]
31
+
32
+ output = [gr.DataFrame(label="Summary"),
33
+ gr.Plot()]
34
+
35
+ gr.Interface(fn=compute_return, inputs=inputs, outputs=output).launch()