Spaces:
Running
Running
| import gradio as gr | |
| from interface.rebalancing_interface import ( | |
| input as rebalancing_inputs, | |
| output as rebalancing_output, | |
| update_output as rebalancing_update_output, | |
| examples as rebalancing_examples, | |
| component_rows as rebalancing_component_rows, | |
| ) | |
| from interface.share_price_trend_interface import ( | |
| input as share_price_trend_inputs, | |
| output as share_price_trend_output, | |
| update_output as share_price_trend_update_output, | |
| examples as share_price_trend_examples, | |
| component_rows as share_price_trend_component_rows, | |
| ) | |
| from interface.dollar_cost_averaging_interface import ( | |
| input as dollar_cost_averaging_inputs, | |
| output as dollar_cost_averaging_output, | |
| update_output as dollar_cost_averaging_update_output, | |
| examples as dollar_cost_averaging_examples, | |
| component_rows as dollar_cost_averaging_component_rows, | |
| ) | |
| from interface.retirement_planning_interface import ( | |
| input as retirement_planning_inputs, | |
| output as retirement_planning_output, | |
| update_output as retirement_update_output, | |
| examples as retirement_planning_examples, | |
| component_rows as retirement_planning_component_rows, | |
| ) | |
| tabs_configuration = [ | |
| #("πΈ Dividend-Based Retirement Planning", retirement_planning_inputs, retirement_planning_output, retirement_update_output, retirement_planning_examples, retirement_planning_component_rows), | |
| ("π Re-Balancing Calculator", rebalancing_inputs, rebalancing_output, rebalancing_update_output, rebalancing_examples, rebalancing_component_rows), | |
| # ("π Share Price Trend", share_price_trend_inputs, share_price_trend_output, share_price_trend_update_output, share_price_trend_examples, share_price_trend_component_rows), | |
| # ("π Dollar Cost Averaging Calculator", dollar_cost_averaging_inputs, dollar_cost_averaging_output, dollar_cost_averaging_update_output, dollar_cost_averaging_examples, dollar_cost_averaging_component_rows), | |
| ] | |
| def initial_load(*args): | |
| idx = 0 | |
| rebalancing_results = rebalancing_update_output(*args[idx:idx+len(rebalancing_inputs)]) | |
| idx += len(rebalancing_inputs) | |
| share_price_trend_results = share_price_trend_update_output(*args[idx:idx+len(share_price_trend_inputs)]) | |
| idx += len(share_price_trend_inputs) | |
| dollar_cost_averaging_results = dollar_cost_averaging_update_output(*args[idx:idx+len(dollar_cost_averaging_inputs)]) | |
| idx += len(dollar_cost_averaging_inputs) | |
| retirement_results = retirement_update_output(*args[idx:]) | |
| return (rebalancing_results, share_price_trend_results, dollar_cost_averaging_results, retirement_results) | |
| MARKDOWN = (""" | |
| --- | |
| **If you find this tool useful and would like to support its development, please consider making a donation. Your support is greatly appreciated!** | |
| - [Donate with KakaoPay](https://qr.kakaopay.com/Ej7jF6o7B) | |
| --- | |
| For any questions or feedback, reach us at: π§ [[email protected]](mailto:[email protected]) | |
| --- | |
| """) | |
| # Helper function to add buttons | |
| def clear_buttons(inputs): | |
| clear_button = gr.ClearButton(value="Clear") | |
| clear_button.click( | |
| fn=lambda: [None] * len(inputs), | |
| inputs=[], | |
| outputs=inputs | |
| ) | |
| return clear_button | |
| def submit_buttons(inputs, update_fn, output): | |
| submit_button = gr.Button(value="Run", variant="primary") | |
| submit_button.click( | |
| fn=update_fn, | |
| inputs=inputs, | |
| outputs=output | |
| ) | |
| return submit_button | |
| def on_change(inputs, update_ouutput, outputs): | |
| for input_component in inputs: | |
| input_component.change( | |
| fn=update_ouutput, | |
| inputs=inputs, | |
| outputs=outputs | |
| ) | |
| def render_components(component_rows): | |
| for row in component_rows: | |
| if isinstance(row, list): | |
| with gr.Row(): | |
| for component in row: | |
| component.render() | |
| else: | |
| row.render() | |
| def create_tab(tab_name, inputs, outputs, update_fn, examples, component_rows): | |
| with gr.Tab(tab_name): | |
| with gr.Row(): | |
| with gr.Column(elem_classes="input", scale=1): | |
| render_components(component_rows) | |
| clear_buttons(inputs) | |
| submit_buttons(inputs, update_fn, outputs) | |
| with gr.Column(scale=3): | |
| outputs.render() | |
| with gr.Accordion("π Examples", open=False): | |
| gr.Examples(examples=examples, cache_examples=False, inputs=inputs) | |
| on_change(inputs, update_fn, outputs) | |
| with gr.Blocks(css='style.css') as demo: | |
| with gr.Column(elem_id="col-container"): | |
| with gr.Tabs(): | |
| for tab in tabs_configuration: | |
| create_tab(*tab) | |
| # render_about_tab() # "Support Us" ν μΆκ° | |
| with gr.Accordion("π€ DONATE", open=True): | |
| gr.Markdown(MARKDOWN, elem_id="col-container") | |
| demo.load( | |
| initial_load, | |
| inputs=rebalancing_inputs + share_price_trend_inputs + dollar_cost_averaging_inputs + retirement_planning_inputs, | |
| outputs=[ | |
| rebalancing_output, | |
| share_price_trend_output, | |
| dollar_cost_averaging_output, | |
| retirement_planning_output | |
| ] | |
| ) | |
| demo.launch(share=True) | |