Spaces:
Running
Running
P01yH3dr0n
commited on
Commit
•
6c62d51
1
Parent(s):
42979db
Update utils.py
Browse files
utils.py
CHANGED
@@ -5,7 +5,7 @@ import requests
|
|
5 |
import json
|
6 |
import base64
|
7 |
|
8 |
-
from PIL import Image
|
9 |
|
10 |
|
11 |
jwt_token = ''
|
@@ -91,7 +91,7 @@ def generate_novelai_image(
|
|
91 |
if selection == 'inp' and inp_img['background'].getextrema()[3][1] > 0:
|
92 |
payload['action'] = "infill"
|
93 |
payload['model'] = 'nai-diffusion-3-inpainting'
|
94 |
-
payload['parameters']['mask'] = image2base64(
|
95 |
payload['parameters']['image'] = image2base64(inp_img['background'])
|
96 |
payload['parameters']['extra_noise_seed'] = seed
|
97 |
if i2i_image is not None and selection == 'i2i':
|
@@ -131,4 +131,10 @@ def image2base64(img):
|
|
131 |
img.save(output_buffer, format='PNG' if img.mode=='RGBA' else 'JPEG')
|
132 |
byte_data = output_buffer.getvalue()
|
133 |
base64_str = base64.b64encode(byte_data).decode()
|
134 |
-
return base64_str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import json
|
6 |
import base64
|
7 |
|
8 |
+
from PIL import Image
|
9 |
|
10 |
|
11 |
jwt_token = ''
|
|
|
91 |
if selection == 'inp' and inp_img['background'].getextrema()[3][1] > 0:
|
92 |
payload['action'] = "infill"
|
93 |
payload['model'] = 'nai-diffusion-3-inpainting'
|
94 |
+
payload['parameters']['mask'] = image2base64(convert_mask(inp_img['layers'][0]))
|
95 |
payload['parameters']['image'] = image2base64(inp_img['background'])
|
96 |
payload['parameters']['extra_noise_seed'] = seed
|
97 |
if i2i_image is not None and selection == 'i2i':
|
|
|
131 |
img.save(output_buffer, format='PNG' if img.mode=='RGBA' else 'JPEG')
|
132 |
byte_data = output_buffer.getvalue()
|
133 |
base64_str = base64.b64encode(byte_data).decode()
|
134 |
+
return base64_str
|
135 |
+
|
136 |
+
def convert_mask(img):
|
137 |
+
a = img.split()[3]
|
138 |
+
base = Image.new('RGB', img.size, 'white')
|
139 |
+
base.putalpha(a)
|
140 |
+
return base
|