Commit ae820236 authored by kurumuz's avatar kurumuz

add tracebacks

parent fd351764
import traceback
from dotmap import DotMap
import math
from io import BytesIO
import base64
traceback
v1pp_defaults = {
'steps': 50,
......@@ -97,8 +99,9 @@ def sanitize_stable_diffusion(request):
#decode from base64
try:
request.image = base64.b64decode(request.image.encode('utf-8'))
except Exception as e:
traceback.print_exc()
return False, "image is not valid base64"
#check if image is valid
try:
......@@ -107,13 +110,18 @@ def sanitize_stable_diffusion(request):
image.verify()
except Exception as e:
traceback.print_exc()
return False, "image is not valid"
#image is valid, load it again
image = Image.open(BytesIO(request.image))
image = image.convert('RGB')
image = image.resize((request.width, request.height), resample=Image.Resampling.LANCZOS)
request.image = image
#image is valid, load it again(still check again, verify() can't be sure as it doesn't decode.)
try:
image = Image.open(BytesIO(request.image))
image = image.convert('RGB')
image = image.resize((request.width, request.height), resample=Image.Resampling.LANCZOS)
request.image = image
except Exception as e:
traceback.print_exc()
return False, "Error while opening and cleaning image"
return True, request
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment