yekkala commited on
Commit
2ccf350
·
verified ·
1 Parent(s): 884fb1e

Upload 3 files

Browse files
Files changed (3) hide show
  1. gr.File.py +5 -0
  2. pil_image +22 -0
  3. pilot_graph +18 -0
gr.File.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ outputs=[
2
+ gr.Textbox(label="Fraud Probability"),
3
+ gr.File(label="Transaction Network Graph (PNG)"), # Use gr.File
4
+ gr.Textbox(label="Feature Importance Explanation"),
5
+ ]
pil_image ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ demo = gr.Interface(
2
+ fn=predict,
3
+ inputs=[
4
+ gr.Number(label="Transaction Amount", minimum=0),
5
+ gr.Number(label="Time of Day (24h)", minimum=0, maximum=24),
6
+ gr.Textbox(label="User Role", placeholder="e.g., CFO, AP"),
7
+ gr.Number(label="Keystroke Speed (WPM)", minimum=0),
8
+ gr.Number(label="Typing Error Rate", minimum=0, maximum=1),
9
+ ],
10
+ outputs=[
11
+ gr.Textbox(label="Fraud Probability"),
12
+ gr.Image(label="Transaction Network Graph"), # Accepts PIL Image
13
+ gr.Textbox(label="Feature Importance Explanation"),
14
+ ],
15
+ title="Fraud Detection with Behavioral Analytics",
16
+ description="Detects anomalies in transaction patterns using unsupervised learning and behavioral biometrics.",
17
+ examples=[
18
+ [5000, 23, "CFO", 25, 0.1],
19
+ [100, 9, "AP", 50, 0.01],
20
+ [20000, 20, "CFO", 20, 0.2]
21
+ ]
22
+ )
pilot_graph ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import io
3
+ import matplotlib.pyplot as plt
4
+
5
+ def plot_graph(self, G):
6
+ plt.figure(figsize=(3, 2))
7
+ nx.draw(G, with_labels=True, node_color="lightblue", font_weight="bold")
8
+ plt.axis("off")
9
+ plt.tight_layout()
10
+
11
+ # Save the figure to a BytesIO buffer
12
+ buf = io.BytesIO()
13
+ plt.savefig(buf, format="png")
14
+ plt.close()
15
+
16
+ # Load the image from the buffer into a PIL Image
17
+ image = Image.open(buf)
18
+ return image