Spaces:
Runtime error
Runtime error
kevinwang676
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffsynth import ModelManager, SDVideoPipeline, ControlNetConfigUnit, VideoData, save_video
|
2 |
+
import torch, spaces
|
3 |
+
|
4 |
+
# Load models
|
5 |
+
model_manager = ModelManager(torch_dtype=torch.float16, device="cuda")
|
6 |
+
model_manager.load_textual_inversions("models/textual_inversion")
|
7 |
+
model_manager.load_models([
|
8 |
+
"models/stable_diffusion/flat2DAnimerge_v45Sharp.safetensors",
|
9 |
+
"models/AnimateDiff/mm_sd_v15_v2.ckpt",
|
10 |
+
"models/ControlNet/control_v11p_sd15_lineart.pth",
|
11 |
+
"models/ControlNet/control_v11f1e_sd15_tile.pth",
|
12 |
+
])
|
13 |
+
pipe = SDVideoPipeline.from_model_manager(
|
14 |
+
model_manager,
|
15 |
+
[
|
16 |
+
ControlNetConfigUnit(
|
17 |
+
processor_id="lineart",
|
18 |
+
model_path="models/ControlNet/control_v11p_sd15_lineart.pth",
|
19 |
+
scale=0.5
|
20 |
+
),
|
21 |
+
ControlNetConfigUnit(
|
22 |
+
processor_id="tile",
|
23 |
+
model_path="models/ControlNet/control_v11f1e_sd15_tile.pth",
|
24 |
+
scale=0.5
|
25 |
+
)
|
26 |
+
]
|
27 |
+
)
|
28 |
+
|
29 |
+
@spaces.GPU(duration=500)
|
30 |
+
def generate_video(inp_vid):
|
31 |
+
video = VideoData(
|
32 |
+
video_file=inp_vid,
|
33 |
+
height=1024, width=1024)
|
34 |
+
input_video = [video[i] for i in range(0, 60)]
|
35 |
+
|
36 |
+
# Toon shading (20G VRAM)
|
37 |
+
torch.manual_seed(0)
|
38 |
+
output_video = pipe(
|
39 |
+
prompt="best quality, perfect anime illustration, light, a girl is dancing, smile, solo",
|
40 |
+
negative_prompt="verybadimagenegative_v1.3",
|
41 |
+
cfg_scale=3, clip_skip=2,
|
42 |
+
controlnet_frames=input_video, num_frames=len(input_video),
|
43 |
+
num_inference_steps=10, height=1024, width=1024,
|
44 |
+
animatediff_batch_size=32, animatediff_stride=16,
|
45 |
+
vram_limit_level=0,
|
46 |
+
)
|
47 |
+
|
48 |
+
# Save video
|
49 |
+
save_video(output_video, "output_video.mp4", fps=60)
|
50 |
+
|
51 |
+
return "output_video.mp4"
|
52 |
+
|
53 |
+
|
54 |
+
app = gr.Blocks(theme="JohnSmith9982/small_and_pretty")
|
55 |
+
with app:
|
56 |
+
gr.Markdown("# <center>🌊💕🎶 Diffutoon</center>")
|
57 |
+
inp_vid = gr.Video(label="请上传一个视频文件")
|
58 |
+
btn = gr.Button("一键开启视频转绘", variant="primary")
|
59 |
+
out_vid = gr.Video(label="请上传一个视频文件")
|
60 |
+
|
61 |
+
btn.click(generate_video, inp_vid, out_vid)
|
62 |
+
|
63 |
+
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。请自觉合规使用此程序,程序开发者不负有任何责任。</center>")
|
64 |
+
gr.HTML('''
|
65 |
+
<div class="footer">
|
66 |
+
<p>🌊🏞️🎶 - 江水东流急,滔滔无尽声。 明·顾璘
|
67 |
+
</p>
|
68 |
+
</div>
|
69 |
+
''')
|
70 |
+
#app.queue(max_size=40, api_open=False)
|
71 |
+
app.launch(show_error=True)
|