Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,6 +56,8 @@ def detect_defect(img):
|
|
| 56 |
|
| 57 |
|
| 58 |
def process_image(pilimg):
|
|
|
|
|
|
|
| 59 |
# Perform classification first, then perform detection if Defective
|
| 60 |
classification = classify_image(pilimg)
|
| 61 |
|
|
@@ -67,7 +69,8 @@ def process_image(pilimg):
|
|
| 67 |
#font = ImageFont.truetype("arialbd.ttf", 30) # Use arial.ttf for bold font
|
| 68 |
|
| 69 |
draw.text((250, 10), "Good", fill="green", font=font)
|
| 70 |
-
gr.Info("No defect detected,GOOD!", duration=3)
|
|
|
|
| 71 |
|
| 72 |
else: # Defective
|
| 73 |
detection_result = detect_defect(pilimg)
|
|
@@ -79,21 +82,26 @@ def process_image(pilimg):
|
|
| 79 |
font = ImageFont.truetype(font_path, 30)
|
| 80 |
#font = ImageFont.truetype("arialbd.ttf", 30) # Use arial.ttf for bold font
|
| 81 |
|
| 82 |
-
draw.text((
|
| 83 |
|
| 84 |
detections = detection_result[0].boxes.data # Get detections
|
| 85 |
if len(detections) > 0:
|
| 86 |
-
gr.Warning("Defect detected, BAD!", duration=3)
|
|
|
|
| 87 |
else:
|
| 88 |
-
gr.Warning("Classified as Defective but defect cannot be detected, ERROR!")
|
|
|
|
| 89 |
|
| 90 |
-
return out_pilimg
|
| 91 |
|
| 92 |
-
title = "Detect the status of the cap
|
| 93 |
interface = gr.Interface(
|
| 94 |
fn=process_image,
|
| 95 |
inputs=gr.Image(type="pil", label="Input Image"),
|
| 96 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 97 |
title=title,
|
| 98 |
)
|
| 99 |
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
def process_image(pilimg):
|
| 59 |
+
summary_str = "" # summary variable
|
| 60 |
+
|
| 61 |
# Perform classification first, then perform detection if Defective
|
| 62 |
classification = classify_image(pilimg)
|
| 63 |
|
|
|
|
| 69 |
#font = ImageFont.truetype("arialbd.ttf", 30) # Use arial.ttf for bold font
|
| 70 |
|
| 71 |
draw.text((250, 10), "Good", fill="green", font=font)
|
| 72 |
+
#gr.Info("No defect detected,GOOD!", duration=3)
|
| 73 |
+
summary_str = "No defect is detected, the cap is GOOD!"
|
| 74 |
|
| 75 |
else: # Defective
|
| 76 |
detection_result = detect_defect(pilimg)
|
|
|
|
| 82 |
font = ImageFont.truetype(font_path, 30)
|
| 83 |
#font = ImageFont.truetype("arialbd.ttf", 30) # Use arial.ttf for bold font
|
| 84 |
|
| 85 |
+
draw.text((330, 10), "Defective", fill="red", font=font)
|
| 86 |
|
| 87 |
detections = detection_result[0].boxes.data # Get detections
|
| 88 |
if len(detections) > 0:
|
| 89 |
+
#gr.Warning("Defect detected, BAD!", duration=3)
|
| 90 |
+
summary_str = "Defect is detected, the cap is BAD"
|
| 91 |
else:
|
| 92 |
+
#gr.Warning("Classified as Defective but defect cannot be detected, ERROR!")
|
| 93 |
+
summary_str = "The cap is classifed as Defective but defect cannot be detected, ERROR!"
|
| 94 |
|
| 95 |
+
return out_pilimg, summary_str
|
| 96 |
|
| 97 |
+
title = "Detect the status of the cap: DEFECTIVE or GOOD"
|
| 98 |
interface = gr.Interface(
|
| 99 |
fn=process_image,
|
| 100 |
inputs=gr.Image(type="pil", label="Input Image"),
|
| 101 |
+
outputs=[
|
| 102 |
+
gr.Image(type="pil", label="Classification/Detection result"),
|
| 103 |
+
gr.Textbox(label="Classification/Detection Summary"),
|
| 104 |
+
],
|
| 105 |
title=title,
|
| 106 |
)
|
| 107 |
|