Tenefix commited on
Commit
630ff31
·
verified ·
1 Parent(s): 836fe82

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from predictor import predict
3
+
4
+ def make_prediction(distance_from_home, distance_from_last_transaction,
5
+ ratio_to_median_purchase_price, repeat_retailer,
6
+ used_chip, used_pin_number, online_order):
7
+ """
8
+ Prepares user input data and performs a local prediction.
9
+
10
+ Args:
11
+ distance_from_home (float): Distance from home.
12
+ distance_from_last_transaction (float): Distance from the last transaction.
13
+ ratio_to_median_purchase_price (float): Ratio to the median purchase price.
14
+ repeat_retailer (bool): Repeated retailer.
15
+ used_chip (bool): Used chip.
16
+ used_pin_number (bool): Used PIN number.
17
+ online_order (bool): Online order.
18
+
19
+ Returns:
20
+ str: Prediction result ("Fraudulent" or "Non-fraudulent").
21
+ """
22
+ try:
23
+ input_data = {
24
+ "distance_from_home": distance_from_home,
25
+ "distance_from_last_transaction": distance_from_last_transaction,
26
+ "ratio_to_median_purchase_price": ratio_to_median_purchase_price,
27
+ "repeat_retailer": int(repeat_retailer),
28
+ "used_chip": int(used_chip),
29
+ "used_pin_number": int(used_pin_number),
30
+ "online_order": int(online_order),
31
+ }
32
+ return predict(input_data)
33
+ except Exception as e:
34
+ return f"Unexpected error: {e}"
35
+
36
+ # Gradio user interface
37
+ iface = gr.Interface(
38
+ fn=make_prediction,
39
+ inputs=[
40
+ gr.Number(label="Distance from Home"),
41
+ gr.Number(label="Distance from Last Transaction"),
42
+ gr.Number(label="Ratio to Median Purchase Price"),
43
+ gr.Checkbox(label="Repeat Retailer"),
44
+ gr.Checkbox(label="Used Chip"),
45
+ gr.Checkbox(label="Used PIN Number"),
46
+ gr.Checkbox(label="Online Order"),
47
+ ],
48
+ outputs="text",
49
+ title="Fraud Detection with Local FHE Model",
50
+ description="Local interface using a compiled FHE model to detect fraud."
51
+ )
52
+
53
+ if __name__ == "__main__":
54
+ iface.launch()