BestWishYsh commited on
Commit
24fe9ed
1 Parent(s): 5ff5ddc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -65
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
- @spaces.GPU(duration=300)
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
- # inference_config = OmegaConf.load(inference_config_path)[1]
213
- # tokenizer = CLIPTokenizer.from_pretrained(pretrained_model_path, subfolder="tokenizer")
214
- # text_encoder = CLIPTextModel.from_pretrained(pretrained_model_path, subfolder="text_encoder").cuda()
215
- # vae = AutoencoderKL.from_pretrained(pretrained_model_path, subfolder="vae").cuda()
216
- # unet = UNet3DConditionModel.from_pretrained_2d(pretrained_model_path, subfolder="unet", unet_additional_kwargs=OmegaConf.to_container(inference_config.unet_additional_kwargs)).cuda()
217
- # text_model = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14")
218
- # controller = MagicTimeController(tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, unet=unet, text_model=text_model)
219
- controller = MagicTimeController()
220
-
221
- def ui():
222
- with gr.Blocks(css=css) as demo:
223
- gr.Markdown(
224
- """
225
- <div style='display: flex; align-items: center; justify-content: center; text-align: center;'>
226
- <img src='https://www.pnglog.com/48rWnj.png' style='width: 300px; height: auto; margin-right: 10px;' />
227
- </div>
228
-
229
- <h2 align="center"> <a href="https://github.com/PKU-YuanGroup/MagicTime">MagicTime: Time-lapse Video Generation Models as Metamorphic Simulators</a></h2>
230
- <h5 style="text-align:left;">If you like our project, please give us a star ⭐ on GitHub for the latest update.</h5>
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
- with gr.Column():
258
- result_video = gr.Video( label="Generated Animation", interactive=False )
259
- json_config = gr.Json( label="Config", value=None )
 
 
 
 
 
 
260
 
261
- inputs = [dreambooth_dropdown, motion_module_dropdown, prompt_textbox, negative_prompt_textbox, width_slider, height_slider, seed_textbox]
262
- outputs = [result_video, json_config]
263
-
264
- generate_button.click( fn=controller.magictime, inputs=inputs, outputs=outputs )
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
- demo = ui()
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()