gsbm commited on
Commit
ebbe4cc
·
verified ·
1 Parent(s): 1756ee0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -40,8 +40,7 @@ def generate_normal_map(image):
40
  return Image.fromarray(normal_map)
41
 
42
  def fix_base64_padding(base64_str):
43
- # Add padding if necessary
44
- return base64_str + "=" * ((4 - len(base64_str) % 4) % 4)
45
 
46
  def generate_image(
47
  prompt: str,
@@ -80,7 +79,10 @@ def generate_image(
80
  api_name="/run",
81
  )
82
  result = fix_base64_padding(result) # Fix the padding of the base64 string
83
- image_bytes = base64.b64decode(result)
 
 
 
84
  image = Image.open(BytesIO(image_bytes)) # Ensure the result is converted to a PIL Image
85
  normal_map = generate_normal_map(image)
86
  return image, normal_map
 
40
  return Image.fromarray(normal_map)
41
 
42
  def fix_base64_padding(base64_str):
43
+ return base64_str + "=" * (-len(base64_str) % 4)
 
44
 
45
  def generate_image(
46
  prompt: str,
 
79
  api_name="/run",
80
  )
81
  result = fix_base64_padding(result) # Fix the padding of the base64 string
82
+ try:
83
+ image_bytes = base64.b64decode(result)
84
+ except binascii.Error:
85
+ raise ValueError("Error decoding the Base64 string. Please check the input.")
86
  image = Image.open(BytesIO(image_bytes)) # Ensure the result is converted to a PIL Image
87
  normal_map = generate_normal_map(image)
88
  return image, normal_map