LapStore commited on
Commit ·
b68e332
1
Parent(s): a82c1e0
make better error handling
Browse files
app.py
CHANGED
|
@@ -65,8 +65,15 @@ async def image_step1(image_file: UploadFile = File(...),background_image: Optio
|
|
| 65 |
image = Image.open(io.BytesIO(contents_img))
|
| 66 |
|
| 67 |
|
| 68 |
-
output_step1=SegmenterBackground().Back_step1(image,input_to_type_of_filters,int(blur_radius))
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
'''
|
| 72 |
# Save the processed image to a temporary file
|
|
@@ -83,7 +90,8 @@ async def image_step1(image_file: UploadFile = File(...),background_image: Optio
|
|
| 83 |
# Returning both text and the base64 image
|
| 84 |
return {
|
| 85 |
"message": output_step1[1],
|
| 86 |
-
"image_base64": encoded_img
|
|
|
|
| 87 |
}
|
| 88 |
|
| 89 |
|
|
|
|
| 65 |
image = Image.open(io.BytesIO(contents_img))
|
| 66 |
|
| 67 |
|
| 68 |
+
output_step1 =SegmenterBackground().Back_step1(image,input_to_type_of_filters,int(blur_radius))
|
| 69 |
+
|
| 70 |
+
if (output_step1[-1] == 0):
|
| 71 |
+
return {
|
| 72 |
+
"Error": output_step1[0],
|
| 73 |
+
"status": output_step1[-1]
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
produced_image = output_step1[0]
|
| 77 |
|
| 78 |
'''
|
| 79 |
# Save the processed image to a temporary file
|
|
|
|
| 90 |
# Returning both text and the base64 image
|
| 91 |
return {
|
| 92 |
"message": output_step1[1],
|
| 93 |
+
"image_base64": encoded_img,
|
| 94 |
+
"status": output_step1[-1]
|
| 95 |
}
|
| 96 |
|
| 97 |
|
server.py
CHANGED
|
@@ -98,6 +98,11 @@ class SegmenterBackground():
|
|
| 98 |
|
| 99 |
masks = [results[0].masks.data[i].cpu().numpy() for i in range(len(results[0].masks.data))]
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
##### put masks on image
|
| 102 |
outpt = self.putMaskImage(raw_image,masks,background_image,blur_radius)
|
| 103 |
|
|
@@ -123,7 +128,7 @@ class SegmenterBackground():
|
|
| 123 |
|
| 124 |
label_counter.append(current_label)
|
| 125 |
|
| 126 |
-
return outpt.resize(org_size), label_counter
|
| 127 |
|
| 128 |
|
| 129 |
def Back_step2(self,raw_image:Image,background_image:Image,things_replace:list,blur_radius=23):
|
|
|
|
| 98 |
|
| 99 |
masks = [results[0].masks.data[i].cpu().numpy() for i in range(len(results[0].masks.data))]
|
| 100 |
|
| 101 |
+
if len(masks)==0:
|
| 102 |
+
return ("No thing in image") ,0 # 0 error happened ,if so it's 2 returns ,first is message
|
| 103 |
+
|
| 104 |
+
#----------> other methods
|
| 105 |
+
|
| 106 |
##### put masks on image
|
| 107 |
outpt = self.putMaskImage(raw_image,masks,background_image,blur_radius)
|
| 108 |
|
|
|
|
| 128 |
|
| 129 |
label_counter.append(current_label)
|
| 130 |
|
| 131 |
+
return outpt.resize(org_size), label_counter , 1
|
| 132 |
|
| 133 |
|
| 134 |
def Back_step2(self,raw_image:Image,background_image:Image,things_replace:list,blur_radius=23):
|