fbnnb commited on
Commit
49f1aef
·
verified ·
1 Parent(s): fab4cfb

Update gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +104 -85
gradio_app.py CHANGED
@@ -1,86 +1,105 @@
1
- import os, argparse
2
- import sys
3
- import gradio as gr
4
- from scripts.gradio.i2v_test_application import Image2Video
5
- sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
6
-
7
-
8
- i2v_examples_interp_512 = [
9
- ['prompts/512_interp/74906_1462_frame1.png', 'walking man', 50, 7.5, 1.0, 10, 123, 'prompts/512_interp/74906_1462_frame3.png'],
10
- ['prompts/512_interp/Japan_v2_2_062266_s2_frame1.png', 'an anime scene', 50, 7.5, 1.0, 10, 789, 'prompts/512_interp/Japan_v2_2_062266_s2_frame3.png'],
11
- ['prompts/512_interp/Japan_v2_3_119235_s2_frame1.png', 'an anime scene', 50, 7.5, 1.0, 10, 123, 'prompts/512_interp/Japan_v2_3_119235_s2_frame3.png'],
12
- ]
13
-
14
-
15
-
16
-
17
- def dynamicrafter_demo(result_dir='./tmp/', res=512):
18
- if res == 1024:
19
- resolution = '576_1024'
20
- css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}"""
21
- elif res == 512:
22
- resolution = '320_512'
23
- css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px} #input_img2 {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px}"""
24
- elif res == 256:
25
- resolution = '256_256'
26
- css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}"""
27
- else:
28
- raise NotImplementedError(f"Unsupported resolution: {res}")
29
- image2video = Image2Video(result_dir, resolution=resolution)
30
- with gr.Blocks(analytics_enabled=False, css=css) as dynamicrafter_iface:
31
-
32
-
33
-
34
- with gr.Tab(label='ToonCrafter_320x512'):
35
- with gr.Column():
36
- with gr.Row():
37
- with gr.Column():
38
- with gr.Row():
39
- i2v_input_image = gr.Image(label="Input Image1",elem_id="input_img")
40
- frame_guides = gr.Video(label="Input Guidance",elem_id="input_guidance", autoplay=True,show_share_button=True)
41
- with gr.Row():
42
- i2v_input_text = gr.Text(label='Prompts')
43
- with gr.Row():
44
- i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123)
45
- i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
46
- i2v_cfg_scale = gr.Slider(minimum=1.0, maximum=15.0, step=0.5, label='CFG Scale', value=7.5, elem_id="i2v_cfg_scale")
47
- with gr.Row():
48
- i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
49
- i2v_motion = gr.Slider(minimum=5, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=10)
50
- control_scale = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, elem_id="i2v_ctrl_scale", label="control_scale", value=0.6)
51
- i2v_end_btn = gr.Button("Generate")
52
- with gr.Column():
53
- with gr.Row():
54
- i2v_input_image2 = gr.Image(label="Input Image2",elem_id="input_img2")
55
- with gr.Row():
56
- i2v_output_video = gr.Video(label="Generated Video",elem_id="output_vid",autoplay=True,show_share_button=True)
57
-
58
- gr.Examples(examples=i2v_examples_interp_512,
59
- inputs=[i2v_input_image, i2v_input_text, i2v_steps, i2v_cfg_scale, i2v_eta, i2v_motion, i2v_seed, i2v_input_image2, control_scale],
60
- outputs=[i2v_output_video],
61
- fn = image2video.get_image,
62
- cache_examples=False,
63
- )
64
- i2v_end_btn.click(inputs=[i2v_input_image, i2v_input_text, i2v_steps, i2v_cfg_scale, i2v_eta, i2v_motion, i2v_seed, i2v_input_image2, frame_guides, control_scale],
65
- outputs=[i2v_output_video],
66
- fn = image2video.get_image
67
- )
68
-
69
-
70
- return dynamicrafter_iface
71
-
72
- def get_parser():
73
- parser = argparse.ArgumentParser()
74
- return parser
75
-
76
- if __name__ == "__main__":
77
- parser = get_parser()
78
- args = parser.parse_args()
79
-
80
- result_dir = os.path.join('./', 'results')
81
- dynamicrafter_iface = dynamicrafter_demo(result_dir)
82
- # dynamicrafter_iface.queue(max_size=12)
83
- # dynamicrafter_iface.launch(max_threads=1, share=True)
84
- print("launching...")
85
- dynamicrafter_iface.launch(server_name='0.0.0.0', server_port=12345, share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  print("launched...")
 
1
+ import os, argparse
2
+ import sys
3
+ import gradio as gr
4
+ from scripts.gradio.i2v_test_application import Image2Video
5
+ sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
6
+
7
+
8
+ i2v_examples_interp_512 = [
9
+ ['prompts/512_interp/74906_1462_frame1.png', 'walking man', 50, 7.5, 1.0, 10, 123, 'prompts/512_interp/74906_1462_frame3.png'],
10
+ ['prompts/512_interp/Japan_v2_2_062266_s2_frame1.png', 'an anime scene', 50, 7.5, 1.0, 10, 789, 'prompts/512_interp/Japan_v2_2_062266_s2_frame3.png'],
11
+ ['prompts/512_interp/Japan_v2_3_119235_s2_frame1.png', 'an anime scene', 50, 7.5, 1.0, 10, 123, 'prompts/512_interp/Japan_v2_3_119235_s2_frame3.png'],
12
+ ]
13
+
14
+
15
+
16
+
17
+ from huggingface_hub import snapshot_download
18
+ import os
19
+
20
+ # 设置仓库地址和要下载的文件名
21
+ repo_id = "Doubiiu/ToonCrafter"
22
+ filename = "sketch_encoder.ckpt"
23
+
24
+ # 指定下载的目标目录
25
+ target_directory = "./control_models/"
26
+
27
+ # 确保目标目录存在,如果不存在则创建它
28
+ os.makedirs(target_directory, exist_ok=True)
29
+
30
+ # 下载文件到本地,并指定保存路径
31
+ local_dir = snapshot_download(repo_id=repo_id, allow_patterns=[filename], local_dir=target_directory, local_dir_use_symlinks=False)
32
+
33
+ print(f"文件已下载到: {local_dir}")
34
+
35
+
36
+ def dynamicrafter_demo(result_dir='./tmp/', res=512):
37
+ if res == 1024:
38
+ resolution = '576_1024'
39
+ css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}"""
40
+ elif res == 512:
41
+ resolution = '320_512'
42
+ css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px} #input_img2 {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px}"""
43
+ elif res == 256:
44
+ resolution = '256_256'
45
+ css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}"""
46
+ else:
47
+ raise NotImplementedError(f"Unsupported resolution: {res}")
48
+ image2video = Image2Video(result_dir, resolution=resolution)
49
+ with gr.Blocks(analytics_enabled=False, css=css) as dynamicrafter_iface:
50
+
51
+
52
+
53
+ with gr.Tab(label='ToonCrafter_320x512'):
54
+ with gr.Column():
55
+ with gr.Row():
56
+ with gr.Column():
57
+ with gr.Row():
58
+ i2v_input_image = gr.Image(label="Input Image1",elem_id="input_img")
59
+ frame_guides = gr.Video(label="Input Guidance",elem_id="input_guidance", autoplay=True,show_share_button=True)
60
+ with gr.Row():
61
+ i2v_input_text = gr.Text(label='Prompts')
62
+ with gr.Row():
63
+ i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123)
64
+ i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
65
+ i2v_cfg_scale = gr.Slider(minimum=1.0, maximum=15.0, step=0.5, label='CFG Scale', value=7.5, elem_id="i2v_cfg_scale")
66
+ with gr.Row():
67
+ i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
68
+ i2v_motion = gr.Slider(minimum=5, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=10)
69
+ control_scale = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, elem_id="i2v_ctrl_scale", label="control_scale", value=0.6)
70
+ i2v_end_btn = gr.Button("Generate")
71
+ with gr.Column():
72
+ with gr.Row():
73
+ i2v_input_image2 = gr.Image(label="Input Image2",elem_id="input_img2")
74
+ with gr.Row():
75
+ i2v_output_video = gr.Video(label="Generated Video",elem_id="output_vid",autoplay=True,show_share_button=True)
76
+
77
+ gr.Examples(examples=i2v_examples_interp_512,
78
+ inputs=[i2v_input_image, i2v_input_text, i2v_steps, i2v_cfg_scale, i2v_eta, i2v_motion, i2v_seed, i2v_input_image2, control_scale],
79
+ outputs=[i2v_output_video],
80
+ fn = image2video.get_image,
81
+ cache_examples=False,
82
+ )
83
+ i2v_end_btn.click(inputs=[i2v_input_image, i2v_input_text, i2v_steps, i2v_cfg_scale, i2v_eta, i2v_motion, i2v_seed, i2v_input_image2, frame_guides, control_scale],
84
+ outputs=[i2v_output_video],
85
+ fn = image2video.get_image
86
+ )
87
+
88
+
89
+ return dynamicrafter_iface
90
+
91
+ def get_parser():
92
+ parser = argparse.ArgumentParser()
93
+ return parser
94
+
95
+ if __name__ == "__main__":
96
+ parser = get_parser()
97
+ args = parser.parse_args()
98
+
99
+ result_dir = os.path.join('./', 'results')
100
+ dynamicrafter_iface = dynamicrafter_demo(result_dir)
101
+ # dynamicrafter_iface.queue(max_size=12)
102
+ # dynamicrafter_iface.launch(max_threads=1, share=True)
103
+ print("launching...")
104
+ dynamicrafter_iface.launch(server_name='0.0.0.0', server_port=12345, share=True)
105
  print("launched...")