Spaces:
Paused
Paused
P01yH3dr0n
commited on
Commit
•
f5f05d8
1
Parent(s):
0933690
Update utils.py
Browse files
utils.py
CHANGED
@@ -3,6 +3,7 @@ import io
|
|
3 |
import zipfile
|
4 |
import requests
|
5 |
import json
|
|
|
6 |
|
7 |
from PIL import Image
|
8 |
|
@@ -38,6 +39,12 @@ def generate_novelai_image(
|
|
38 |
dyn=False,
|
39 |
dyn_threshold=False,
|
40 |
cfg_rescale=0,
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
):
|
42 |
# Assign a random seed if seed is -1
|
43 |
if seed == -1:
|
@@ -56,21 +63,32 @@ def generate_novelai_image(
|
|
56 |
"steps": steps,
|
57 |
"n_samples": 1,
|
58 |
"ucPreset": 0,
|
59 |
-
"add_original_image":
|
60 |
"cfg_rescale": cfg_rescale,
|
61 |
"controlnet_strength": 1,
|
62 |
"dynamic_thresholding": dyn_threshold,
|
|
|
63 |
"legacy": False,
|
|
|
64 |
"negative_prompt": negative_prompt,
|
|
|
65 |
"noise_schedule": schedule,
|
66 |
"qualityToggle": True,
|
|
|
|
|
67 |
"seed": seed,
|
68 |
"sm": smea,
|
69 |
"sm_dyn": dyn,
|
70 |
"uncond_scale": 1,
|
71 |
}
|
72 |
}
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# Send the POST request
|
75 |
response = requests.post(url, json=payload, headers=headers)
|
76 |
|
@@ -93,4 +111,11 @@ def generate_novelai_image(
|
|
93 |
def image_from_bytes(data):
|
94 |
img_file = io.BytesIO(data)
|
95 |
img_file.seek(0)
|
96 |
-
return Image.open(img_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import zipfile
|
4 |
import requests
|
5 |
import json
|
6 |
+
import base64
|
7 |
|
8 |
from PIL import Image
|
9 |
|
|
|
39 |
dyn=False,
|
40 |
dyn_threshold=False,
|
41 |
cfg_rescale=0,
|
42 |
+
ref_image=None,
|
43 |
+
info_extract=1,
|
44 |
+
ref_str=0.6,
|
45 |
+
inp_img=None,
|
46 |
+
overlay=False,
|
47 |
+
use_inp=False
|
48 |
):
|
49 |
# Assign a random seed if seed is -1
|
50 |
if seed == -1:
|
|
|
63 |
"steps": steps,
|
64 |
"n_samples": 1,
|
65 |
"ucPreset": 0,
|
66 |
+
"add_original_image": overlay,
|
67 |
"cfg_rescale": cfg_rescale,
|
68 |
"controlnet_strength": 1,
|
69 |
"dynamic_thresholding": dyn_threshold,
|
70 |
+
"params_version": 1,
|
71 |
"legacy": False,
|
72 |
+
"legacy_v3_extend": False,
|
73 |
"negative_prompt": negative_prompt,
|
74 |
+
"noise": 0,
|
75 |
"noise_schedule": schedule,
|
76 |
"qualityToggle": True,
|
77 |
+
"reference_information_extracted": 1,
|
78 |
+
"reference_strength": 0.6,
|
79 |
"seed": seed,
|
80 |
"sm": smea,
|
81 |
"sm_dyn": dyn,
|
82 |
"uncond_scale": 1,
|
83 |
}
|
84 |
}
|
85 |
+
if ref_image is not None:
|
86 |
+
payload['parameters']['reference_image'] = image2base64(ref_image)
|
87 |
+
if use_inp:
|
88 |
+
payload['action'] = "infill"
|
89 |
+
payload['model'] = 'nai-diffusion-3-inpaint'
|
90 |
+
payload['parameters']['mask'] = image2base64(inp_img['layers'][0])
|
91 |
+
payload['parameters']['image'] = image2base64(inp_img['background'])
|
92 |
# Send the POST request
|
93 |
response = requests.post(url, json=payload, headers=headers)
|
94 |
|
|
|
111 |
def image_from_bytes(data):
|
112 |
img_file = io.BytesIO(data)
|
113 |
img_file.seek(0)
|
114 |
+
return Image.open(img_file)
|
115 |
+
|
116 |
+
def image2base64(img):
|
117 |
+
output_buffer = io.BytesIO()
|
118 |
+
img.save(output_buffer, format='PNG' if img.mode=='RGBA' else 'JPEG')
|
119 |
+
byte_data = output_buffer.getvalue()
|
120 |
+
base64_str = base64.b64encode(byte_data).decode()
|
121 |
+
return base64_str
|