k-l-lambda
commited on
Commit
•
bdec242
1
Parent(s):
97ebe70
upgraded novita_client to 0.5.0
Browse files- README.md +1 -1
- app.py +47 -68
- requirements.txt +1 -1
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 📈
|
|
4 |
colorFrom: indigo
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
4 |
colorFrom: indigo
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.19.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
CHANGED
@@ -7,7 +7,7 @@ import base64
|
|
7 |
from io import BytesIO
|
8 |
import PIL.Image
|
9 |
from typing import Tuple
|
10 |
-
from novita_client import NovitaClient, V3TaskResponseStatus
|
11 |
from time import time
|
12 |
|
13 |
from style_template import styles
|
@@ -120,26 +120,26 @@ LORA_MODELS = [
|
|
120 |
|
121 |
|
122 |
CONTROLNET_DICT = dict(
|
123 |
-
pose=
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
depth=
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
canny=
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
lineart=
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
)
|
144 |
|
145 |
last_check = 0
|
@@ -309,62 +309,41 @@ def generate_image (
|
|
309 |
height = int(height * scaling)
|
310 |
|
311 |
(
|
312 |
-
CONTROLNET_DICT['pose']
|
313 |
-
CONTROLNET_DICT['canny']
|
314 |
-
CONTROLNET_DICT['depth']
|
315 |
-
CONTROLNET_DICT['lineart']
|
316 |
) = [controlnet_strength_1, controlnet_strength_2, controlnet_strength_3, controlnet_strength_4]
|
317 |
|
318 |
-
|
319 |
-
|
320 |
-
res = client._post('/v3/async/instant-id', {
|
321 |
-
'extra': {
|
322 |
-
'response_image_type': 'jpeg',
|
323 |
-
},
|
324 |
-
'model_name': f'{model_name}.safetensors',
|
325 |
-
'face_image_assets_ids': [face_image_uploaded],
|
326 |
-
'ref_image_assets_ids': [ref_image_uploaded],
|
327 |
-
'prompt': prompt,
|
328 |
-
'negative_prompt': negative_prompt,
|
329 |
-
'controlnet': {
|
330 |
-
'units': [CONTROLNET_DICT[name] for name in controlnet_selection if name in CONTROLNET_DICT],
|
331 |
-
},
|
332 |
-
'loras': [dict(
|
333 |
-
model_name=f'{name}.safetensors',
|
334 |
-
scale=1,
|
335 |
-
) for name in lora_selection],
|
336 |
-
'image_num': 1,
|
337 |
-
'steps': num_steps,
|
338 |
-
'seed': seed,
|
339 |
-
'guidance_scale': guidance_scale,
|
340 |
-
'sampler_name': scheduler,
|
341 |
-
'id_strength': identitynet_strength_ratio,
|
342 |
-
'adapter_strength': adapter_strength_ratio,
|
343 |
-
'width': width,
|
344 |
-
'height': height,
|
345 |
-
})
|
346 |
-
|
347 |
-
print('task_id:', res['task_id'])
|
348 |
-
def progress (x):
|
349 |
global last_check
|
350 |
t = time()
|
351 |
if t > last_check + 5:
|
352 |
last_check = t
|
353 |
-
print('progress:', t, x
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
except Exception as e:
|
362 |
raise gr.Error(f'Error: {e}')
|
363 |
|
364 |
-
|
365 |
-
#print('final_res.images_encoded:', final_res.images_encoded)
|
366 |
-
|
367 |
-
image = PIL.Image.open(BytesIO(base64.b64decode(final_res.images_encoded[0])))
|
368 |
|
369 |
return image, gr.update(visible=True)
|
370 |
|
|
|
7 |
from io import BytesIO
|
8 |
import PIL.Image
|
9 |
from typing import Tuple
|
10 |
+
from novita_client import NovitaClient, V3TaskResponseStatus, InstantIDControlnetUnit
|
11 |
from time import time
|
12 |
|
13 |
from style_template import styles
|
|
|
120 |
|
121 |
|
122 |
CONTROLNET_DICT = dict(
|
123 |
+
pose=InstantIDControlnetUnit(
|
124 |
+
model_name='controlnet-openpose-sdxl-1.0',
|
125 |
+
strength=1,
|
126 |
+
preprocessor='openpose',
|
127 |
+
),
|
128 |
+
depth=InstantIDControlnetUnit(
|
129 |
+
model_name='controlnet-depth-sdxl-1.0',
|
130 |
+
strength=1,
|
131 |
+
preprocessor='depth',
|
132 |
+
),
|
133 |
+
canny=InstantIDControlnetUnit(
|
134 |
+
model_name='controlnet-canny-sdxl-1.0',
|
135 |
+
strength=1,
|
136 |
+
preprocessor='canny',
|
137 |
+
),
|
138 |
+
lineart=InstantIDControlnetUnit(
|
139 |
+
model_name='controlnet-softedge-sdxl-1.0',
|
140 |
+
strength=1,
|
141 |
+
preprocessor='lineart',
|
142 |
+
),
|
143 |
)
|
144 |
|
145 |
last_check = 0
|
|
|
309 |
height = int(height * scaling)
|
310 |
|
311 |
(
|
312 |
+
CONTROLNET_DICT['pose'].strength,
|
313 |
+
CONTROLNET_DICT['canny'].strength,
|
314 |
+
CONTROLNET_DICT['depth'].strength,
|
315 |
+
CONTROLNET_DICT['lineart'].strength,
|
316 |
) = [controlnet_strength_1, controlnet_strength_2, controlnet_strength_3, controlnet_strength_4]
|
317 |
|
318 |
+
def progress_ (x):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
global last_check
|
320 |
t = time()
|
321 |
if t > last_check + 5:
|
322 |
last_check = t
|
323 |
+
print('progress:', t, x)
|
324 |
+
|
325 |
+
res = client.instant_id(
|
326 |
+
model_name=f'{model_name}.safetensors',
|
327 |
+
face_images=[face_image_path],
|
328 |
+
ref_images=[ref_image_path],
|
329 |
+
prompt=prompt,
|
330 |
+
negative_prompt=negative_prompt,
|
331 |
+
controlnets=[CONTROLNET_DICT[name] for name in controlnet_selection if name in CONTROLNET_DICT],
|
332 |
+
steps=num_steps,
|
333 |
+
seed=seed,
|
334 |
+
guidance_scale=guidance_scale,
|
335 |
+
sampler_name=scheduler,
|
336 |
+
id_strength=identitynet_strength_ratio,
|
337 |
+
adapter_strength=adapter_strength_ratio,
|
338 |
+
width=width,
|
339 |
+
height=height,
|
340 |
+
#response_image_type='jpeg', # wait for novita_client 0.5.1 to fix this argument
|
341 |
+
callback=progress_,
|
342 |
+
)
|
343 |
except Exception as e:
|
344 |
raise gr.Error(f'Error: {e}')
|
345 |
|
346 |
+
image = PIL.Image.open(BytesIO(base64.b64decode(res.images_encoded[0])))
|
|
|
|
|
|
|
347 |
|
348 |
return image, gr.update(visible=True)
|
349 |
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
novita_client==0.
|
2 |
gradio==4.15.0
|
|
|
1 |
+
novita_client==0.5.0
|
2 |
gradio==4.15.0
|