Spaces:
Paused
Paused
seawolf2357
commited on
Commit
•
93c305a
1
Parent(s):
cdb7645
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,24 @@
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
-
from diffusers import AnimateDiffPipeline, MotionAdapter, DPMSolverMultistepScheduler, AutoencoderKL, SparseControlNetModel
|
4 |
from diffusers.utils import export_to_gif, load_image
|
|
|
5 |
|
6 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def generate_video(prompt, negative_prompt, num_inference_steps, conditioning_frame_indices, controlnet_conditioning_scale):
|
|
|
|
|
|
|
9 |
motion_adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-3", torch_dtype=torch.float16).to(device)
|
10 |
controlnet = SparseControlNetModel.from_pretrained("guoyww/animatediff-sparsectrl-scribble", torch_dtype=torch.float16).to(device)
|
11 |
vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse", torch_dtype=torch.float16).to(device)
|
@@ -43,52 +56,18 @@ def generate_video(prompt, negative_prompt, num_inference_steps, conditioning_fr
|
|
43 |
export_to_gif(video, "output.gif")
|
44 |
return "output.gif"
|
45 |
|
46 |
-
|
47 |
-
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16).to(device)
|
48 |
-
pipe = AnimateDiffPipeline.from_pretrained("SG161222/Realistic_Vision_V6.0_B1_noVAE", motion_adapter=adapter, torch_dtype=torch.float16).to(device)
|
49 |
-
pipe.scheduler = EulerAncestralDiscreteScheduler(
|
50 |
-
beta_schedule="linear",
|
51 |
-
beta_start=0.00085,
|
52 |
-
beta_end=0.012,
|
53 |
-
)
|
54 |
-
|
55 |
-
pipe.enable_free_noise()
|
56 |
-
pipe.vae.enable_slicing()
|
57 |
-
pipe.enable_model_cpu_offload()
|
58 |
-
|
59 |
-
frames = pipe(
|
60 |
-
prompt,
|
61 |
-
num_frames=128,
|
62 |
-
num_inference_steps=100,
|
63 |
-
guidance_scale=15.0,
|
64 |
-
decode_chunk_size=1,
|
65 |
-
).frames[0]
|
66 |
-
|
67 |
-
export_to_gif(frames, "simple_output.gif")
|
68 |
-
return "simple_output.gif"
|
69 |
-
|
70 |
-
demo1 = gr.Interface(
|
71 |
fn=generate_video,
|
72 |
inputs=[
|
73 |
-
gr.Textbox(label="Prompt", value="
|
74 |
-
gr.Textbox(label="Negative Prompt", value="
|
75 |
gr.Slider(label="Number of Inference Steps", minimum=1, maximum=200, step=1, value=100),
|
76 |
gr.Textbox(label="Conditioning Frame Indices", value="[0, 8, 15]"),
|
77 |
gr.Slider(label="ControlNet Conditioning Scale", minimum=0.1, maximum=2.0, step=0.1, value=1.0)
|
78 |
],
|
79 |
outputs=gr.Image(label="Generated Video"),
|
80 |
-
title="
|
81 |
-
description="
|
82 |
)
|
83 |
|
84 |
-
demo2 = gr.Interface(
|
85 |
-
fn=generate_simple_video,
|
86 |
-
inputs=gr.Textbox(label="Prompt", value="An astronaut riding a horse on Mars."),
|
87 |
-
outputs=gr.Image(label="Generated Simple Video"),
|
88 |
-
title="Generate Simple Video with AnimateDiff",
|
89 |
-
description="Generate a simple video using the AnimateDiffPipeline."
|
90 |
-
)
|
91 |
-
|
92 |
-
demo = gr.TabbedInterface([demo1, demo2], ["Advanced Video Generation", "Simple Video Generation"])
|
93 |
-
|
94 |
demo.launch()
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
+
from diffusers import AnimateDiffPipeline, MotionAdapter, DPMSolverMultistepScheduler, AutoencoderKL, SparseControlNetModel
|
4 |
from diffusers.utils import export_to_gif, load_image
|
5 |
+
from transformers import pipeline
|
6 |
|
7 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
|
9 |
+
# 한글-영어 번역 모델 로드
|
10 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
11 |
+
|
12 |
+
def translate_korean_to_english(text):
|
13 |
+
if any('\u3131' <= char <= '\u3163' or '\uac00' <= char <= '\ud7a3' for char in text):
|
14 |
+
translated = translator(text)[0]['translation_text']
|
15 |
+
return translated
|
16 |
+
return text
|
17 |
+
|
18 |
def generate_video(prompt, negative_prompt, num_inference_steps, conditioning_frame_indices, controlnet_conditioning_scale):
|
19 |
+
prompt = translate_korean_to_english(prompt)
|
20 |
+
negative_prompt = translate_korean_to_english(negative_prompt)
|
21 |
+
|
22 |
motion_adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-3", torch_dtype=torch.float16).to(device)
|
23 |
controlnet = SparseControlNetModel.from_pretrained("guoyww/animatediff-sparsectrl-scribble", torch_dtype=torch.float16).to(device)
|
24 |
vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse", torch_dtype=torch.float16).to(device)
|
|
|
56 |
export_to_gif(video, "output.gif")
|
57 |
return "output.gif"
|
58 |
|
59 |
+
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
fn=generate_video,
|
61 |
inputs=[
|
62 |
+
gr.Textbox(label="Prompt (한글 또는 영어)", value="사이버펑크 도시의 공중 전망, 밤, 네온 불빛, 걸작, 고품질"),
|
63 |
+
gr.Textbox(label="Negative Prompt (한글 또는 영어)", value="저품질, 최악의 품질, 레터박스"),
|
64 |
gr.Slider(label="Number of Inference Steps", minimum=1, maximum=200, step=1, value=100),
|
65 |
gr.Textbox(label="Conditioning Frame Indices", value="[0, 8, 15]"),
|
66 |
gr.Slider(label="ControlNet Conditioning Scale", minimum=0.1, maximum=2.0, step=0.1, value=1.0)
|
67 |
],
|
68 |
outputs=gr.Image(label="Generated Video"),
|
69 |
+
title="AnimateDiffSparseControlNetPipeline을 사용한 비디오 생성",
|
70 |
+
description="AnimateDiffSparseControlNetPipeline을 사용하여 비디오를 생성합니다. 한글 또는 영어로 프롬프트를 입력할 수 있습니다."
|
71 |
)
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
demo.launch()
|