Skip to content

Commit

Permalink
Scratch remove API image upscale flag add
Browse files Browse the repository at this point in the history
  • Loading branch information
aunyoni88 committed Dec 18, 2023
1 parent 3332c53 commit 06b7b1a
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions extensions/arifScratchRemoverWebUIExtention/scripts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ async def download_model(
@app.post('/sdapi/ai/v1/scratch_remove')
async def generate_mask_image(
input_image: str = Body("", title='scratch remove input image'),
image_name: str = Body("", title='input image name')
upscale: bool = Body(False, title='input image name')
):
utc_time = datetime.now(timezone.utc)
start_time = time.time()

downloadScratchRemoverModelModel()
pil_image = api.decode_base64_to_image(input_image)
image_base64_str = remove_scratch_using_mask(pil_image)
image_base64_str = remove_scratch_using_mask(pil_image, upscale)

end_time = time.time()
server_process_time = end_time - start_time
Expand All @@ -82,7 +82,7 @@ async def generate_mask_image(
"output_image": image_base64_str
}

def remove_scratch_using_mask(source_image: Image):
def remove_scratch_using_mask(source_image: Image, upscale : bool):
curDir = os.getcwd()
fileName = "arif.png"

Expand Down Expand Up @@ -138,11 +138,11 @@ def remove_scratch_using_mask(source_image: Image):
mask_image=main_mask
).images[0]
#return base64 image
# opencvImage = cv2.cvtColor(numpy.array(without_scratch_Image_output), cv2.COLOR_RGB2BGR)
# _, encoded_img = cv2.imencode('.jpg', opencvImage)
# img_str = base64.b64encode(encoded_img).decode("utf-8")
# return img_str

if upscale == False:
opencvImage = cv2.cvtColor(numpy.array(without_scratch_Image_output), cv2.COLOR_RGB2BGR)
_, encoded_img = cv2.imencode('.jpg', opencvImage)
img_str = base64.b64encode(encoded_img).decode("utf-8")
return img_str

args = scripts.scripts_postproc.create_args_for_run({
"Upscale": {
Expand All @@ -164,25 +164,12 @@ def remove_scratch_using_mask(source_image: Image):
},
})

# new_Image = postprocessing.run_postprocessing(0, without_scratch_Image_output, "", "", "", True, *args, save_output=False)
# opencvImage = cv2.cvtColor(numpy.array(new_Image), cv2.COLOR_RGB2BGR)
# _, encoded_img = cv2.imencode('.jpg', opencvImage)
# img_str = base64.b64encode(encoded_img).decode("utf-8")
result = postprocessing.run_postprocessing(0, without_scratch_Image_output, "", "", "", True, *args, save_output=False)
img_str = api.encode_pil_to_base64(result[0][0])
return img_str












def save_file(file: UploadFile, path: str):
with open(path, "wb+") as file_object:
shutil.copyfileobj(file.file, file_object)
Expand Down

0 comments on commit 06b7b1a

Please sign in to comment.