| | import gradio as gr |
| | import pandas as pd |
| |
|
| | def calculate_de_ratio( |
| | long_term_borrowings, |
| | debentures, |
| | bonds, |
| | term_loans, |
| | equity_share_capital, |
| | preference_share_capital, |
| | reserves_surplus, |
| | retained_earnings |
| | ): |
| | |
| | total_debt = long_term_borrowings + debentures + bonds + term_loans |
| | shareholders_equity = ( |
| | equity_share_capital |
| | + preference_share_capital |
| | + reserves_surplus |
| | + retained_earnings |
| | ) |
| |
|
| | |
| | de_ratio = total_debt / shareholders_equity if shareholders_equity != 0 else 0 |
| |
|
| | |
| | summary = f""" |
| | ### 📊 Debt–Equity Ratio Summary |
| | |
| | - **Total Debt:** ₹ {total_debt:,.2f} |
| | - **Shareholders’ Equity:** ₹ {shareholders_equity:,.2f} |
| | - **Debt–Equity Ratio:** **{de_ratio:.2f}** |
| | """ |
| |
|
| | |
| | data = { |
| | "Component": [ |
| | "Long-term Borrowings", |
| | "Debentures", |
| | "Bonds", |
| | "Term Loans", |
| | "Equity Share Capital", |
| | "Preference Share Capital", |
| | "Reserves & Surplus", |
| | "Retained Earnings", |
| | ], |
| | "Amount (₹)": [ |
| | long_term_borrowings, |
| | debentures, |
| | bonds, |
| | term_loans, |
| | equity_share_capital, |
| | preference_share_capital, |
| | reserves_surplus, |
| | retained_earnings, |
| | ], |
| | } |
| |
|
| | df = pd.DataFrame(data) |
| |
|
| | return summary, df |
| |
|
| |
|
| | with gr.Blocks() as demo: |
| | gr.Markdown("# 💰 Debt–Equity Ratio Calculator") |
| |
|
| | with gr.Row(): |
| | with gr.Column(): |
| | gr.Markdown("## Total Debt Components") |
| | long_term_borrowings = gr.Number(label="Long-term Borrowings", value=0) |
| | debentures = gr.Number(label="Debentures", value=0) |
| | bonds = gr.Number(label="Bonds", value=0) |
| | term_loans = gr.Number(label="Term Loans", value=0) |
| |
|
| | with gr.Column(): |
| | gr.Markdown("## Shareholders’ Equity Components") |
| | equity_share_capital = gr.Number(label="Equity Share Capital", value=0) |
| | preference_share_capital = gr.Number(label="Preference Share Capital", value=0) |
| | reserves_surplus = gr.Number(label="Reserves & Surplus", value=0) |
| | retained_earnings = gr.Number(label="Retained Earnings", value=0) |
| |
|
| | calculate_btn = gr.Button("Calculate") |
| |
|
| | output_md = gr.Markdown() |
| | output_table = gr.Dataframe() |
| |
|
| | calculate_btn.click( |
| | fn=calculate_de_ratio, |
| | inputs=[ |
| | long_term_borrowings, |
| | debentures, |
| | bonds, |
| | term_loans, |
| | equity_share_capital, |
| | preference_share_capital, |
| | reserves_surplus, |
| | retained_earnings, |
| | ], |
| | outputs=[output_md, output_table], |
| | ) |
| |
|
| | demo.launch() |
| |
|