import gradio as gr from transformers import pipeline # Load Hugging Face model classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") # Classification function 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})" # Build the Gradio app with gr.Blocks() as demo: # ✅ Properly rendered banner image (no HTML) gr.Image( value="anomalyvisionagent.png", label=None, show_label=False, show_download_button=False, container=False, width=800 ) # App header gr.Markdown("## AnomalyVision Trainer\nAn AI agent that classifies surveillance event descriptions into suspicious or normal behavior using Hugging Face Transformers.") # Input/output layout 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) # Example inputs 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 ) # Optional footer gr.HTML( """