Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,13 +26,6 @@ detection_model = YOLO(best_yolo_model, task='detect')
|
|
| 26 |
|
| 27 |
|
| 28 |
# Define the image preprocessing function
|
| 29 |
-
def preprocess_imageXX(image):
|
| 30 |
-
image = image.resize((224, 224)) # Resize to the input size of ResNet50
|
| 31 |
-
image = np.array(image) # Convert to numpy array
|
| 32 |
-
image = preprocess_input(image) # Preprocess for ResNet50
|
| 33 |
-
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 34 |
-
return image
|
| 35 |
-
|
| 36 |
def preprocess_image(pilimg):
|
| 37 |
img = pilimg.resize((224, 224)) # Resize to the input size of ResNet50
|
| 38 |
img_array = image.img_to_array(img)
|
|
@@ -69,7 +62,7 @@ def process_image(pilimg):
|
|
| 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
|
|
@@ -82,7 +75,7 @@ def process_image(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((
|
| 86 |
|
| 87 |
detections = detection_result[0].boxes.data # Get detections
|
| 88 |
if len(detections) > 0:
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
# Define the image preprocessing function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def preprocess_image(pilimg):
|
| 30 |
img = pilimg.resize((224, 224)) # Resize to the input size of ResNet50
|
| 31 |
img_array = image.img_to_array(img)
|
|
|
|
| 62 |
#font = ImageFont.truetype("arialbd.ttf", 30) # Use arial.ttf for bold font
|
| 63 |
|
| 64 |
draw.text((250, 10), "Good", fill="green", font=font)
|
| 65 |
+
#gr.Info("No defect detected, GOOD!", duration=3)
|
| 66 |
summary_str = "No defect is detected, the cap is GOOD!"
|
| 67 |
|
| 68 |
else: # Defective
|
|
|
|
| 75 |
font = ImageFont.truetype(font_path, 30)
|
| 76 |
#font = ImageFont.truetype("arialbd.ttf", 30) # Use arial.ttf for bold font
|
| 77 |
|
| 78 |
+
draw.text((300, 10), "Defective", fill="red", font=font)
|
| 79 |
|
| 80 |
detections = detection_result[0].boxes.data # Get detections
|
| 81 |
if len(detections) > 0:
|