Spaces:
Sleeping
Sleeping
fixed gradio
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ def forward_diffusion_sample(x_0, t):
|
|
| 41 |
return sqrt_alphas_cumprod_t.to(device) * x_0.to(device) \
|
| 42 |
+ sqrt_one_minus_alphas_cumprod_t.to(device) * noise.to(device), noise.to(device)
|
| 43 |
|
| 44 |
-
T =
|
| 45 |
betas = cosine_beta_schedule(timesteps=T)
|
| 46 |
# Pre-calculate different terms for closed form
|
| 47 |
alphas = 1. - betas
|
|
@@ -89,7 +89,7 @@ torch.cuda.empty_cache()
|
|
| 89 |
|
| 90 |
def save_video_frames_as_mp4(frames, fps, save_path):
|
| 91 |
frame_h, frame_w = frames[0].shape[2:]
|
| 92 |
-
fourcc = cv2.VideoWriter_fourcc('
|
| 93 |
video = cv2.VideoWriter(save_path, fourcc, fps, (frame_w, frame_h))
|
| 94 |
frames = frames[0]
|
| 95 |
for frame in frames:
|
|
@@ -157,7 +157,8 @@ def get_image_embedding(input_image):
|
|
| 157 |
return encoder_hidden_states
|
| 158 |
|
| 159 |
def predict_fn(img_path, progress=gr.Progress()):
|
| 160 |
-
|
|
|
|
| 161 |
encoder_hidden_states = get_image_embedding(input_image=image)
|
| 162 |
encoded_image = VAE_encode(image)
|
| 163 |
noise_video = torch.randn([1, frameLimit, 4, 80, 64]).to(device)
|
|
@@ -171,19 +172,26 @@ def predict_fn(img_path, progress=gr.Progress()):
|
|
| 171 |
save_video_frames_as_mp4(final_video, 25, "result.mp4")
|
| 172 |
return "result.mp4"
|
| 173 |
|
| 174 |
-
with gr.
|
| 175 |
-
with gr.
|
| 176 |
-
with gr.
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
[
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
return sqrt_alphas_cumprod_t.to(device) * x_0.to(device) \
|
| 42 |
+ sqrt_one_minus_alphas_cumprod_t.to(device) * noise.to(device), noise.to(device)
|
| 43 |
|
| 44 |
+
T = 10
|
| 45 |
betas = cosine_beta_schedule(timesteps=T)
|
| 46 |
# Pre-calculate different terms for closed form
|
| 47 |
alphas = 1. - betas
|
|
|
|
| 89 |
|
| 90 |
def save_video_frames_as_mp4(frames, fps, save_path):
|
| 91 |
frame_h, frame_w = frames[0].shape[2:]
|
| 92 |
+
fourcc = cv2.VideoWriter_fourcc(*'avc1')
|
| 93 |
video = cv2.VideoWriter(save_path, fourcc, fps, (frame_w, frame_h))
|
| 94 |
frames = frames[0]
|
| 95 |
for frame in frames:
|
|
|
|
| 157 |
return encoder_hidden_states
|
| 158 |
|
| 159 |
def predict_fn(img_path, progress=gr.Progress()):
|
| 160 |
+
img2tensor = get_transform()
|
| 161 |
+
image = img2tensor(img_path).unsqueeze(0).to(device)
|
| 162 |
encoder_hidden_states = get_image_embedding(input_image=image)
|
| 163 |
encoded_image = VAE_encode(image)
|
| 164 |
noise_video = torch.randn([1, frameLimit, 4, 80, 64]).to(device)
|
|
|
|
| 172 |
save_video_frames_as_mp4(final_video, 25, "result.mp4")
|
| 173 |
return "result.mp4"
|
| 174 |
|
| 175 |
+
with gr.Blocks() as demo:
|
| 176 |
+
with gr.Tab("Image-to-Video"):
|
| 177 |
+
with gr.Row():
|
| 178 |
+
with gr.Column():
|
| 179 |
+
image_input = gr.Image(type="pil", label="Input Image")
|
| 180 |
+
img_generate = gr.Button("Generate Video")
|
| 181 |
+
with gr.Column():
|
| 182 |
+
img_output = gr.Video(label="Generated Video")
|
| 183 |
+
gr.Examples(
|
| 184 |
+
examples=[
|
| 185 |
+
['sample/blue.jpg',]
|
| 186 |
+
],
|
| 187 |
+
inputs=[image_input],
|
| 188 |
+
outputs=[]
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
img_generate.click(
|
| 192 |
+
fn=predict_fn,
|
| 193 |
+
inputs=image_input,
|
| 194 |
+
outputs=img_output
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
demo.launch()
|
models/__pycache__/diffusion_model.cpython-311.pyc
ADDED
|
Binary file (40.4 kB). View file
|
|
|
models/__pycache__/diffusion_model.cpython-312.pyc
ADDED
|
Binary file (35.2 kB). View file
|
|
|
models/__pycache__/unet_dual_encoder.cpython-311.pyc
ADDED
|
Binary file (3.78 kB). View file
|
|
|
models/__pycache__/unet_dual_encoder.cpython-312.pyc
ADDED
|
Binary file (3.4 kB). View file
|
|
|