Update handler.py
Browse files- handler.py +4 -7
handler.py
CHANGED
@@ -4,10 +4,9 @@ from io import BytesIO
|
|
4 |
from PIL import Image
|
5 |
from transparent_background import Remover
|
6 |
|
7 |
-
|
8 |
class EndpointHandler:
|
9 |
-
def __init__(self):
|
10 |
-
|
11 |
self.remover = Remover(mode='fast')
|
12 |
# Warm up the model with a dummy image.
|
13 |
dummy = Image.new("RGB", (256, 256), "white")
|
@@ -17,22 +16,20 @@ class EndpointHandler:
|
|
17 |
"""
|
18 |
Expects a dictionary (JSON) with keys:
|
19 |
- "images": a list of base64-encoded image strings (e.g. "data:image/png;base64,...")
|
20 |
-
- "output_type": one of "rgba", "map", "green", "blur",
|
21 |
- "threshold": a float (0.0 to 1.0)
|
22 |
- "reverse": a boolean flag
|
23 |
Returns a dictionary with:
|
24 |
- "images": list of processed images (base64-encoded with data URI prefix)
|
25 |
- "processing_times": a string with individual and total processing times
|
26 |
"""
|
27 |
-
# Get parameters from the request.
|
28 |
images_data = request.get("images", [])
|
29 |
output_type = request.get("output_type", "rgba")
|
30 |
-
threshold = request.get("threshold", 0.
|
31 |
reverse = request.get("reverse", False)
|
32 |
|
33 |
processed_results = []
|
34 |
times_list = []
|
35 |
-
|
36 |
global_start = time.time()
|
37 |
|
38 |
# Process up to 3 images
|
|
|
4 |
from PIL import Image
|
5 |
from transparent_background import Remover
|
6 |
|
|
|
7 |
class EndpointHandler:
|
8 |
+
def __init__(self, path=""):
|
9 |
+
self.path = path
|
10 |
self.remover = Remover(mode='fast')
|
11 |
# Warm up the model with a dummy image.
|
12 |
dummy = Image.new("RGB", (256, 256), "white")
|
|
|
16 |
"""
|
17 |
Expects a dictionary (JSON) with keys:
|
18 |
- "images": a list of base64-encoded image strings (e.g. "data:image/png;base64,...")
|
19 |
+
- "output_type": one of "rgba", "map", "green", "blur", "overlay"
|
20 |
- "threshold": a float (0.0 to 1.0)
|
21 |
- "reverse": a boolean flag
|
22 |
Returns a dictionary with:
|
23 |
- "images": list of processed images (base64-encoded with data URI prefix)
|
24 |
- "processing_times": a string with individual and total processing times
|
25 |
"""
|
|
|
26 |
images_data = request.get("images", [])
|
27 |
output_type = request.get("output_type", "rgba")
|
28 |
+
threshold = request.get("threshold", 0.0)
|
29 |
reverse = request.get("reverse", False)
|
30 |
|
31 |
processed_results = []
|
32 |
times_list = []
|
|
|
33 |
global_start = time.time()
|
34 |
|
35 |
# Process up to 3 images
|