Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
from __future__ import annotations
|
2 |
-
import pathlib
|
3 |
import io
|
4 |
import cv2
|
5 |
import gradio as gr
|
@@ -66,6 +65,9 @@ def extract_persons(image: np.ndarray, bboxes: np.ndarray) -> list[Image.Image]:
|
|
66 |
x1, y1, x2, y2 = bbox
|
67 |
person_image = image[y1:y2, x1:x2] # Crop the detected person
|
68 |
person_pil_image = Image.fromarray(person_image).convert('RGB') # Convert to RGB
|
|
|
|
|
|
|
69 |
person_images.append(person_pil_image)
|
70 |
return person_images
|
71 |
|
@@ -82,14 +84,10 @@ def detect(image: np.ndarray) -> tuple[Image.Image, list[Image.Image]]:
|
|
82 |
return Image.fromarray(res[:, :, ::-1], 'RGB'), person_images # BGR -> RGB
|
83 |
|
84 |
|
85 |
-
examples = sorted(pathlib.Path("images").glob("*.jpg"))
|
86 |
-
|
87 |
demo = gr.Interface(
|
88 |
fn=detect,
|
89 |
inputs=gr.Image(label="Input", type="numpy"),
|
90 |
outputs=[gr.Image(label="Processed Image", type="numpy"), gr.Gallery(label="Detected Persons", type="numpy")],
|
91 |
-
examples=examples,
|
92 |
-
examples_per_page=30,
|
93 |
title=TITLE,
|
94 |
description=DESCRIPTION,
|
95 |
)
|
|
|
1 |
from __future__ import annotations
|
|
|
2 |
import io
|
3 |
import cv2
|
4 |
import gradio as gr
|
|
|
65 |
x1, y1, x2, y2 = bbox
|
66 |
person_image = image[y1:y2, x1:x2] # Crop the detected person
|
67 |
person_pil_image = Image.fromarray(person_image).convert('RGB') # Convert to RGB
|
68 |
+
with io.BytesIO() as output:
|
69 |
+
person_pil_image.save(output, format='JPEG') # Convert to JPEG
|
70 |
+
person_pil_image = Image.open(output) # Reopen to ensure format
|
71 |
person_images.append(person_pil_image)
|
72 |
return person_images
|
73 |
|
|
|
84 |
return Image.fromarray(res[:, :, ::-1], 'RGB'), person_images # BGR -> RGB
|
85 |
|
86 |
|
|
|
|
|
87 |
demo = gr.Interface(
|
88 |
fn=detect,
|
89 |
inputs=gr.Image(label="Input", type="numpy"),
|
90 |
outputs=[gr.Image(label="Processed Image", type="numpy"), gr.Gallery(label="Detected Persons", type="numpy")],
|
|
|
|
|
91 |
title=TITLE,
|
92 |
description=DESCRIPTION,
|
93 |
)
|