Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,15 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from predict import predict_transaction
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def predict_ui(check_id, employee_id, total, discount_amount, item_count, time, terminal_id):
|
5 |
return predict_transaction({
|
6 |
"check_id": check_id,
|
@@ -14,8 +23,16 @@ def predict_ui(check_id, employee_id, total, discount_amount, item_count, time,
|
|
14 |
|
15 |
demo = gr.Interface(
|
16 |
fn=predict_ui,
|
17 |
-
inputs=[
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
title="Suspicious Transaction Detector"
|
20 |
)
|
21 |
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
import gradio as gr
|
4 |
from predict import predict_transaction
|
5 |
|
6 |
+
# Ensure the model directory exists and model is trained
|
7 |
+
if not (os.path.exists("model/model.pkl") and os.path.exists("model/encoders.pkl")):
|
8 |
+
print("Model files not found. Training model...")
|
9 |
+
os.makedirs("model", exist_ok=True)
|
10 |
+
subprocess.run(["python", "train.py"], check=True)
|
11 |
+
|
12 |
+
# Gradio UI wrapper
|
13 |
def predict_ui(check_id, employee_id, total, discount_amount, item_count, time, terminal_id):
|
14 |
return predict_transaction({
|
15 |
"check_id": check_id,
|
|
|
23 |
|
24 |
demo = gr.Interface(
|
25 |
fn=predict_ui,
|
26 |
+
inputs=[
|
27 |
+
gr.Number(label="Check ID"),
|
28 |
+
gr.Text(label="Employee ID"),
|
29 |
+
gr.Number(label="Total"),
|
30 |
+
gr.Number(label="Discount Amount"),
|
31 |
+
gr.Number(label="Item Count"),
|
32 |
+
gr.Text(label="Time (HH:MM)"),
|
33 |
+
gr.Text(label="Terminal ID"),
|
34 |
+
],
|
35 |
+
outputs=gr.Text(label="Suspicious (1=True, 0=False)"),
|
36 |
title="Suspicious Transaction Detector"
|
37 |
)
|
38 |
|