File size: 3,573 Bytes
6c490d4
 
 
5852e51
 
 
6c490d4
5852e51
6c490d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5852e51
6c490d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5852e51
6c490d4
 
 
 
 
 
 
 
 
 
 
 
 
5852e51
6c490d4
 
 
 
 
 
 
5852e51
6c490d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5852e51
6c490d4
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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()