Prasanna1622 commited on
Commit
0c75867
·
verified ·
1 Parent(s): 35a6dad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -8,6 +8,15 @@ from ultralytics import YOLO
8
  # Download model if not present
9
  model_path ="best.pt"
10
 
 
 
 
 
 
 
 
 
 
11
  def detect_faults(video_path):
12
  try:
13
  # Generate unique run directory
@@ -50,18 +59,7 @@ def detect_faults(video_path):
50
  cap.release()
51
  out.release()
52
 
53
- # Return the output video path
54
- if os.path.exists(output_path):
55
- print(f"✅ Output saved at: {output_path}")
56
- return output_path
57
- else:
58
- print("❌ Output video not found.")
59
- return "Error: Annotated video not found."
60
-
61
- except Exception as e:
62
- print(f"❌ Exception during fault detection: {e}")
63
- return "Error during video fault detection."
64
-
65
  def detect_faults_in_image(image):
66
  try:
67
  results = model(image)
@@ -80,15 +78,19 @@ video_ui = gr.Interface(
80
  description="Upload a drone video of solar panels. The model detects faults and returns an annotated video."
81
  )
82
 
83
- image_ui = gr.Interface(
84
- fn=detect_faults_in_image,
85
- inputs=gr.Image(type="numpy", label="Upload Solar Panel Image"),
86
- outputs=gr.Image(label="Detected Faults in Image"),
87
- title="Solar Panel Fault Detection (Image)",
88
- description="Upload an image of a solar panel. The model highlights any detected faults."
 
89
  )
90
 
91
- app = gr.TabbedInterface([video_ui, image_ui], ["Video Detection", "Image Detection"])
 
 
 
92
 
93
  if __name__ == "__main__":
94
  app.launch()
 
8
  # Download model if not present
9
  model_path ="best.pt"
10
 
11
+ # Load YOLOv8 model
12
+ model = YOLO("best.pt")
13
+
14
+ def detect(image):
15
+ results = model(image)
16
+ annotated_image = results[0].plot() # draw boxes
17
+ return annotated_image
18
+
19
+
20
  def detect_faults(video_path):
21
  try:
22
  # Generate unique run directory
 
59
  cap.release()
60
  out.release()
61
 
62
+
 
 
 
 
 
 
 
 
 
 
 
63
  def detect_faults_in_image(image):
64
  try:
65
  results = model(image)
 
78
  description="Upload a drone video of solar panels. The model detects faults and returns an annotated video."
79
  )
80
 
81
+ # Gradio Interface
82
+ demo = gr.Interface(
83
+ fn=detect,
84
+ inputs=gr.Image(type="filepath", label="Upload an Image"),
85
+ outputs=gr.Image(type="numpy", label="Detected Output"),
86
+ title="Solar Panel Fault Detector - YOLOv8",
87
+ description="Upload a drone image of solar panels. YOLOv8 will detect any faults."
88
  )
89
 
90
+ demo.launch()
91
+
92
+
93
+ app = gr.TabbedInterface([image_ui, video_ui], ["Image Detection"], "Video Detection")
94
 
95
  if __name__ == "__main__":
96
  app.launch()