BestWishYsh
commited on
Commit
•
24fe9ed
1
Parent(s):
5ff5ddc
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import copy
|
3 |
import torch
|
4 |
import random
|
|
|
5 |
import gradio as gr
|
6 |
from glob import glob
|
7 |
from omegaconf import OmegaConf
|
@@ -14,7 +15,6 @@ from transformers import CLIPTextModel, CLIPTokenizer
|
|
14 |
from utils.unet import UNet3DConditionModel
|
15 |
from utils.pipeline_magictime import MagicTimePipeline
|
16 |
from utils.util import save_videos_grid, convert_ldm_unet_checkpoint, convert_ldm_clip_checkpoint, convert_ldm_vae_checkpoint, load_diffusers_lora_unet, convert_ldm_clip_text_model
|
17 |
-
import spaces
|
18 |
|
19 |
pretrained_model_path = "./ckpts/Base_Model/stable-diffusion-v1-5"
|
20 |
inference_config_path = "./sample_configs/RealisticVision.yaml"
|
@@ -62,7 +62,7 @@ examples = [
|
|
62 |
print(f"### Cleaning cached examples ...")
|
63 |
os.system(f"rm -rf gradio_cached_examples/")
|
64 |
|
65 |
-
|
66 |
class MagicTimeController:
|
67 |
def __init__(self):
|
68 |
|
@@ -208,72 +208,51 @@ class MagicTimeController:
|
|
208 |
"dreambooth": dreambooth_dropdown,
|
209 |
}
|
210 |
return gr.Video(value=save_sample_path), gr.Json(value=json_config)
|
|
|
|
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
[GitHub](https://github.com/PKU-YuanGroup/MagicTime) | [arXiv](https://arxiv.org/abs/2404.05014) | [Home Page](https://pku-yuangroup.github.io/MagicTime/) | [Dataset](https://drive.google.com/drive/folders/1WsomdkmSp3ql3ImcNsmzFuSQ9Qukuyr8?usp=sharing)
|
233 |
-
"""
|
234 |
-
)
|
235 |
-
with gr.Row():
|
236 |
-
with gr.Column():
|
237 |
-
dreambooth_dropdown = gr.Dropdown( label="DreamBooth Model", choices=controller.dreambooth_list, value=controller.dreambooth_list[0], interactive=True )
|
238 |
-
motion_module_dropdown = gr.Dropdown( label="Motion Module", choices=controller.motion_module_list, value=controller.motion_module_list[0], interactive=True )
|
239 |
-
|
240 |
-
dreambooth_dropdown.change(fn=controller.update_dreambooth, inputs=[dreambooth_dropdown], outputs=[dreambooth_dropdown])
|
241 |
-
motion_module_dropdown.change(fn=controller.update_motion_module, inputs=[motion_module_dropdown], outputs=[motion_module_dropdown])
|
242 |
-
|
243 |
-
prompt_textbox = gr.Textbox( label="Prompt", lines=3 )
|
244 |
-
negative_prompt_textbox = gr.Textbox( label="Negative Prompt", lines=3, value="worst quality, low quality, nsfw, logo")
|
245 |
-
|
246 |
-
with gr.Accordion("Advance", open=False):
|
247 |
-
with gr.Row():
|
248 |
-
width_slider = gr.Slider( label="Width", value=512, minimum=256, maximum=1024, step=64 )
|
249 |
-
height_slider = gr.Slider( label="Height", value=512, minimum=256, maximum=1024, step=64 )
|
250 |
-
with gr.Row():
|
251 |
-
seed_textbox = gr.Textbox( label="Seed (-1 means random)", value=-1)
|
252 |
-
seed_button = gr.Button(value="\U0001F3B2", elem_classes="toolbutton")
|
253 |
-
seed_button.click(fn=lambda: gr.Textbox(value=random.randint(1, 1e16)), inputs=[], outputs=[seed_textbox])
|
254 |
-
|
255 |
-
generate_button = gr.Button( value="Generate", variant='primary' )
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
gr.Markdown(
|
267 |
-
"""
|
268 |
-
<h5 style="text-align:left;">Warning: It is worth noting that even if we use the same seed and prompt but we change a machine, the results will be different. If you find a better seed and prompt, please tell me in a GitHub issue.</h5>
|
269 |
-
"""
|
270 |
-
)
|
271 |
-
gr.Examples( fn=controller.magictime, examples=examples, inputs=inputs, outputs=outputs, cache_examples=True )
|
272 |
-
|
273 |
-
return demo
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
if __name__ == "__main__":
|
277 |
-
|
278 |
-
demo.queue(max_size=20)
|
279 |
-
demo.launch()
|
|
|
2 |
import copy
|
3 |
import torch
|
4 |
import random
|
5 |
+
import spaces
|
6 |
import gradio as gr
|
7 |
from glob import glob
|
8 |
from omegaconf import OmegaConf
|
|
|
15 |
from utils.unet import UNet3DConditionModel
|
16 |
from utils.pipeline_magictime import MagicTimePipeline
|
17 |
from utils.util import save_videos_grid, convert_ldm_unet_checkpoint, convert_ldm_clip_checkpoint, convert_ldm_vae_checkpoint, load_diffusers_lora_unet, convert_ldm_clip_text_model
|
|
|
18 |
|
19 |
pretrained_model_path = "./ckpts/Base_Model/stable-diffusion-v1-5"
|
20 |
inference_config_path = "./sample_configs/RealisticVision.yaml"
|
|
|
62 |
print(f"### Cleaning cached examples ...")
|
63 |
os.system(f"rm -rf gradio_cached_examples/")
|
64 |
|
65 |
+
|
66 |
class MagicTimeController:
|
67 |
def __init__(self):
|
68 |
|
|
|
208 |
"dreambooth": dreambooth_dropdown,
|
209 |
}
|
210 |
return gr.Video(value=save_sample_path), gr.Json(value=json_config)
|
211 |
+
|
212 |
+
controller = MagicTimeController()
|
213 |
|
214 |
+
@spaces.GPU
|
215 |
+
def magictime_interface(
|
216 |
+
dreambooth_dropdown,
|
217 |
+
motion_module_dropdown,
|
218 |
+
prompt_textbox,
|
219 |
+
negative_prompt_textbox,
|
220 |
+
width_slider,
|
221 |
+
height_slider,
|
222 |
+
seed_textbox,
|
223 |
+
):
|
224 |
+
return controller.magictime(
|
225 |
+
dreambooth_dropdown,
|
226 |
+
motion_module_dropdown,
|
227 |
+
prompt_textbox,
|
228 |
+
negative_prompt_textbox,
|
229 |
+
width_slider,
|
230 |
+
height_slider,
|
231 |
+
seed_textbox,
|
232 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
+
inputs = [
|
235 |
+
gr.Dropdown(label="DreamBooth Model", choices=controller.dreambooth_list, value=controller.dreambooth_list[0]),
|
236 |
+
gr.Dropdown(label="Motion Module", choices=controller.motion_module_list, value=controller.motion_module_list[0]),
|
237 |
+
gr.Textbox(label="Prompt", lines=3),
|
238 |
+
gr.Textbox(label="Negative Prompt", lines=3, value="worst quality, low quality, nsfw, logo"),
|
239 |
+
gr.Slider(label="Width", value=512, minimum=256, maximum=1024, step=64),
|
240 |
+
gr.Slider(label="Height", value=512, minimum=256, maximum=1024, step=64),
|
241 |
+
gr.Textbox(label="Seed", value="-1"),
|
242 |
+
]
|
243 |
|
244 |
+
outputs = [
|
245 |
+
gr.Video(label="Generated Animation"),
|
246 |
+
gr.Json(label="Config")
|
247 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
+
iface = gr.Interface(
|
250 |
+
fn=magictime_interface,
|
251 |
+
inputs=inputs,
|
252 |
+
outputs=outputs,
|
253 |
+
title="MagicTime Controller",
|
254 |
+
examples=examples
|
255 |
+
)
|
256 |
|
257 |
if __name__ == "__main__":
|
258 |
+
iface.launch()
|
|
|
|