Spaces:
Sleeping
Sleeping
| """FraudSimulator-AI - Fraud Detection System | |
| Built using BDR Agent Factory v1 | |
| """ | |
| import gradio as gr | |
| from typing import Tuple | |
| from agents.pattern_agent import PatternAnalysisAgent | |
| from agents.anomaly_agent import AnomalyDetectionAgent | |
| from agents.risk_scoring_agent import RiskScoringAgent | |
| from governance.fraud_audit_logger import FraudAuditLogger | |
| from governance.fraud_trace import FraudDetectionTrace | |
| class FraudSimulatorAI: | |
| def __init__(self): | |
| self.pattern_agent = PatternAnalysisAgent() | |
| self.anomaly_agent = AnomalyDetectionAgent() | |
| self.risk_agent = RiskScoringAgent() | |
| self.audit_logger = FraudAuditLogger() | |
| self.trace = FraudDetectionTrace() | |
| def analyze_fraud( | |
| self, | |
| claim_id: str, | |
| claim_amount: float, | |
| prior_claims: int, | |
| fraud_flag: bool | |
| ) -> Tuple[str, str, str]: | |
| self.trace.start_trace(claim_id) | |
| claim_data = {"claim_id": claim_id, "claim_amount": claim_amount} | |
| historical_data = {"prior_claims": prior_claims, "fraud_flag": fraud_flag} | |
| pattern_results = self.pattern_agent.process(claim_data, historical_data) | |
| self.trace.add_step("pattern_analysis", pattern_results) | |
| anomaly_results = self.anomaly_agent.process(claim_data, historical_data) | |
| self.trace.add_step("anomaly_detection", anomaly_results) | |
| final_results = self.risk_agent.process(pattern_results, anomaly_results) | |
| self.trace.add_step("risk_scoring", final_results) | |
| audit_id = self.audit_logger.log_fraud_assessment( | |
| claim_id, | |
| final_results["fraud_score"], | |
| final_results["risk_level"], | |
| final_results["fraud_indicators"], | |
| final_results["recommended_action"] | |
| ) | |
| score_text = f"**Fraud Score:** {final_results['fraud_score']:.1%}\n**Risk Level:** {final_results['risk_level'].upper()}" | |
| indicators_text = "**Fraud Indicators:**\n" | |
| if final_results['fraud_indicators']: | |
| indicators_text += "- " + "\n- ".join(final_results['fraud_indicators']) | |
| else: | |
| indicators_text += "No fraud indicators detected" | |
| indicators_text += f"\n\n**Recommended Action:**\n{final_results['recommended_action']}" | |
| if final_results['requires_investigation']: | |
| indicators_text += "\n\nβ οΈ **Investigation Required**" | |
| audit_text = f"""**Audit Trail** | |
| Audit ID: {audit_id} | |
| Trace ID: {self.trace.get_trace()['trace_id']} | |
| **Analysis Pipeline:** | |
| 1. β Pattern Analysis Agent | |
| 2. β Anomaly Detection Agent | |
| 3. β Risk Scoring Agent | |
| **Compliance:** FRAUD_AUDIT | INVESTIGATION_READY | |
| """ | |
| return score_text, indicators_text, audit_text | |
| app = FraudSimulatorAI() | |
| with gr.Blocks(title="FraudSimulator-AI", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown( | |
| """ | |
| # π FraudSimulator-AI | |
| ## AI-Powered Fraud Detection System | |
| **+15% precision improvement | Real-time scoring | Investigation routing** | |
| *Built using [BDR Agent Factory v1](https://huggingface.co/spaces/bdr-ai-org/BDR-Agent-Factory)* | |
| """ | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("### π Claim Information") | |
| claim_id = gr.Textbox(label="Claim ID", value="CLM-FRAUD-001") | |
| claim_amount = gr.Number(label="Claim Amount ($)", value=5000.00) | |
| gr.Markdown("### π Historical Context") | |
| prior_claims = gr.Slider(label="Prior Claims", minimum=0, maximum=10, value=1, step=1) | |
| fraud_flag = gr.Checkbox(label="Previous Fraud Flag", value=False) | |
| analyze_btn = gr.Button("π Analyze Fraud Risk", variant="primary", size="lg") | |
| with gr.Column(scale=1): | |
| gr.Markdown("### π― Fraud Analysis") | |
| score_output = gr.Textbox(label="Fraud Score & Risk Level", lines=2) | |
| indicators_output = gr.Textbox(label="Fraud Indicators", lines=8) | |
| audit_output = gr.Textbox(label="Audit Trail", lines=8) | |
| gr.Examples( | |
| examples=[ | |
| ["CLM-FRAUD-001", 5000.00, 1, False], | |
| ["CLM-FRAUD-002", 15000.00, 4, True], | |
| ["CLM-FRAUD-003", 10000.00, 2, False], | |
| ], | |
| inputs=[claim_id, claim_amount, prior_claims, fraud_flag] | |
| ) | |
| analyze_btn.click( | |
| fn=app.analyze_fraud, | |
| inputs=[claim_id, claim_amount, prior_claims, fraud_flag], | |
| outputs=[score_output, indicators_output, audit_output] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |