Upload handler.py
Browse files- handler.py +11 -0
handler.py
CHANGED
@@ -6,6 +6,8 @@ import base64
|
|
6 |
from ultralytics import YOLO
|
7 |
import os
|
8 |
import gdown
|
|
|
|
|
9 |
|
10 |
class EndpointHandler:
|
11 |
def __init__(self, path='.'): # pass api key to model
|
@@ -72,6 +74,15 @@ class EndpointHandler:
|
|
72 |
cv2.imwrite("result.jpg", clothes)
|
73 |
# create base 64 object
|
74 |
jpg_as_text = base64.b64encode(buffer).decode("utf-8") # Decode bytes to string")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
print("checkpoint 4")
|
76 |
###########################################################################
|
77 |
return jpg_as_text
|
|
|
6 |
from ultralytics import YOLO
|
7 |
import os
|
8 |
import gdown
|
9 |
+
from PIL import Image
|
10 |
+
import io
|
11 |
|
12 |
class EndpointHandler:
|
13 |
def __init__(self, path='.'): # pass api key to model
|
|
|
74 |
cv2.imwrite("result.jpg", clothes)
|
75 |
# create base 64 object
|
76 |
jpg_as_text = base64.b64encode(buffer).decode("utf-8") # Decode bytes to string")
|
77 |
+
# base64_encoded = base64.b64encode(image_bytes).decode("utf-8")
|
78 |
+
|
79 |
+
# Get the image format
|
80 |
+
image_format = Image.open(io.BytesIO(buffer)).format.lower()
|
81 |
+
|
82 |
+
# Construct the data URI
|
83 |
+
data_uri = f"data:image/{image_format};base64,{jpg_as_text}"
|
84 |
+
|
85 |
+
return data_uri
|
86 |
print("checkpoint 4")
|
87 |
###########################################################################
|
88 |
return jpg_as_text
|