File size: 2,007 Bytes
630ff31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from predictor import predict

def make_prediction(distance_from_home, distance_from_last_transaction, 
                    ratio_to_median_purchase_price, repeat_retailer, 
                    used_chip, used_pin_number, online_order):
    """
    Prepares user input data and performs a local prediction.

    Args:
        distance_from_home (float): Distance from home.
        distance_from_last_transaction (float): Distance from the last transaction.
        ratio_to_median_purchase_price (float): Ratio to the median purchase price.
        repeat_retailer (bool): Repeated retailer.
        used_chip (bool): Used chip.
        used_pin_number (bool): Used PIN number.
        online_order (bool): Online order.

    Returns:
        str: Prediction result ("Fraudulent" or "Non-fraudulent").
    """
    try:
        input_data = {
            "distance_from_home": distance_from_home,
            "distance_from_last_transaction": distance_from_last_transaction,
            "ratio_to_median_purchase_price": ratio_to_median_purchase_price,
            "repeat_retailer": int(repeat_retailer),
            "used_chip": int(used_chip),
            "used_pin_number": int(used_pin_number),
            "online_order": int(online_order),
        }
        return predict(input_data)
    except Exception as e:
        return f"Unexpected error: {e}"

# Gradio user interface
iface = gr.Interface(
    fn=make_prediction,
    inputs=[
        gr.Number(label="Distance from Home"),
        gr.Number(label="Distance from Last Transaction"),
        gr.Number(label="Ratio to Median Purchase Price"),
        gr.Checkbox(label="Repeat Retailer"),
        gr.Checkbox(label="Used Chip"),
        gr.Checkbox(label="Used PIN Number"),
        gr.Checkbox(label="Online Order"),
    ],
    outputs="text",
    title="Fraud Detection with Local FHE Model",
    description="Local interface using a compiled FHE model to detect fraud."
)

if __name__ == "__main__":
    iface.launch()