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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -37
app.py CHANGED
@@ -1,37 +1,25 @@
1
- import gradio as gr
2
- import cv2
3
- import os, sys
4
-
5
- # ✅ Fix: Add services/ to path manually
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_gen = get_video_frame("data/sample_pole_video.mp4")
15
-
16
- def monitor_feed():
17
- try:
18
- frame = next(frame_gen)
19
- cv2.imwrite("temp.jpg", frame)
20
-
21
- detections = detect_objects("temp.jpg")
22
- thermal = detect_thermal_anomalies("temp.jpg")
23
- shadow_flag = detect_shadow_coverage("temp.jpg")
24
-
25
- alert_payload = {
26
- "detections": detections,
27
- "thermal": bool(thermal),
28
- "shadow_issue": shadow_flag,
29
- }
30
-
31
- send_to_salesforce(alert_payload)
32
- return frame
33
- except StopIteration:
34
- return None
35
-
36
- iface = gr.Interface(fn=monitor_feed, inputs=[], outputs="image", live=True, title="VIEP Smart Pole Video Fault Detector")
37
- iface.launch()
 
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)