Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,32 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import DetrImageProcessor, DetrForObjectDetection
|
3 |
-
import torch
|
4 |
import cv2
|
5 |
-
|
6 |
-
from
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
10 |
-
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
11 |
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
break
|
20 |
-
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
21 |
-
inputs = processor(images=image, return_tensors="pt")
|
22 |
-
outputs = model(**inputs)
|
23 |
-
target_sizes = torch.tensor([image.size[::-1]])
|
24 |
-
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
|
25 |
-
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
26 |
-
label_name = model.config.id2label[label.item()]
|
27 |
-
if label_name == "person":
|
28 |
-
alerts.append(f"Frame {count}: 🔴 Person Detected!")
|
29 |
-
break
|
30 |
-
count += 1
|
31 |
-
cap.release()
|
32 |
-
return "\n".join(alerts) if alerts else "✅ No intrusion detected."
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
-
|
43 |
-
inputs=gr.Video(label="Upload Video"),
|
44 |
-
outputs=gr.Textbox(label="Intrusion Detection Alerts"))
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
gr.Number(label="Humidity (%)"),
|
49 |
-
gr.Number(label="Solar Output (W)")],
|
50 |
-
outputs=gr.Textbox(label="Sensor Fault Detection"))
|
51 |
-
|
52 |
-
gr.TabbedInterface([video_tab, sensor_tab], ["Intrusion (Video)", "Sensor (Input)"]).launch()
|
53 |
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
2 |
import cv2
|
3 |
+
from services.video_service import get_video_frame
|
4 |
+
from services.detection_service import detect_objects
|
5 |
+
from services.thermal_service import detect_thermal_anomalies
|
6 |
+
from services.shadow_detection import detect_shadow_coverage
|
7 |
+
from services.salesforce_dispatcher import send_to_salesforce
|
8 |
|
9 |
+
frame_gen = get_video_frame("data/drone_day.mp4")
|
|
|
|
|
10 |
|
11 |
+
def monitor_feed():
|
12 |
+
try:
|
13 |
+
frame = next(frame_gen)
|
14 |
+
cv2.imwrite("temp.jpg", frame)
|
15 |
+
detections = detect_objects("temp.jpg")
|
16 |
+
thermal = detect_thermal_anomalies("temp.jpg")
|
17 |
+
shadow_flag = detect_shadow_coverage("temp.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
alert_payload = {
|
20 |
+
"detections": detections,
|
21 |
+
"thermal": bool(thermal),
|
22 |
+
"shadow_issue": shadow_flag,
|
23 |
+
}
|
24 |
+
send_to_salesforce(alert_payload)
|
25 |
+
return frame
|
26 |
+
except StopIteration:
|
27 |
|
28 |
+
return None
|
|
|
|
|
29 |
|
30 |
+
iface = gr.Interface(fn=monitor_feed, inputs=[], outputs="image", live=True, title="Solar
|
31 |
+
Surveillance Feed Simulation")
|
|
|
|
|
|
|
|
|
|
|
32 |
|