svjack commited on
Commit
7f6ae68
·
verified ·
1 Parent(s): a7f3565

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -79
app.py CHANGED
@@ -1,79 +1,80 @@
1
- import os
2
- import argparse
3
- import sys
4
- import gradio as gr
5
- from scripts.gradio.i2v_test_application import Image2Video
6
- sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
7
-
8
- i2v_examples_interp_512 = [
9
- ['genshin_impact_img/ZHONGLI_source.webp', 'An anime character sitting down', 50, 3.5, 1.0, 30, 123, 'genshin_impact_img/ZHONGLI_target.webp'],
10
- ['genshin_impact_img/AYATO_source.webp', 'an anime man smiling', 50, 3.5, 1.0, 30, 123, 'genshin_impact_img/AYATO_target.webp'],
11
- ['prompts/512_interp/74906_1462_frame1.png', 'walking man', 50, 7.5, 1.0, 10, 123, 'prompts/512_interp/74906_1462_frame3.png'],
12
- ['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'],
13
- ['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'],
14
- ]
15
-
16
- def dynamicrafter_demo(result_dir='./tmp/', res=512):
17
- if res == 1024:
18
- resolution = '576_1024'
19
- css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}"""
20
- elif res == 512:
21
- resolution = '320_512'
22
- 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}"""
23
- elif res == 256:
24
- resolution = '256_256'
25
- css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}"""
26
- else:
27
- raise NotImplementedError(f"Unsupported resolution: {res}")
28
- image2video = Image2Video(result_dir, resolution=resolution)
29
- with gr.Blocks(analytics_enabled=False, css=css) as dynamicrafter_iface:
30
- dynamicrafter_iface.title = "Image to Video Converter (with Genshin Impact Demo)" # 添加标题
31
-
32
- with gr.Tab(label='ToonCrafter_320x512'):
33
- with gr.Column():
34
- with gr.Row():
35
- with gr.Column():
36
- with gr.Row():
37
- i2v_input_image = gr.Image(label="Input Image1", elem_id="input_img")
38
- with gr.Row():
39
- i2v_input_text = gr.Text(label='Prompts')
40
- with gr.Row():
41
- i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123)
42
- i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
43
- 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")
44
- with gr.Row():
45
- i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
46
- i2v_motion = gr.Slider(minimum=5, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=10)
47
- i2v_end_btn = gr.Button("Generate")
48
- with gr.Column():
49
- with gr.Row():
50
- i2v_input_image2 = gr.Image(label="Input Image2", elem_id="input_img2")
51
- with gr.Row():
52
- i2v_output_video = gr.Video(label="Generated Video", elem_id="output_vid", autoplay=True, show_share_button=True)
53
-
54
- gr.Examples(examples=i2v_examples_interp_512,
55
- inputs=[i2v_input_image, i2v_input_text, i2v_steps, i2v_cfg_scale, i2v_eta, i2v_motion, i2v_seed, i2v_input_image2],
56
- outputs=[i2v_output_video],
57
- fn=image2video.get_image,
58
- cache_examples=False,
59
- )
60
- 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],
61
- outputs=[i2v_output_video],
62
- fn=image2video.get_image
63
- )
64
-
65
- return dynamicrafter_iface
66
-
67
- def get_parser():
68
- parser = argparse.ArgumentParser()
69
- return parser
70
-
71
- if __name__ == "__main__":
72
- parser = get_parser()
73
- args = parser.parse_args()
74
-
75
- result_dir = os.path.join('./', 'results')
76
- dynamicrafter_iface = dynamicrafter_demo(result_dir)
77
- dynamicrafter_iface.queue(max_size=12)
78
- dynamicrafter_iface.launch(max_threads=1, share=True)
79
- #dynamicrafter_iface.launch(server_name='0.0.0.0', server_port=8080, max_threads=1)
 
 
1
+ import os
2
+ import argparse
3
+ import sys
4
+ import gradio as gr
5
+ from scripts.gradio.i2v_test_application import Image2Video
6
+ sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
7
+
8
+ i2v_examples_interp_512 = [
9
+ ['genshin_impact_img/ZHONGLI_source.webp', 'An anime character sitting down', 50, 3.5, 1.0, 30, 512, 'genshin_impact_img/ZHONGLI_target.webp'],
10
+ ['genshin_impact_img/AYATO_source.webp', 'an anime man smiling', 50, 3.5, 1.0, 30, 789, 'genshin_impact_img/AYATO_target.webp'],
11
+ ['prompts/512_interp/74906_1462_frame1.png', 'walking man', 50, 7.5, 1.0, 10, 123, 'prompts/512_interp/74906_1462_frame3.png'],
12
+ ['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'],
13
+ ['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'],
14
+ ]
15
+
16
+ def dynamicrafter_demo(result_dir='./tmp/', res=512):
17
+ if res == 1024:
18
+ resolution = '576_1024'
19
+ css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}"""
20
+ elif res == 512:
21
+ resolution = '320_512'
22
+ 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}"""
23
+ elif res == 256:
24
+ resolution = '256_256'
25
+ css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}"""
26
+ else:
27
+ raise NotImplementedError(f"Unsupported resolution: {res}")
28
+ image2video = Image2Video(result_dir, resolution=resolution)
29
+ with gr.Blocks(analytics_enabled=False, css=css) as dynamicrafter_iface:
30
+ dynamicrafter_iface.title = "Image to Video Converter (with Genshin Impact Demo)" # 添加标题
31
+
32
+ with gr.Tab(label='ToonCrafter_320x512'):
33
+ with gr.Column():
34
+ with gr.Row():
35
+ with gr.Column():
36
+ with gr.Row():
37
+ i2v_input_image = gr.Image(label="Input Image1", elem_id="input_img")
38
+ with gr.Row():
39
+ i2v_input_text = gr.Text(label='Prompts')
40
+ with gr.Row():
41
+ i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123)
42
+ i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
43
+ 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")
44
+ with gr.Row():
45
+ i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
46
+ i2v_motion = gr.Slider(minimum=5, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=10)
47
+ i2v_end_btn = gr.Button("Generate")
48
+ with gr.Column():
49
+ with gr.Row():
50
+ i2v_input_image2 = gr.Image(label="Input Image2", elem_id="input_img2")
51
+ with gr.Row():
52
+ i2v_output_video = gr.Video(label="Generated Video", elem_id="output_vid", autoplay=True, show_share_button=True)
53
+
54
+ gr.Examples(examples=i2v_examples_interp_512,
55
+ inputs=[i2v_input_image, i2v_input_text, i2v_steps, i2v_cfg_scale, i2v_eta, i2v_motion, i2v_seed, i2v_input_image2],
56
+ outputs=[i2v_output_video],
57
+ fn=image2video.get_image,
58
+ cache_examples=False,
59
+ )
60
+ 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],
61
+ outputs=[i2v_output_video],
62
+ fn=image2video.get_image
63
+ )
64
+
65
+ return dynamicrafter_iface
66
+
67
+ def get_parser():
68
+ parser = argparse.ArgumentParser()
69
+ parser.add_argument('--resolution', type=int, choices=[1024, 512, 256], default=512, help='Resolution for the image to video conversion')
70
+ return parser
71
+
72
+ if __name__ == "__main__":
73
+ parser = get_parser()
74
+ args = parser.parse_args()
75
+
76
+ result_dir = os.path.join('./', 'results')
77
+ dynamicrafter_iface = dynamicrafter_demo(result_dir, res=args.resolution)
78
+ dynamicrafter_iface.queue(max_size=12)
79
+ dynamicrafter_iface.launch(max_threads=1, share=True)
80
+ #dynamicrafter_iface.launch(server_name='0.0.0.0', server_port=8080, max_threads=1)