Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| from loan_model import predict_default | |
| from categorizer import categorize_expenses | |
| from portfolio import analyze_portfolio | |
| # Custom CSS remains the same | |
| css = """ | |
| :root { | |
| --primary: #2563eb; | |
| --secondary: #0ea5e9; | |
| } | |
| body { font-family: 'Segoe UI', sans-serif; } | |
| .header { | |
| background: linear-gradient(120deg, var(--primary), var(--secondary)); | |
| padding: 2rem; | |
| border-radius: 8px; | |
| color: white; | |
| } | |
| .card { | |
| border: 1px solid #e2e8f0; | |
| border-radius: 8px; | |
| padding: 1.5rem; | |
| box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); | |
| } | |
| """ | |
| # Loan Default Predictor UI | |
| def loan_ui(): | |
| with gr.Column(): | |
| gr.Markdown("## π¦ Loan Risk Assessment") | |
| with gr.Row(): | |
| income = gr.Number(label="Monthly Income ($)", value=5000) | |
| loan_amount = gr.Number(label="Loan Amount ($)", value=25000) | |
| with gr.Row(): | |
| credit_score = gr.Slider(300, 850, label="Credit Score", value=720) | |
| employment = gr.Dropdown(["Employed", "Self-employed", "Unemployed"], label="Employment Status", value="Employed") | |
| submit_btn = gr.Button("Assess Risk", variant="primary") | |
| output = gr.Label(label="Risk Prediction") | |
| submit_btn.click( | |
| predict_default, | |
| inputs=[income, loan_amount, credit_score, employment], | |
| outputs=output | |
| ) | |
| # Expense Categorization UI | |
| def expense_ui(): | |
| with gr.Column(): | |
| gr.Markdown("## π§Ύ Expense Categorization") | |
| file_input = gr.File(label="Upload Bank Statement (CSV)") | |
| with gr.Row(): | |
| example_btn = gr.Button("Load Example") | |
| submit_btn = gr.Button("Categorize", variant="primary") | |
| output_table = gr.Dataframe(interactive=False, wrap=True) | |
| example_btn.click( | |
| lambda: "assets/example_statement.csv", | |
| outputs=file_input | |
| ) | |
| submit_btn.click( | |
| categorize_expenses, | |
| inputs=file_input, | |
| outputs=output_table | |
| ) | |
| # Portfolio Analyzer UI | |
| def portfolio_ui(): | |
| with gr.Column(): | |
| gr.Markdown("## π Portfolio Analysis") | |
| file_input = gr.File(label="Upload Holdings (CSV)") | |
| risk_profile = gr.Radio(["Conservative", "Moderate", "Aggressive"], label="Risk Preference", value="Moderate") | |
| with gr.Row(): | |
| example_btn = gr.Button("Load Example") | |
| submit_btn = gr.Button("Analyze", variant="primary") | |
| with gr.Row(): | |
| allocation_plot = gr.Plot() | |
| recommendations = gr.Textbox(label="Optimization Suggestions") | |
| example_btn.click( | |
| lambda: "assets/example_portfolio.csv", | |
| outputs=file_input | |
| ) | |
| submit_btn.click( | |
| analyze_portfolio, | |
| inputs=[file_input, risk_profile], | |
| outputs=[allocation_plot, recommendations] | |
| ) | |
| # Main App Assembly | |
| with gr.Blocks(css=css, title="FinTech Toolkit") as app: | |
| gr.Markdown(""" | |
| <div class="header"> | |
| <h1>π Finance Toolkit Pro</h1> | |
| <p>AI-powered tools for loan risk, expense tracking, and portfolio optimization</p> | |
| </div> | |
| """) | |
| with gr.Tabs(): | |
| with gr.TabItem("Loan Default Predictor", id=0): | |
| loan_ui() | |
| with gr.TabItem("Expense Categorization", id=1): | |
| expense_ui() | |
| with gr.TabItem("Portfolio Analysis", id=2): | |
| portfolio_ui() | |
| gr.Markdown("---\n*Built for FinTech professionals*") | |
| if __name__ == "__main__": | |
| app.launch() |