Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import re | |
| def detect_fraud(provider, procedure, amount, notes): | |
| """ | |
| Lightweight rule-based fraud indicator for demonstration. | |
| """ | |
| text = f"{provider} {procedure} {notes}".lower() | |
| # Rule-based flags (common healthcare fraud patterns) | |
| upcoding_terms = ["complex visit", "level 5", "high severity", "multiple procedures"] | |
| phantom_terms = ["no patient", "patient denies", "never seen"] | |
| unbundling_terms = ["billed separately", "duplicate", "split billing"] | |
| high_amount_threshold = 5000 # simple flag | |
| flags = [] | |
| # Fraud pattern detection | |
| if any(term in text for term in upcoding_terms): | |
| flags.append("Upcoding") | |
| if any(term in text for term in phantom_terms): | |
| flags.append("Phantom Billing") | |
| if any(term in text for term in unbundling_terms): | |
| flags.append("Unbundling") | |
| if amount > high_amount_threshold: | |
| flags.append("High-Dollar Flag") | |
| # Score logic | |
| if len(flags) >= 3: | |
| score = "High Fraud Risk" | |
| elif len(flags) == 2: | |
| score = "Moderate Fraud Risk" | |
| elif len(flags) == 1: | |
| score = "Low Fraud Risk" | |
| else: | |
| score = "No Fraud Indicators Found" | |
| df = pd.DataFrame({ | |
| "Provider": [provider], | |
| "Procedure": [procedure], | |
| "Amount": [amount], | |
| "Detected Flags": [", ".join(flags) if flags else "None"], | |
| "Fraud Risk Score": [score] | |
| }) | |
| return df, f"### Fraud Risk: **{score}**\nFlags: {', '.join(flags) if flags else 'None'}" | |
| # ---- Gradio App UI ---- | |
| with gr.Blocks(title="Healthcare Fraud Detection Demo") as demo: | |
| gr.Markdown("## 🏥 Healthcare Fraud Detection – Demo (Rule-Based)") | |
| gr.Markdown("Upload simple claim information to evaluate possible fraud indicators.") | |
| with gr.Row(): | |
| provider = gr.Textbox(label="Provider Name", placeholder="Example: ABC Clinic") | |
| procedure = gr.Textbox(label="Procedure Code/Description", placeholder="Example: Level 5 visit") | |
| amount = gr.Number(label="Claim Amount ($)", value=1200) | |
| notes = gr.Textbox( | |
| label="Claim Notes", | |
| lines=6, | |
| placeholder="Example: Patient denies visit. Procedure billed separately..." | |
| ) | |
| submit = gr.Button("Analyze Claim") | |
| output_table = gr.Dataframe(label="Fraud Detection Summary") | |
| output_text = gr.Markdown(label="Fraud Score") | |
| submit.click( | |
| detect_fraud, | |
| inputs=[provider, procedure, amount, notes], | |
| outputs=[output_table, output_text] | |
| ) | |
| demo.launch(share=True) |