Commit ae820236 authored by kurumuz's avatar kurumuz

add tracebacks

parent fd351764
import traceback
from dotmap import DotMap from dotmap import DotMap
import math import math
from io import BytesIO from io import BytesIO
import base64 import base64
traceback
v1pp_defaults = { v1pp_defaults = {
'steps': 50, 'steps': 50,
...@@ -97,8 +99,9 @@ def sanitize_stable_diffusion(request): ...@@ -97,8 +99,9 @@ def sanitize_stable_diffusion(request):
#decode from base64 #decode from base64
try: try:
request.image = base64.b64decode(request.image.encode('utf-8')) request.image = base64.b64decode(request.image.encode('utf-8'))
except Exception as e: except Exception as e:
traceback.print_exc()
return False, "image is not valid base64" return False, "image is not valid base64"
#check if image is valid #check if image is valid
try: try:
...@@ -107,13 +110,18 @@ def sanitize_stable_diffusion(request): ...@@ -107,13 +110,18 @@ def sanitize_stable_diffusion(request):
image.verify() image.verify()
except Exception as e: except Exception as e:
traceback.print_exc()
return False, "image is not valid" return False, "image is not valid"
#image is valid, load it again #image is valid, load it again(still check again, verify() can't be sure as it doesn't decode.)
image = Image.open(BytesIO(request.image)) try:
image = image.convert('RGB') image = Image.open(BytesIO(request.image))
image = image.resize((request.width, request.height), resample=Image.Resampling.LANCZOS) image = image.convert('RGB')
request.image = image 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 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