Spaces:
Running
Running
| import gradio as gr | |
| from interface.rebalancing_interface import ( | |
| portfolio_rebalancing_inputs, examples, main_currency, holdings, | |
| cash_amount, cash_ratio, output as rebalancing_output, | |
| update_output as rebalancing_update_output | |
| ) | |
| from interface.share_price_trend_interface import ( | |
| share_price_trend_inputs, stock_codes, period, | |
| output as share_price_trend_output, | |
| update_output as share_price_trend_update_output | |
| ) | |
| from interface.dollar_cost_averaging_interface import ( | |
| dollar_cost_averaging_inputs, old_price, old_quantity, | |
| new_price, new_quantity, | |
| output as dollar_cost_averaging_output, | |
| update_output as dollar_cost_averaging_update_output | |
| ) | |
| from interface.retirement_planning_interface import ( | |
| retirement_planning_inputs, current_age, retirement_age, | |
| life_expectancy, monthly_income_required, inflation_rate, | |
| current_investment, monthly_investment, | |
| annual_increase_in_monthly_investment, reinvest_dividends, | |
| pre_retirement_roi, pre_retirement_dividend_yield, | |
| post_retirement_roi, post_retirement_dividend_yield, | |
| output as retirement_output, | |
| update_output as retirement_update_output | |
| ) | |
| from interface.about_interface import render as render_about_tab | |
| # Helper function to add buttons | |
| def add_buttons(inputs, update_fn, output): | |
| clear_button = gr.ClearButton(value="Clear") | |
| clear_button.click( | |
| fn=lambda: [None] * len(inputs), | |
| inputs=[], | |
| outputs=inputs | |
| ) | |
| submit_button = gr.Button(value="Run", variant="primary") | |
| submit_button.click( | |
| fn=update_fn, | |
| inputs=inputs, | |
| outputs=output | |
| ) | |
| return clear_button, submit_button | |
| with gr.Blocks(css='style.css') as demo: | |
| with gr.Column(elem_id="col-container"): | |
| with gr.Tabs(): | |
| with gr.TabItem("RE-BALANCING"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| holdings.render() | |
| with gr.Row(): | |
| main_currency.render() | |
| cash_amount.render() | |
| cash_ratio.render() | |
| # Add buttons and handlers | |
| clear_button, submit_button = add_buttons( | |
| portfolio_rebalancing_inputs, | |
| rebalancing_update_output, | |
| rebalancing_output | |
| ) | |
| with gr.Column(): | |
| rebalancing_output.render() | |
| gr.Examples( | |
| examples=examples, | |
| cache_examples=False, | |
| inputs=portfolio_rebalancing_inputs | |
| ) | |
| for input_component in portfolio_rebalancing_inputs: | |
| input_component.change( | |
| fn=rebalancing_update_output, | |
| inputs=portfolio_rebalancing_inputs, | |
| outputs=rebalancing_output | |
| ) | |
| with gr.TabItem("SHARE PRICE TREND"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| stock_codes.render() | |
| period.render() | |
| # Add buttons and handlers | |
| clear_button, submit_button = add_buttons( | |
| share_price_trend_inputs, | |
| share_price_trend_update_output, | |
| share_price_trend_output | |
| ) | |
| with gr.Column(): | |
| share_price_trend_output.render() | |
| for input_component in share_price_trend_inputs: | |
| input_component.change( | |
| fn=share_price_trend_update_output, | |
| inputs=share_price_trend_inputs, | |
| outputs=share_price_trend_output | |
| ) | |
| with gr.TabItem("DOLLAR-COST AVERAGING"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| with gr.Accordion("FIRST PURCHASE", open=True): | |
| with gr.Row(): | |
| old_price.render() | |
| old_quantity.render() | |
| with gr.Accordion("SECOND PURCHASE", open=True): | |
| with gr.Row(): | |
| new_price.render() | |
| new_quantity.render() | |
| # Add buttons and handlers | |
| clear_button, submit_button = add_buttons( | |
| dollar_cost_averaging_inputs, | |
| dollar_cost_averaging_update_output, | |
| dollar_cost_averaging_output | |
| ) | |
| with gr.Column(): | |
| dollar_cost_averaging_output.render() | |
| for input_component in dollar_cost_averaging_inputs: | |
| input_component.change( | |
| fn=dollar_cost_averaging_update_output, | |
| inputs=dollar_cost_averaging_inputs, | |
| outputs=dollar_cost_averaging_output | |
| ) | |
| with gr.TabItem("RETIREMENT PLANNING"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| with gr.Accordion("PROFILE", open=True): | |
| with gr.Row(): | |
| current_age.render() | |
| retirement_age.render() | |
| life_expectancy.render() | |
| monthly_income_required.render() | |
| inflation_rate.render() | |
| with gr.Accordion("SAVINGS", open=True): | |
| with gr.Row(): | |
| current_investment.render() | |
| monthly_investment.render() | |
| annual_increase_in_monthly_investment.render() | |
| reinvest_dividends.render() | |
| with gr.Accordion("GROWTH", open=True): | |
| with gr.Row(): | |
| pre_retirement_roi.render() | |
| pre_retirement_dividend_yield.render() | |
| post_retirement_roi.render() | |
| post_retirement_dividend_yield.render() | |
| # Add buttons and handlers | |
| clear_button, submit_button = add_buttons( | |
| retirement_planning_inputs, | |
| retirement_update_output, | |
| retirement_output | |
| ) | |
| with gr.Column(): | |
| retirement_output.render() | |
| for input_component in retirement_planning_inputs: | |
| input_component.change( | |
| fn=retirement_update_output, | |
| inputs=retirement_planning_inputs, | |
| outputs=retirement_output | |
| ) | |
| render_about_tab() | |
| demo.launch(share=True) | |