Spaces:
Runtime error
Runtime error
LeoXing1996
commited on
Commit
·
046f233
1
Parent(s):
f302f51
support new year feature
Browse files- .gitattributes +1 -0
- app-huggingface.py +158 -94
- requirements.txt +1 -0
- zyhzx.ttf +3 -0
.gitattributes
CHANGED
@@ -1 +1,2 @@
|
|
1 |
__assets__/image_animation/zhening/zhening.jpeg filter=lfs diff=lfs merge=lfs -text
|
|
|
|
1 |
__assets__/image_animation/zhening/zhening.jpeg filter=lfs diff=lfs merge=lfs -text
|
2 |
+
zyhzx.ttf filter=lfs diff=lfs merge=lfs -text
|
app-huggingface.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
import json
|
2 |
import copy
|
|
|
3 |
import os
|
4 |
import os.path as osp
|
5 |
import random
|
@@ -7,17 +7,54 @@ from argparse import ArgumentParser
|
|
7 |
from datetime import datetime
|
8 |
|
9 |
import gradio as gr
|
|
|
10 |
import numpy as np
|
11 |
import torch
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
from omegaconf import OmegaConf
|
14 |
-
from PIL import Image
|
15 |
|
16 |
from animatediff.pipelines import I2VPipeline
|
17 |
from animatediff.utils.util import RANGE_LIST, save_videos_grid
|
18 |
|
19 |
sample_idx = 0
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
css = """
|
22 |
.toolbutton {
|
23 |
margin-buttom: 0em 0em 0em 0em;
|
@@ -43,7 +80,6 @@ LOCAL_DEBUG = args.local_debug
|
|
43 |
BASE_CONFIG = 'example/config/base.yaml'
|
44 |
STYLE_CONFIG_LIST = {
|
45 |
'3d_cartoon': './example/openxlab/3-3d.yaml',
|
46 |
-
# 'realistic': './example/openxlab/1-realistic.yaml',
|
47 |
}
|
48 |
|
49 |
|
@@ -79,11 +115,7 @@ if not LOCAL_DEBUG:
|
|
79 |
PIA_PATH = hf_hub_download(repo_id='Leoxing/PIA',
|
80 |
filename='pia.ckpt', cache_dir=PIA_PATH)
|
81 |
PIA_PATH = '/'.join(PIA_PATH.split('/')[:-1])
|
82 |
-
# os.system('bash download_bashscripts/1-RealisticVision.sh')
|
83 |
os.system('bash download_bashscripts/2-RcnzCartoon.sh')
|
84 |
-
# hf_hub_download(repo_id='frankjoshua/realisticVisionV51_v51VAE',
|
85 |
-
# filename='realisticVisionV51_v51VAE.safetensors',
|
86 |
-
# cache_dir='')
|
87 |
print(os.listdir(DreamBooth_LoRA_PATH))
|
88 |
|
89 |
# unet
|
@@ -186,7 +218,6 @@ class AnimateController:
|
|
186 |
self.pipeline_dict = self.load_model_list()
|
187 |
|
188 |
def load_model_list(self):
|
189 |
-
print(os.listdir(DreamBooth_LoRA_PATH))
|
190 |
pipeline_dict = dict()
|
191 |
for style, cfg in self.style_configs.items():
|
192 |
dreambooth_path = cfg.get('dreambooth', 'none')
|
@@ -235,9 +266,13 @@ class AnimateController:
|
|
235 |
ip_adapter_scale,
|
236 |
style,
|
237 |
example_img=None,
|
|
|
|
|
238 |
progress=gr.Progress(),
|
239 |
):
|
240 |
|
|
|
|
|
241 |
if init_img is None:
|
242 |
if example_img is None:
|
243 |
gr.Warning('Please upload image or use example images.')
|
@@ -247,18 +282,24 @@ class AnimateController:
|
|
247 |
|
248 |
if seed_textbox != -1 and seed_textbox != "":
|
249 |
torch.manual_seed(int(seed_textbox))
|
|
|
250 |
else:
|
251 |
seed = torch.initial_seed()
|
252 |
-
|
|
|
253 |
seed_everything(seed)
|
254 |
|
|
|
|
|
255 |
pipeline = self.pipeline_dict[style]
|
256 |
init_img, h, w = preprocess_img(init_img)
|
257 |
print(f'img size: {h, w}')
|
|
|
258 |
sample = pipeline(
|
259 |
image=init_img,
|
260 |
prompt=prompt_textbox,
|
261 |
negative_prompt=negative_prompt_textbox,
|
|
|
262 |
num_inference_steps=sample_step_slider,
|
263 |
guidance_scale=cfg_scale_slider,
|
264 |
width=w,
|
@@ -269,9 +310,13 @@ class AnimateController:
|
|
269 |
progress_fn=progress,
|
270 |
).videos
|
271 |
|
272 |
-
|
273 |
self.savedir_sample, f"{sample_idx}.mp4")
|
274 |
-
|
|
|
|
|
|
|
|
|
275 |
|
276 |
sample_config = {
|
277 |
"prompt": prompt_textbox,
|
@@ -283,13 +328,21 @@ class AnimateController:
|
|
283 |
"seed": seed,
|
284 |
"motion": motion_scale,
|
285 |
}
|
|
|
286 |
json_str = json.dumps(sample_config, indent=4)
|
287 |
with open(os.path.join(self.savedir, "logs.json"), "a") as f:
|
288 |
f.write(json_str)
|
289 |
f.write("\n\n")
|
290 |
|
291 |
-
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
|
295 |
controller = AnimateController()
|
@@ -297,6 +350,26 @@ controller = AnimateController()
|
|
297 |
|
298 |
def ui():
|
299 |
with gr.Blocks(css=css) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
|
301 |
gr.HTML(
|
302 |
"<div align='center'><font size='7'> <img src=\"file/pia.png\" style=\"height: 72px;\"/ > Your Personalized Image Animator</font></div>"
|
@@ -311,33 +384,27 @@ def ui():
|
|
311 |
)
|
312 |
|
313 |
with gr.Row(equal_height=False):
|
314 |
-
# build state for default buttons
|
315 |
-
example_img = gr.State(value='__assets__/image_animation/zhening/zhening.jpeg')
|
316 |
-
default_motion = gr.State(value=1)
|
317 |
-
default_prompt1 = gr.State(value='lift a red envelope, Chinese new year')
|
318 |
-
default_prompt2 = gr.State(value='smiling, Chinese costume, Chinese new year')
|
319 |
-
default_prompt3 = gr.State(value='angry, Chinese costume, Chinese new year')
|
320 |
-
default_prompt4 = gr.State(value='sparklers, Chinese new year')
|
321 |
-
default_n_prompt = gr.State(value='wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg')
|
322 |
-
default_seed = gr.State(10201304011203481448)
|
323 |
-
default_ip_adapter_scale = gr.State(0.2)
|
324 |
-
default_style = gr.State('3d_cartoon')
|
325 |
-
default_cfg = gr.State(7.5)
|
326 |
-
|
327 |
with gr.Column():
|
328 |
with gr.Row():
|
329 |
init_img = gr.Image(label='Input Image')
|
330 |
|
331 |
gr.Markdown('## Fast Try!')
|
332 |
with gr.Row():
|
333 |
-
with gr.Column(scale=
|
334 |
-
default_1 = gr.Button(
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
with gr.Column(scale=
|
340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
style_dropdown = gr.Dropdown(label='Style', choices=list(
|
343 |
STYLE_CONFIG_LIST.keys()), value=list(STYLE_CONFIG_LIST.keys())[0])
|
@@ -374,14 +441,17 @@ def ui():
|
|
374 |
value=controller.fetch_default_n_prompt(
|
375 |
list(STYLE_CONFIG_LIST.keys())[0])[0],
|
376 |
label="Negative prompt", lines=2)
|
377 |
-
|
378 |
-
label='IP-Apdater Scale', value=controller.fetch_default_n_prompt(
|
379 |
-
list(STYLE_CONFIG_LIST.keys())[0])[1], minimum=0, maximum=1)
|
380 |
sample_step_slider = gr.Slider(
|
381 |
label="Sampling steps", value=20, minimum=10, maximum=100, step=1)
|
382 |
|
383 |
cfg_scale_slider = gr.Slider(
|
384 |
label="CFG Scale", value=7.5, minimum=0, maximum=20)
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
with gr.Row():
|
387 |
seed_textbox = gr.Textbox(label="Seed", value=-1)
|
@@ -396,8 +466,11 @@ def ui():
|
|
396 |
generate_button = gr.Button(
|
397 |
value="Generate", variant='primary')
|
398 |
|
399 |
-
|
400 |
-
|
|
|
|
|
|
|
401 |
|
402 |
style_dropdown.change(fn=controller.fetch_default_n_prompt,
|
403 |
inputs=[style_dropdown],
|
@@ -417,9 +490,10 @@ def ui():
|
|
417 |
seed_textbox,
|
418 |
ip_adapter_scale,
|
419 |
style_dropdown,
|
|
|
420 |
],
|
421 |
-
outputs=[result_video]
|
422 |
-
|
423 |
default_1.click(
|
424 |
fn=controller.animate,
|
425 |
inputs=[
|
@@ -428,13 +502,15 @@ def ui():
|
|
428 |
default_prompt1,
|
429 |
default_n_prompt,
|
430 |
sample_step_slider,
|
431 |
-
default_cfg
|
432 |
default_seed,
|
433 |
default_ip_adapter_scale,
|
434 |
default_style,
|
435 |
example_img,
|
|
|
|
|
436 |
],
|
437 |
-
outputs=[result_video])
|
438 |
default_2.click(
|
439 |
fn=controller.animate,
|
440 |
inputs=[
|
@@ -443,13 +519,15 @@ def ui():
|
|
443 |
default_prompt2,
|
444 |
default_n_prompt,
|
445 |
sample_step_slider,
|
446 |
-
default_cfg
|
447 |
default_seed,
|
448 |
default_ip_adapter_scale,
|
449 |
default_style,
|
450 |
example_img,
|
|
|
|
|
451 |
],
|
452 |
-
outputs=[result_video])
|
453 |
default_3.click(
|
454 |
fn=controller.animate,
|
455 |
inputs=[
|
@@ -458,13 +536,15 @@ def ui():
|
|
458 |
default_prompt3,
|
459 |
default_n_prompt,
|
460 |
sample_step_slider,
|
461 |
-
default_cfg
|
462 |
default_seed,
|
463 |
default_ip_adapter_scale,
|
464 |
default_style,
|
465 |
example_img,
|
|
|
|
|
466 |
],
|
467 |
-
outputs=[result_video])
|
468 |
default_4.click(
|
469 |
fn=controller.animate,
|
470 |
inputs=[
|
@@ -473,13 +553,21 @@ def ui():
|
|
473 |
default_prompt4,
|
474 |
default_n_prompt,
|
475 |
sample_step_slider,
|
476 |
-
default_cfg
|
477 |
default_seed,
|
478 |
default_ip_adapter_scale,
|
479 |
default_style,
|
480 |
example_img,
|
|
|
|
|
481 |
],
|
482 |
-
outputs=[result_video])
|
|
|
|
|
|
|
|
|
|
|
|
|
483 |
|
484 |
def create_example(input_list):
|
485 |
return gr.Examples(
|
@@ -500,16 +588,16 @@ def ui():
|
|
500 |
create_example(
|
501 |
[
|
502 |
[
|
503 |
-
'
|
504 |
-
'
|
505 |
'1boy in Christmas suit, lift a Christmas gift',
|
506 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
507 |
'3d_cartoon',
|
508 |
2,
|
509 |
],
|
510 |
[
|
511 |
-
'
|
512 |
-
'
|
513 |
'1girl lift a Christmas gift',
|
514 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
515 |
'3d_cartoon',
|
@@ -523,16 +611,16 @@ def ui():
|
|
523 |
create_example([
|
524 |
[
|
525 |
|
526 |
-
'
|
527 |
-
'
|
528 |
'1girl open mouth ',
|
529 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
530 |
'3d_cartoon',
|
531 |
3,
|
532 |
],
|
533 |
[
|
534 |
-
'
|
535 |
-
'
|
536 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
537 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
538 |
'3d_cartoon',
|
@@ -544,49 +632,25 @@ def ui():
|
|
544 |
with gr.Accordion('More Examples for Prompt Changing', open=False):
|
545 |
create_example(
|
546 |
[
|
547 |
-
# [
|
548 |
-
# './__assets__/image_animation/real/lighthouse.jpg',
|
549 |
-
# './__assets__/image_animation/real/1.mp4',
|
550 |
-
# 'lightning, lighthouse',
|
551 |
-
# 'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
552 |
-
# 'realistic',
|
553 |
-
# 1,
|
554 |
-
# ],
|
555 |
-
# [
|
556 |
-
# './__assets__/image_animation/real/lighthouse.jpg',
|
557 |
-
# './__assets__/image_animation/real/2.mp4',
|
558 |
-
# 'sun rising, lighthouse',
|
559 |
-
# 'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
560 |
-
# 'realistic',
|
561 |
-
# 1,
|
562 |
-
# ],
|
563 |
-
# [
|
564 |
-
# './__assets__/image_animation/real/lighthouse.jpg',
|
565 |
-
# './__assets__/image_animation/real/3.mp4',
|
566 |
-
# 'fireworks, lighthouse',
|
567 |
-
# 'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
568 |
-
# 'realistic',
|
569 |
-
# 1,
|
570 |
-
# ],
|
571 |
[
|
572 |
-
'
|
573 |
-
'
|
574 |
'1boy smiling',
|
575 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
576 |
'3d_cartoon',
|
577 |
2
|
578 |
],
|
579 |
[
|
580 |
-
'
|
581 |
-
'
|
582 |
'1boy playing magic fire',
|
583 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
584 |
'3d_cartoon',
|
585 |
2
|
586 |
],
|
587 |
[
|
588 |
-
'
|
589 |
-
'
|
590 |
'1boy is waving hands',
|
591 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
592 |
'3d_cartoon',
|
@@ -598,24 +662,24 @@ def ui():
|
|
598 |
create_example(
|
599 |
[
|
600 |
[
|
601 |
-
'
|
602 |
-
'
|
603 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
604 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
605 |
'3d_cartoon',
|
606 |
1,
|
607 |
],
|
608 |
[
|
609 |
-
'
|
610 |
-
'
|
611 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
612 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
613 |
'3d_cartoon',
|
614 |
2,
|
615 |
],
|
616 |
[
|
617 |
-
'
|
618 |
-
'
|
619 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
620 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
621 |
'3d_cartoon',
|
@@ -632,4 +696,4 @@ if __name__ == "__main__":
|
|
632 |
demo.launch(server_name=args.server_name,
|
633 |
server_port=args.port, share=args.share,
|
634 |
max_threads=40,
|
635 |
-
allowed_paths=['pia.png'])
|
|
|
|
|
1 |
import copy
|
2 |
+
import json
|
3 |
import os
|
4 |
import os.path as osp
|
5 |
import random
|
|
|
7 |
from datetime import datetime
|
8 |
|
9 |
import gradio as gr
|
10 |
+
import moviepy.editor as mpy
|
11 |
import numpy as np
|
12 |
import torch
|
13 |
from huggingface_hub import hf_hub_download
|
14 |
from omegaconf import OmegaConf
|
15 |
+
from PIL import Image, ImageDraw, ImageFont
|
16 |
|
17 |
from animatediff.pipelines import I2VPipeline
|
18 |
from animatediff.utils.util import RANGE_LIST, save_videos_grid
|
19 |
|
20 |
sample_idx = 0
|
21 |
|
22 |
+
|
23 |
+
def convert_gif_to_mp4(gif_path, mp4_path):
|
24 |
+
|
25 |
+
clip = mpy.VideoFileClip(gif_path)
|
26 |
+
clip.write_videofile(mp4_path)
|
27 |
+
|
28 |
+
|
29 |
+
def add_text(gif_file: str, mp4_file: str, text_index: int):
|
30 |
+
image = Image.open(gif_file)
|
31 |
+
|
32 |
+
frames = []
|
33 |
+
try:
|
34 |
+
while True:
|
35 |
+
frames.append(image.copy().convert('RGB'))
|
36 |
+
image.seek(len(frames))
|
37 |
+
except EOFError:
|
38 |
+
pass
|
39 |
+
|
40 |
+
text = ['Happy New Year!'][text_index]
|
41 |
+
size = [36, 36, 36, 36][text_index]
|
42 |
+
|
43 |
+
for i, frame in enumerate(frames):
|
44 |
+
font = ImageFont.truetype('zyhzx.ttf', size=size + i * 2)
|
45 |
+
draw = ImageDraw.Draw(frame)
|
46 |
+
|
47 |
+
text_width, text_height = draw.textsize(text, font=font)
|
48 |
+
image_width, image_height = image.size
|
49 |
+
x = (image_width - text_width) // 2
|
50 |
+
y = (image_height - text_height) - (image_height - text_height) // 8
|
51 |
+
|
52 |
+
draw.text((x, y), text, fill='red', font=font)
|
53 |
+
|
54 |
+
frames[0].save(gif_file, save_all=True, append_images=frames[1:], loop=0)
|
55 |
+
mp4_file = convert_gif_to_mp4(gif_file, mp4_file)
|
56 |
+
return gif_file, mp4_file
|
57 |
+
|
58 |
css = """
|
59 |
.toolbutton {
|
60 |
margin-buttom: 0em 0em 0em 0em;
|
|
|
80 |
BASE_CONFIG = 'example/config/base.yaml'
|
81 |
STYLE_CONFIG_LIST = {
|
82 |
'3d_cartoon': './example/openxlab/3-3d.yaml',
|
|
|
83 |
}
|
84 |
|
85 |
|
|
|
115 |
PIA_PATH = hf_hub_download(repo_id='Leoxing/PIA',
|
116 |
filename='pia.ckpt', cache_dir=PIA_PATH)
|
117 |
PIA_PATH = '/'.join(PIA_PATH.split('/')[:-1])
|
|
|
118 |
os.system('bash download_bashscripts/2-RcnzCartoon.sh')
|
|
|
|
|
|
|
119 |
print(os.listdir(DreamBooth_LoRA_PATH))
|
120 |
|
121 |
# unet
|
|
|
218 |
self.pipeline_dict = self.load_model_list()
|
219 |
|
220 |
def load_model_list(self):
|
|
|
221 |
pipeline_dict = dict()
|
222 |
for style, cfg in self.style_configs.items():
|
223 |
dreambooth_path = cfg.get('dreambooth', 'none')
|
|
|
266 |
ip_adapter_scale,
|
267 |
style,
|
268 |
example_img=None,
|
269 |
+
with_text=False,
|
270 |
+
text_idx=0,
|
271 |
progress=gr.Progress(),
|
272 |
):
|
273 |
|
274 |
+
global sample_idx
|
275 |
+
|
276 |
if init_img is None:
|
277 |
if example_img is None:
|
278 |
gr.Warning('Please upload image or use example images.')
|
|
|
282 |
|
283 |
if seed_textbox != -1 and seed_textbox != "":
|
284 |
torch.manual_seed(int(seed_textbox))
|
285 |
+
seed = int(seed_textbox)
|
286 |
else:
|
287 |
seed = torch.initial_seed()
|
288 |
+
generator = torch.Generator(device='cuda')
|
289 |
+
generator.manual_seed(seed)
|
290 |
seed_everything(seed)
|
291 |
|
292 |
+
print(f'Seed: {seed}')
|
293 |
+
|
294 |
pipeline = self.pipeline_dict[style]
|
295 |
init_img, h, w = preprocess_img(init_img)
|
296 |
print(f'img size: {h, w}')
|
297 |
+
|
298 |
sample = pipeline(
|
299 |
image=init_img,
|
300 |
prompt=prompt_textbox,
|
301 |
negative_prompt=negative_prompt_textbox,
|
302 |
+
generator=generator,
|
303 |
num_inference_steps=sample_step_slider,
|
304 |
guidance_scale=cfg_scale_slider,
|
305 |
width=w,
|
|
|
310 |
progress_fn=progress,
|
311 |
).videos
|
312 |
|
313 |
+
save_sample_path_mp4 = os.path.join(
|
314 |
self.savedir_sample, f"{sample_idx}.mp4")
|
315 |
+
save_sample_path_gif = os.path.join(
|
316 |
+
self.savedir_sample, f"{sample_idx}.gif")
|
317 |
+
|
318 |
+
save_videos_grid(sample, save_sample_path_mp4)
|
319 |
+
save_videos_grid(sample, save_sample_path_gif)
|
320 |
|
321 |
sample_config = {
|
322 |
"prompt": prompt_textbox,
|
|
|
328 |
"seed": seed,
|
329 |
"motion": motion_scale,
|
330 |
}
|
331 |
+
print(sample_config)
|
332 |
json_str = json.dumps(sample_config, indent=4)
|
333 |
with open(os.path.join(self.savedir, "logs.json"), "a") as f:
|
334 |
f.write(json_str)
|
335 |
f.write("\n\n")
|
336 |
|
337 |
+
if with_text:
|
338 |
+
add_text(save_sample_path_gif, save_sample_path_mp4, text_idx)
|
339 |
+
|
340 |
+
sample_idx += 1
|
341 |
+
# return (save_sample_path_mp4,
|
342 |
+
# gr.update(link=f'file/{save_sample_path_mp4}'),
|
343 |
+
# gr.update(link=f'file/{save_sample_path_gif}'))
|
344 |
+
return (save_sample_path_mp4,
|
345 |
+
[save_sample_path_mp4, save_sample_path_gif])
|
346 |
|
347 |
|
348 |
controller = AnimateController()
|
|
|
350 |
|
351 |
def ui():
|
352 |
with gr.Blocks(css=css) as demo:
|
353 |
+
# build state for default buttons
|
354 |
+
example_img = gr.State(
|
355 |
+
value='__assets__/image_animation/zhening/zhening.jpeg')
|
356 |
+
default_motion = gr.State(value=1)
|
357 |
+
default_prompt1 = gr.State(
|
358 |
+
value='lift a red envelope, Chinese new year')
|
359 |
+
default_prompt2 = gr.State(
|
360 |
+
value='smiling, Chinese costume, Chinese new year')
|
361 |
+
default_prompt3 = gr.State(
|
362 |
+
value='angry, Chinese costume, Chinese new year')
|
363 |
+
default_prompt4 = gr.State(value='sparklers, Chinese new year')
|
364 |
+
default_n_prompt = gr.State(value='wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg')
|
365 |
+
default_seed = gr.State(10201304011203481448)
|
366 |
+
default_ip_adapter_scale = gr.State(0.2)
|
367 |
+
default_style = gr.State('3d_cartoon')
|
368 |
+
default_cfg = gr.State(7.5)
|
369 |
+
default_1_idx = gr.State(0)
|
370 |
+
default_2_idx = gr.State(1)
|
371 |
+
default_3_idx = gr.State(2)
|
372 |
+
default_4_idx = gr.State(3)
|
373 |
|
374 |
gr.HTML(
|
375 |
"<div align='center'><font size='7'> <img src=\"file/pia.png\" style=\"height: 72px;\"/ > Your Personalized Image Animator</font></div>"
|
|
|
384 |
)
|
385 |
|
386 |
with gr.Row(equal_height=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
with gr.Column():
|
388 |
with gr.Row():
|
389 |
init_img = gr.Image(label='Input Image')
|
390 |
|
391 |
gr.Markdown('## Fast Try!')
|
392 |
with gr.Row():
|
393 |
+
with gr.Column(scale=1, min_width=50):
|
394 |
+
default_1 = gr.Button(
|
395 |
+
'🧧', variant='primary', size='sm')
|
396 |
+
with gr.Column(scale=1, min_width=50):
|
397 |
+
default_2 = gr.Button(
|
398 |
+
'🤗', variant='primary', size='sm')
|
399 |
+
with gr.Column(scale=1, min_width=50):
|
400 |
+
default_3 = gr.Button(
|
401 |
+
'😡', variant='primary', size='sm')
|
402 |
+
with gr.Column(scale=1, min_width=50):
|
403 |
+
default_4 = gr.Button(
|
404 |
+
'🧨', variant='primary', size='sm')
|
405 |
+
|
406 |
+
with gr.Column(scale=1.5, min_width=150):
|
407 |
+
with_wishes = gr.Checkbox(label='With Wishes✨')
|
408 |
|
409 |
style_dropdown = gr.Dropdown(label='Style', choices=list(
|
410 |
STYLE_CONFIG_LIST.keys()), value=list(STYLE_CONFIG_LIST.keys())[0])
|
|
|
441 |
value=controller.fetch_default_n_prompt(
|
442 |
list(STYLE_CONFIG_LIST.keys())[0])[0],
|
443 |
label="Negative prompt", lines=2)
|
444 |
+
|
|
|
|
|
445 |
sample_step_slider = gr.Slider(
|
446 |
label="Sampling steps", value=20, minimum=10, maximum=100, step=1)
|
447 |
|
448 |
cfg_scale_slider = gr.Slider(
|
449 |
label="CFG Scale", value=7.5, minimum=0, maximum=20)
|
450 |
+
ip_adapter_scale = gr.Slider(
|
451 |
+
label='IP-Apdater Scale',
|
452 |
+
value=controller.fetch_default_n_prompt(
|
453 |
+
list(STYLE_CONFIG_LIST.keys())[0])[1],
|
454 |
+
minimum=0, maximum=1)
|
455 |
|
456 |
with gr.Row():
|
457 |
seed_textbox = gr.Textbox(label="Seed", value=-1)
|
|
|
466 |
generate_button = gr.Button(
|
467 |
value="Generate", variant='primary')
|
468 |
|
469 |
+
with gr.Column():
|
470 |
+
result_video = gr.Video(
|
471 |
+
label="Generated Animation", interactive=False)
|
472 |
+
with gr.Row():
|
473 |
+
download = gr.Files(file_types=['gif', 'mp4'], label='Donwload Output')
|
474 |
|
475 |
style_dropdown.change(fn=controller.fetch_default_n_prompt,
|
476 |
inputs=[style_dropdown],
|
|
|
490 |
seed_textbox,
|
491 |
ip_adapter_scale,
|
492 |
style_dropdown,
|
493 |
+
# None,
|
494 |
],
|
495 |
+
outputs=[result_video, download])
|
496 |
+
|
497 |
default_1.click(
|
498 |
fn=controller.animate,
|
499 |
inputs=[
|
|
|
502 |
default_prompt1,
|
503 |
default_n_prompt,
|
504 |
sample_step_slider,
|
505 |
+
default_cfg,
|
506 |
default_seed,
|
507 |
default_ip_adapter_scale,
|
508 |
default_style,
|
509 |
example_img,
|
510 |
+
with_wishes,
|
511 |
+
default_1_idx,
|
512 |
],
|
513 |
+
outputs=[result_video, download])
|
514 |
default_2.click(
|
515 |
fn=controller.animate,
|
516 |
inputs=[
|
|
|
519 |
default_prompt2,
|
520 |
default_n_prompt,
|
521 |
sample_step_slider,
|
522 |
+
default_cfg,
|
523 |
default_seed,
|
524 |
default_ip_adapter_scale,
|
525 |
default_style,
|
526 |
example_img,
|
527 |
+
with_wishes,
|
528 |
+
default_2_idx,
|
529 |
],
|
530 |
+
outputs=[result_video, download])
|
531 |
default_3.click(
|
532 |
fn=controller.animate,
|
533 |
inputs=[
|
|
|
536 |
default_prompt3,
|
537 |
default_n_prompt,
|
538 |
sample_step_slider,
|
539 |
+
default_cfg,
|
540 |
default_seed,
|
541 |
default_ip_adapter_scale,
|
542 |
default_style,
|
543 |
example_img,
|
544 |
+
with_wishes,
|
545 |
+
default_3_idx,
|
546 |
],
|
547 |
+
outputs=[result_video, download])
|
548 |
default_4.click(
|
549 |
fn=controller.animate,
|
550 |
inputs=[
|
|
|
553 |
default_prompt4,
|
554 |
default_n_prompt,
|
555 |
sample_step_slider,
|
556 |
+
default_cfg,
|
557 |
default_seed,
|
558 |
default_ip_adapter_scale,
|
559 |
default_style,
|
560 |
example_img,
|
561 |
+
with_wishes,
|
562 |
+
default_4_idx,
|
563 |
],
|
564 |
+
outputs=[result_video, download])
|
565 |
+
|
566 |
+
# save_as_gif.click(
|
567 |
+
# fn=None,
|
568 |
+
# inputs=[save_as_gif],
|
569 |
+
# js=_js_open_if_not_logged_in,
|
570 |
+
# )
|
571 |
|
572 |
def create_example(input_list):
|
573 |
return gr.Examples(
|
|
|
588 |
create_example(
|
589 |
[
|
590 |
[
|
591 |
+
'__assets__/image_animation/yiming/yiming.jpeg',
|
592 |
+
'__assets__/image_animation/yiming/yiming.mp4',
|
593 |
'1boy in Christmas suit, lift a Christmas gift',
|
594 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
595 |
'3d_cartoon',
|
596 |
2,
|
597 |
],
|
598 |
[
|
599 |
+
'__assets__/image_animation/yanhong/yanhong.png',
|
600 |
+
'__assets__/image_animation/yanhong/yanhong.mp4',
|
601 |
'1girl lift a Christmas gift',
|
602 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
603 |
'3d_cartoon',
|
|
|
611 |
create_example([
|
612 |
[
|
613 |
|
614 |
+
'__assets__/image_animation/style_transfer/anya/anya.jpg',
|
615 |
+
'__assets__/image_animation/style_transfer/anya/2.mp4',
|
616 |
'1girl open mouth ',
|
617 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
618 |
'3d_cartoon',
|
619 |
3,
|
620 |
],
|
621 |
[
|
622 |
+
'__assets__/image_animation/magnitude/genshin/genshin.jpg',
|
623 |
+
'__assets__/image_animation/magnitude/genshin/3.mp4',
|
624 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
625 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
626 |
'3d_cartoon',
|
|
|
632 |
with gr.Accordion('More Examples for Prompt Changing', open=False):
|
633 |
create_example(
|
634 |
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
635 |
[
|
636 |
+
'__assets__/image_animation/rcnz/harry.png',
|
637 |
+
'__assets__/image_animation/rcnz/1.mp4',
|
638 |
'1boy smiling',
|
639 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
640 |
'3d_cartoon',
|
641 |
2
|
642 |
],
|
643 |
[
|
644 |
+
'__assets__/image_animation/rcnz/harry.png',
|
645 |
+
'__assets__/image_animation/rcnz/2.mp4',
|
646 |
'1boy playing magic fire',
|
647 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
648 |
'3d_cartoon',
|
649 |
2
|
650 |
],
|
651 |
[
|
652 |
+
'__assets__/image_animation/rcnz/harry.png',
|
653 |
+
'__assets__/image_animation/rcnz/3.mp4',
|
654 |
'1boy is waving hands',
|
655 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
656 |
'3d_cartoon',
|
|
|
662 |
create_example(
|
663 |
[
|
664 |
[
|
665 |
+
'__assets__/image_animation/magnitude/labrador.png',
|
666 |
+
'__assets__/image_animation/magnitude/1.mp4',
|
667 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
668 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
669 |
'3d_cartoon',
|
670 |
1,
|
671 |
],
|
672 |
[
|
673 |
+
'__assets__/image_animation/magnitude/labrador.png',
|
674 |
+
'__assets__/image_animation/magnitude/2.mp4',
|
675 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
676 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
677 |
'3d_cartoon',
|
678 |
2,
|
679 |
],
|
680 |
[
|
681 |
+
'__assets__/image_animation/magnitude/labrador.png',
|
682 |
+
'__assets__/image_animation/magnitude/3.mp4',
|
683 |
'cherry blossoms in the wind, raidenshogundef, yaemikodef, best quality, 4k',
|
684 |
'wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg',
|
685 |
'3d_cartoon',
|
|
|
696 |
demo.launch(server_name=args.server_name,
|
697 |
server_port=args.port, share=args.share,
|
698 |
max_threads=40,
|
699 |
+
allowed_paths=['pia.png', 'samples'])
|
requirements.txt
CHANGED
@@ -11,3 +11,4 @@ safetensors
|
|
11 |
gradio==4.7.1
|
12 |
moviepy
|
13 |
pytorch_lightning==1.9.4
|
|
|
|
11 |
gradio==4.7.1
|
12 |
moviepy
|
13 |
pytorch_lightning==1.9.4
|
14 |
+
pillow==9.5.0
|
zyhzx.ttf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a0e787d88450c8d8c6ba84ffd7b1d8105708270165fdce8b365656bca0294e54
|
3 |
+
size 15260048
|