dschandra commited on
Commit
9982e81
·
verified ·
1 Parent(s): b5e6606

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -1,21 +1,28 @@
1
  import gradio as gr
2
- import json
3
- from model.anomaly_detector import detect_anomaly
4
 
5
- def process_input(json_input):
6
- try:
7
- input_data = json.loads(json_input)
8
- result = detect_anomaly(input_data)
9
- return json.dumps(result, indent=2)
10
- except Exception as e:
11
- return f"Error: {str(e)}"
 
 
12
 
13
  iface = gr.Interface(
14
- fn=process_input,
15
- inputs=gr.Textbox(label="Input JSON", lines=10, placeholder='Paste agent data in JSON format'),
16
- outputs="text",
 
 
 
 
 
 
17
  title="Agent Behavior Anomaly Detector",
18
- description="Detects abnormal agent behavior using Isolation Forest"
19
  )
20
 
21
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from model.anomaly_detector import detect_anomaly_plain_text
 
3
 
4
+ def predict(agent_id, weekly_calls, missed_visits, travel_distance, lead_drop_rate):
5
+ input_data = {
6
+ "agent_id": agent_id,
7
+ "weekly_calls": weekly_calls,
8
+ "missed_visits": missed_visits,
9
+ "travel_distance": travel_distance,
10
+ "lead_drop_rate": lead_drop_rate
11
+ }
12
+ return detect_anomaly_plain_text(input_data)
13
 
14
  iface = gr.Interface(
15
+ fn=predict,
16
+ inputs=[
17
+ gr.Textbox(label="Agent ID", placeholder="e.g., AG1541"),
18
+ gr.Slider(0, 20, step=1, label="Weekly Calls"),
19
+ gr.Slider(0, 20, step=1, label="Missed Visits"),
20
+ gr.Slider(0, 100, step=1, label="Travel Distance (km)"),
21
+ gr.Slider(0.0, 1.0, step=0.01, label="Lead Drop Rate")
22
+ ],
23
+ outputs=gr.Textbox(label="Analysis Result"),
24
  title="Agent Behavior Anomaly Detector",
25
+ description="Detects anomalies in agent behavior and provides reason in plain English."
26
  )
27
 
28
  if __name__ == "__main__":