|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") |
|
|
|
|
|
|
|
|
def classify_event(text): |
|
|
safe_keywords = ["janitor", "maintenance", "cleaning", "mopping", "scheduled", "authorized personnel"] |
|
|
if any(keyword in text.lower() for keyword in safe_keywords): |
|
|
return "Prediction: Normal Activity (manually classified: routine task)" |
|
|
|
|
|
result = classifier(text)[0] |
|
|
label = result['label'] |
|
|
score = result['score'] |
|
|
classification = "Suspicious Behavior" if label == "NEGATIVE" and score > 0.7 else "Normal Activity" |
|
|
return f"Prediction: {classification} ({label} - confidence {score:.2f})" |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
|
|
gr.Image( |
|
|
value="anomalyvisionagent.png", |
|
|
label=None, |
|
|
show_label=False, |
|
|
show_download_button=False, |
|
|
container=False, |
|
|
width=800 |
|
|
) |
|
|
|
|
|
|
|
|
gr.Markdown("## AnomalyVision Trainer\nAn AI agent that classifies surveillance event descriptions into suspicious or normal behavior using Hugging Face Transformers.") |
|
|
|
|
|
|
|
|
with gr.Row(): |
|
|
input_box = gr.Textbox(lines=4, placeholder="Describe the surveillance event here...", label="Event Description") |
|
|
|
|
|
output_box = gr.Text(label="Classification") |
|
|
submit_btn = gr.Button("Submit") |
|
|
submit_btn.click(fn=classify_event, inputs=input_box, outputs=output_box) |
|
|
|
|
|
|
|
|
gr.Examples( |
|
|
examples=[ |
|
|
["A person is standing at the emergency exit for 20 minutes"], |
|
|
["An unknown bag left near the main lobby unattended"], |
|
|
["Two staff members chatting during break in cafeteria"], |
|
|
["A janitor is cleaning the hallway with a mop and cart during scheduled maintenance hours"], |
|
|
["A car drove into the loading dock after hours without a badge"] |
|
|
], |
|
|
inputs=input_box |
|
|
) |
|
|
|
|
|
|
|
|
gr.HTML( |
|
|
""" |
|
|
<div style="margin-top: 30px; text-align: center; font-size: 14px; color: #666;"> |
|
|
Built with π‘ by |
|
|
<a href="https://huggingface.co/GeetaAIVisionary" target="_blank" style="text-decoration: none; color: #0072b1; font-weight: bold;"> |
|
|
GeetaAIVisionary |
|
|
</a> |
|
|
<a href="https://www.linkedin.com/in/geetakudumula" target="_blank" style="margin-left: 8px;"> |
|
|
<img src="https://cdn.jsdelivr.net/gh/simple-icons/simple-icons/icons/linkedin.svg" width="16" height="16" alt="LinkedIn" style="vertical-align: text-bottom; filter: invert(26%) sepia(68%) saturate(727%) hue-rotate(180deg) brightness(93%) contrast(90%);"> |
|
|
</a> |
|
|
</div> |
|
|
""" |
|
|
) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|