sakthi54321 commited on
Commit
8e3fd6b
·
verified ·
1 Parent(s): 643b80a

requirements.tx

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from ultralytics import YOLO
3
+ import cv2
4
+ import numpy as np
5
+ import gradio as gr
6
+
7
+ # ✅ Load YOLOv8 model from Hugging Face
8
+ model_path = "https://huggingface.co/Sakthi3214/pcb_detection/resolve/main/best.pt"
9
+ model = YOLO(model_path)
10
+
11
+ def detect_pcb_faults(image):
12
+ """Runs YOLOv8 on the input image and returns detected objects."""
13
+ results = model(image) # Run inference
14
+ boxes = results[0].boxes.xyxy.cpu().numpy() # Extract bounding boxes
15
+ confs = results[0].boxes.conf.cpu().numpy() # Extract confidence scores
16
+
17
+ # Draw bounding boxes
18
+ for (x1, y1, x2, y2), conf in zip(boxes, confs):
19
+ cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2)
20
+ cv2.putText(image, f"{conf:.2f}", (int(x1), int(y1) - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
21
+
22
+ return image
23
+
24
+ # ✅ Gradio UI
25
+ gr.Interface(
26
+ fn=detect_pcb_faults,
27
+ inputs=gr.Image(type="numpy"),
28
+ outputs=gr.Image(type="numpy"),
29
+ title="PCB Fault Detection",
30
+ description="Upload a PCB image to detect defects using YOLOv8."
31
+ ).launch()