Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pandas as pd | |
| import plotly.graph_objects as go | |
| def compute_return(month_deposit, initial_deposit, interest_rate, years): | |
| total = initial_deposit | |
| actual = initial_deposit | |
| total_values = [] | |
| actual_values = [] | |
| for i in range(years): | |
| for j in range(12): | |
| total += month_deposit | |
| actual += month_deposit | |
| total = total * (interest_rate/100 + 1) | |
| total_values.append(total) | |
| actual_values.append(actual) | |
| df = pd.DataFrame([[round(total,2), actual, round((total - actual)/actual*100, 2)]], columns=["Total asset", "Actual Investment", "Percentage Return"]) | |
| # add a line plot for total asset with years | |
| years_range = list(range(1, years+1)) | |
| fig = go.Figure() | |
| fig.add_trace(go.Scatter(x=years_range, y=total_values, mode='lines', name='Total')) | |
| fig.add_trace(go.Scatter(x=years_range, y=actual_values, mode='lines', name='Actual')) | |
| fig.update_layout(title='Evolution of Actual investment and Total asset with Years', xaxis_title='Years', yaxis_title='Amount') | |
| return df, fig | |
| inputs = [ | |
| gr.Slider(minimum=0, maximum=2000, step=100, value=500, label="Monthly Deposit"), | |
| gr.Slider(minimum=0, maximum=20000, step=1000, value=500, label="Initial Deposit"), | |
| gr.Slider(minimum=0, maximum=10, step=0.5, value=1, label="Monthly Return Rate"), | |
| gr.Slider(minimum=0, maximum=10, step=1, value=1, label="Years") | |
| ] | |
| output = [gr.DataFrame(label="Summary"), | |
| gr.Plot()] | |
| gr.Interface(fn=compute_return, inputs=inputs, outputs=output).launch() | |