import os import subprocess import gradio as gr from predict import predict_transaction # Ensure the model directory exists and 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) # Gradio UI wrapper def predict_ui(check_id, employee_id, total, discount_amount, item_count, time, terminal_id): return predict_transaction({ "check_id": check_id, "employee_id": employee_id, "total": total, "discount_amount": discount_amount, "item_count": item_count, "time": time, "terminal_id": terminal_id }) 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()