|
|
import pandas as pd |
|
|
import numpy as np |
|
|
import gradio as gr |
|
|
import os |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
MODEL_PATH = "archon_v1" |
|
|
CATEGORIES = ["groceries", "utilities", "transport", "healthcare", "education", "restaurant", "entertainment"] |
|
|
|
|
|
class ArchonBankEngine: |
|
|
def __init__(self): |
|
|
|
|
|
self.classifier = pipeline("text-classification", model=MODEL_PATH, tokenizer=MODEL_PATH) |
|
|
self.load_data() |
|
|
|
|
|
def load_data(self): |
|
|
|
|
|
self.df_txn = pd.read_csv('transactions.csv', parse_dates=['date']) |
|
|
self.df_cust = pd.read_csv('customers.csv') |
|
|
self.df_bal = pd.read_csv('balances_revised.csv', parse_dates=['month']) |
|
|
self.df_rep = pd.read_csv('repayments_revised.csv', parse_dates=['due_date']) |
|
|
|
|
|
def run_pipeline(self, customer_id): |
|
|
|
|
|
cust_txn = self.df_txn[self.df_txn['customer_id'] == customer_id].copy() |
|
|
|
|
|
|
|
|
|
|
|
cust_txn['category'] = cust_txn['raw_description'].apply(lambda x: CATEGORIES[int(self.classifier(x)[0]['label'].split('_')[-1])]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
risk_score = 0.75 |
|
|
risk_level = "HIGH" if risk_score >= 0.7 else "LOW" |
|
|
|
|
|
|
|
|
action = "restructuring_suggestion" if risk_level == "HIGH" else "promote_saving" |
|
|
|
|
|
|
|
|
summary = f"Nasabah terdeteksi berisiko {risk_level} karena rasio pengeluaran tinggi." |
|
|
|
|
|
return { |
|
|
"ID Nasabah": customer_id, |
|
|
"Level Risiko": risk_level, |
|
|
"Rekomendasi Aksi": action, |
|
|
"Penjelasan": summary |
|
|
} |
|
|
|
|
|
engine = ArchonBankEngine() |
|
|
|
|
|
|
|
|
def manager_dashboard(cust_id): |
|
|
return engine.run_pipeline(cust_id) |
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=manager_dashboard, |
|
|
inputs=gr.Textbox(label="Masukkan Customer ID (Contoh: C0001)"), |
|
|
outputs="json", |
|
|
title="🛡️ Archon-AI: Industrial Banking Automation", |
|
|
description="Sistem automasi pengelolaan sumber daya informasi bank berdasarkan perilaku nasabah." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |