Sanjayraju30 commited on
Commit
1ef0f8e
·
verified ·
1 Parent(s): 79196ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -1,25 +1,43 @@
1
- # Import necessary libraries
2
- import warnings
3
- from ultralytics import YOLO # Ensure ultralytics is installed
4
- from transformers import pipeline, DetrImageProcessor
5
-
6
- # Suppress unnecessary warnings
7
- warnings.filterwarnings("ignore", message=".*copying from a non-meta parameter.*")
8
-
9
- # Setup the image processor
10
- processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50", use_fast=True)
11
-
12
- # Load the YOLO model (make sure ultralytics is installed)
13
- model = YOLO("yolov5s.pt") # Change to the model you are using
14
-
15
- # Your model inference or other operations
16
- # Example detection function
17
- def detect_objects(image):
18
- # Use your model for object detection
19
- results = model(image)
20
- return results
21
-
22
- # Call the function
23
- image = "path_to_image.jpg" # Replace with your image path
24
- detection_results = detect_objects(image)
25
- print(detection_results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os, sys
3
+ import cv2
4
+
5
+ # Ensure services is importable
6
+ sys.path.append(os.path.join(os.path.dirname(__file__), "services"))
7
+
8
+ from video_service import get_video_frame
9
+ from detection_service import detect_objects
10
+ from thermal_service import detect_thermal_anomalies
11
+ from shadow_detection import detect_shadow_coverage
12
+ from salesforce_dispatcher import send_to_salesforce
13
+
14
+ frame_generator = get_video_frame("data/sample_pole_video.mp4")
15
+
16
+ def detect_frame():
17
+ try:
18
+ frame = next(frame_generator)
19
+ temp_path = "temp.jpg"
20
+ cv2.imwrite(temp_path, frame)
21
+
22
+ objects = detect_objects(temp_path)
23
+ thermal = detect_thermal_anomalies(temp_path)
24
+ shadow = detect_shadow_coverage(temp_path)
25
+
26
+ alert = {
27
+ "detections": objects,
28
+ "thermal": bool(thermal),
29
+ "shadow_issue": shadow,
30
+ }
31
+
32
+ send_to_salesforce(alert)
33
+ return frame
34
+ except StopIteration:
35
+ return None
36
+
37
+ gr.Interface(
38
+ fn=detect_frame,
39
+ inputs=[],
40
+ outputs="image",
41
+ live=True,
42
+ title="VIEP Smart Pole Live Fault Detection"
43
+ ).launch()