GeetaAIVisionary commited on
Commit
8a1f91a
·
verified ·
1 Parent(s): e9f7228

added logic to train the model for sentiment

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -4,8 +4,16 @@ from transformers import pipeline
4
  # Load the Hugging Face text classification pipeline
5
  classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
- # Custom mapping based on classification score
8
  def classify_event(text):
 
 
 
 
 
 
 
 
9
  result = classifier(text)[0]
10
  label = result['label']
11
  score = result['score']
@@ -16,7 +24,8 @@ def classify_event(text):
16
  classification = "Normal Activity"
17
 
18
  return f"Prediction: {classification} ({label} - confidence {score:.2f})"
19
- # Gradio UI
 
20
  demo = gr.Interface(
21
  fn=classify_event,
22
  inputs=gr.Textbox(lines=4, placeholder="Describe the surveillance event here..."),
@@ -27,6 +36,7 @@ demo = gr.Interface(
27
  ["A person is standing at the emergency exit for 20 minutes"],
28
  ["An unknown bag left near the main lobby unattended"],
29
  ["Two staff members chatting during break in cafeteria"],
 
30
  ["A car drove into the loading dock after hours without a badge"]
31
  ]
32
  )
 
4
  # Load the Hugging Face text classification pipeline
5
  classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
+ # Enhanced classification logic with override for safe routines
8
  def classify_event(text):
9
+ # List of keywords that indicate normal activity
10
+ safe_keywords = ["janitor", "maintenance", "cleaning", "mopping", "scheduled", "authorized personnel"]
11
+
12
+ # Check if the input text contains any routine or safe keywords
13
+ if any(keyword in text.lower() for keyword in safe_keywords):
14
+ return "Prediction: Normal Activity (manually classified: routine task)"
15
+
16
+ # Otherwise, use the classifier
17
  result = classifier(text)[0]
18
  label = result['label']
19
  score = result['score']
 
24
  classification = "Normal Activity"
25
 
26
  return f"Prediction: {classification} ({label} - confidence {score:.2f})"
27
+
28
+ # Gradio Interface
29
  demo = gr.Interface(
30
  fn=classify_event,
31
  inputs=gr.Textbox(lines=4, placeholder="Describe the surveillance event here..."),
 
36
  ["A person is standing at the emergency exit for 20 minutes"],
37
  ["An unknown bag left near the main lobby unattended"],
38
  ["Two staff members chatting during break in cafeteria"],
39
+ ["A janitor is cleaning the hallway with a mop and cart during scheduled maintenance hours"],
40
  ["A car drove into the loading dock after hours without a badge"]
41
  ]
42
  )