Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,9 +18,9 @@ class_names = {
|
|
| 18 |
5: "Copper",
|
| 19 |
} if not model.names else model.names # Use model.names if available
|
| 20 |
|
| 21 |
-
def detect_pcb_faults(image):
|
| 22 |
-
"""Runs YOLOv8 on the input image
|
| 23 |
-
results = model(image, conf=
|
| 24 |
|
| 25 |
boxes = results[0].boxes.xyxy.cpu().numpy() # Extract bounding boxes
|
| 26 |
confs = results[0].boxes.conf.cpu().numpy() # Extract confidence scores
|
|
@@ -38,11 +38,14 @@ def detect_pcb_faults(image):
|
|
| 38 |
|
| 39 |
return image
|
| 40 |
|
| 41 |
-
# ✅ Gradio UI
|
| 42 |
gr.Interface(
|
| 43 |
fn=detect_pcb_faults,
|
| 44 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 45 |
outputs=gr.Image(type="numpy"),
|
| 46 |
title="PCB Fault Detection",
|
| 47 |
-
description="Upload a PCB image to detect defects using YOLOv8.
|
| 48 |
).launch()
|
|
|
|
| 18 |
5: "Copper",
|
| 19 |
} if not model.names else model.names # Use model.names if available
|
| 20 |
|
| 21 |
+
def detect_pcb_faults(image, conf_threshold):
|
| 22 |
+
"""Runs YOLOv8 on the input image with an adjustable confidence threshold."""
|
| 23 |
+
results = model(image, conf=conf_threshold) # 🔥 Adjustable confidence
|
| 24 |
|
| 25 |
boxes = results[0].boxes.xyxy.cpu().numpy() # Extract bounding boxes
|
| 26 |
confs = results[0].boxes.conf.cpu().numpy() # Extract confidence scores
|
|
|
|
| 38 |
|
| 39 |
return image
|
| 40 |
|
| 41 |
+
# ✅ Gradio UI with Confidence Threshold Slider
|
| 42 |
gr.Interface(
|
| 43 |
fn=detect_pcb_faults,
|
| 44 |
+
inputs=[
|
| 45 |
+
gr.Image(type="numpy"),
|
| 46 |
+
gr.Slider(minimum=0.1, maximum=0.9, value=0.18, label="Confidence Threshold")
|
| 47 |
+
],
|
| 48 |
outputs=gr.Image(type="numpy"),
|
| 49 |
title="PCB Fault Detection",
|
| 50 |
+
description="Upload a PCB image to detect defects using YOLOv8. Adjust the confidence threshold to fine-tune detections."
|
| 51 |
).launch()
|