Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,28 +2,9 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from diffusers import AnimateDiffPipeline, MotionAdapter, DPMSolverMultistepScheduler, AutoencoderKL, SparseControlNetModel, EulerAncestralDiscreteScheduler
|
4 |
from diffusers.utils import export_to_gif, load_image
|
5 |
-
from realesrgan import RealESRGAN
|
6 |
-
from PIL import Image
|
7 |
-
import cv2
|
8 |
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
|
11 |
-
def enhance_quality(image_path):
|
12 |
-
model = RealESRGAN(device, scale=4)
|
13 |
-
model.load_weights('RealESRGAN_x4.pth', download=True)
|
14 |
-
img = Image.open(image_path)
|
15 |
-
sr_image = model.predict(img)
|
16 |
-
enhanced_path = 'enhanced_' + image_path
|
17 |
-
sr_image.save(enhanced_path)
|
18 |
-
return enhanced_path
|
19 |
-
|
20 |
-
def denoise_image(image_path):
|
21 |
-
image = cv2.imread(image_path)
|
22 |
-
denoised_image = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
|
23 |
-
denoised_path = 'denoised_' + image_path
|
24 |
-
cv2.imwrite(denoised_path, denoised_image)
|
25 |
-
return denoised_path
|
26 |
-
|
27 |
def generate_video(prompt, negative_prompt, num_inference_steps, conditioning_frame_indices, controlnet_conditioning_scale):
|
28 |
motion_adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-3", torch_dtype=torch.float16).to(device)
|
29 |
controlnet = SparseControlNetModel.from_pretrained("guoyww/animatediff-sparsectrl-scribble", torch_dtype=torch.float16).to(device)
|
@@ -60,9 +41,7 @@ def generate_video(prompt, negative_prompt, num_inference_steps, conditioning_fr
|
|
60 |
).frames[0]
|
61 |
|
62 |
export_to_gif(video, "output.gif")
|
63 |
-
|
64 |
-
denoised_gif = denoise_image(enhanced_gif)
|
65 |
-
return denoised_gif
|
66 |
|
67 |
def generate_simple_video(prompt):
|
68 |
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16).to(device)
|
@@ -79,23 +58,21 @@ def generate_simple_video(prompt):
|
|
79 |
|
80 |
frames = pipe(
|
81 |
prompt,
|
82 |
-
num_frames=128,
|
83 |
-
num_inference_steps=100,
|
84 |
-
guidance_scale=15.0,
|
85 |
decode_chunk_size=1,
|
86 |
).frames[0]
|
87 |
|
88 |
export_to_gif(frames, "simple_output.gif")
|
89 |
-
|
90 |
-
denoised_gif = denoise_image(enhanced_gif)
|
91 |
-
return denoised_gif
|
92 |
|
93 |
demo1 = gr.Interface(
|
94 |
fn=generate_video,
|
95 |
inputs=[
|
96 |
gr.Textbox(label="Prompt", value="an aerial view of a cyberpunk city, night time, neon lights, masterpiece, high quality"),
|
97 |
gr.Textbox(label="Negative Prompt", value="low quality, worst quality, letterboxed"),
|
98 |
-
gr.Slider(label="Number of Inference Steps", minimum=1, maximum=200, step=1, value=100),
|
99 |
gr.Textbox(label="Conditioning Frame Indices", value="[0, 8, 15]"),
|
100 |
gr.Slider(label="ControlNet Conditioning Scale", minimum=0.1, maximum=2.0, step=0.1, value=1.0)
|
101 |
],
|
@@ -114,5 +91,4 @@ demo2 = gr.Interface(
|
|
114 |
|
115 |
demo = gr.TabbedInterface([demo1, demo2], ["Advanced Video Generation", "Simple Video Generation"])
|
116 |
|
117 |
-
demo.launch()
|
118 |
-
#demo.launch(server_name="0.0.0.0", server_port=7910)
|
|
|
2 |
import gradio as gr
|
3 |
from diffusers import AnimateDiffPipeline, MotionAdapter, DPMSolverMultistepScheduler, AutoencoderKL, SparseControlNetModel, EulerAncestralDiscreteScheduler
|
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)
|
|
|
41 |
).frames[0]
|
42 |
|
43 |
export_to_gif(video, "output.gif")
|
44 |
+
return "output.gif"
|
|
|
|
|
45 |
|
46 |
def generate_simple_video(prompt):
|
47 |
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16).to(device)
|
|
|
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="an aerial view of a cyberpunk city, night time, neon lights, masterpiece, high quality"),
|
74 |
gr.Textbox(label="Negative Prompt", value="low quality, worst quality, letterboxed"),
|
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 |
],
|
|
|
91 |
|
92 |
demo = gr.TabbedInterface([demo1, demo2], ["Advanced Video Generation", "Simple Video Generation"])
|
93 |
|
94 |
+
demo.launch()
|
|