File size: 1,353 Bytes
89f28de
 
76c9d7a
 
3993b73
89f28de
 
 
 
 
3993b73
 
 
 
76c9d7a
5c36e3d
 
 
76c9d7a
 
5c36e3d
76c9d7a
 
 
5c36e3d
 
76c9d7a
 
 
 
89f28de
 
 
 
 
 
 
 
 
 
76c9d7a
 
 
 
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
import os
import subprocess
import gradio as gr

# Ensure model is trained
if not (os.path.exists("model/model.pkl") and os.path.exists("model/encoders.pkl")):
    print("Model files not found. Training model...")
    os.makedirs("model", exist_ok=True)
    subprocess.run(["python", "train.py"], check=True)

# ✅ Import AFTER model is guaranteed to exist
from predict import predict_transaction

# Gradio UI
def predict_ui(check_id, employee_id, total, discount_amount, item_count, time, terminal_id):
    if not employee_id or not time or not terminal_id:
        return "Please provide all required fields."

    return predict_transaction({
        "check_id": check_id,
        "employee_id": employee_id.strip(),
        "total": total,
        "discount_amount": discount_amount,
        "item_count": item_count,
        "time": time.strip(),
        "terminal_id": terminal_id.strip()
    })

demo = gr.Interface(
    fn=predict_ui,
    inputs=[
        gr.Number(label="Check ID"),
        gr.Text(label="Employee ID"),
        gr.Number(label="Total"),
        gr.Number(label="Discount Amount"),
        gr.Number(label="Item Count"),
        gr.Text(label="Time (HH:MM)"),
        gr.Text(label="Terminal ID"),
    ],
    outputs=gr.Text(label="Suspicious (1=True, 0=False)"),
    title="Suspicious Transaction Detector"
)

demo.launch()