CoolFace
Apppublic

cocktailpeanut/MotionDirector

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py124 linesDownload Raw Back to root
1import gradio as gr2import os3from demo.motiondirector import MotionDirector4 5from huggingface_hub import snapshot_download6 7snapshot_download(repo_id="cerspense/zeroscope_v2_576w", local_dir="./zeroscope_v2_576w/")8snapshot_download(repo_id="ruizhaocv/MotionDirector", local_dir="./MotionDirector_pretrained")9 10is_spaces = True if "SPACE_ID" in os.environ else False11true_for_shared_ui = False  # This will be true only if you are in a shared UI12if (is_spaces):13    true_for_shared_ui = True if "ruizhaocv/MotionDirector" in os.environ['SPACE_ID'] else False14 15 16 17runner = MotionDirector()18 19 20def motiondirector(model_select, text_pormpt, neg_text_pormpt, random_seed=1, steps=25, guidance_scale=7.5, baseline_select=False):21    return runner(model_select, text_pormpt, neg_text_pormpt, int(random_seed) if random_seed != "" else 1, int(steps), float(guidance_scale), baseline_select)22 23 24with gr.Blocks() as demo:25    gr.HTML(26        """27        <div style="display: flex; justify-content: center; align-items: center; text-align: center;">28        <a href="https://github.com/showlab/MotionDirector" style="margin-right: 20px; text-decoration: none; display: flex; align-items: center;">29        </a>30        <div>31            <h1 >MotionDirector: Motion Customization of Text-to-Video Diffusion Models</h1>32            <h5 style="margin: 0;">More MotionDirectors are on the way. Stay tuned 🔥!</h5>33             <h5 style="margin: 0;"> If you like our project, please give us a star ✨ on Github for the latest update.</h5>34            </br>35            <div style="display: flex; justify-content: center; align-items: center; text-align: center;>36                <a href="https://arxiv.org/abs/2310.08465"></a>37                <a href="https://arxiv.org/abs/2310.08465"><img src="https://img.shields.io/badge/arXiv-2310.08465-b31b1b.svg"></a>&nbsp;&nbsp;38                <a href="https://showlab.github.io/MotionDirector"><img src="https://img.shields.io/badge/Project_Page-MotionDirector-green"></a>&nbsp;&nbsp;39                <a href="https://github.com/showlab/MotionDirector"><img src="https://img.shields.io/badge/Github-Code-blue"></a>&nbsp;&nbsp;40            </div>41        </div>42        </div>43        """)44    with gr.Row():45        generated_video_baseline = gr.Video(format="mp4", label="Video Generated by base model (ZeroScope with same seed)")46        generated_video = gr.Video(format="mp4", label="Video Generated by MotionDirector")47 48        with gr.Column():49            baseline_select = gr.Checkbox(label="Compare with baseline (ZeroScope with same seed)", info="Run baseline? Note: Inference time will be doubled.")50            random_seed = gr.Textbox(label="Random seed", value=1, info="default: 1")51            sampling_steps = gr.Textbox(label="Sampling steps", value=30, info="default: 30")52            guidance_scale = gr.Textbox(label="Guidance scale", value=12, info="default: 12")53 54    with gr.Row():55        model_select = gr.Dropdown(56            ["1-1: [Cinematic Shots] -- Zoom Out",57             "1-2: [Cinematic Shots] -- Zoom In",58             "1-3: [Cinematic Shots] -- Dolly Zoom (Hitchcockian Zoom) 1",59             "1-4: [Cinematic Shots] -- Dolly Zoom (Hitchcockian Zoom) 2",60             "1-5: [Cinematic Shots] -- Follow",61             "1-6: [Cinematic Shots] -- Reverse Follow",62             "1-7: [Cinematic Shots] -- Chest Transition",63             "1-8: [Cinematic Shots] -- Mini Jib Reveal",64             "1-9: [Cinematic Shots] -- Orbit",65             "1-10: [Cinematic Shots] -- Pull Back",66             "2-1: [Object Trajectory] -- Right to Left",67             "2-2: [Object Trajectory] -- Left to Right",68             "3-1: [Sports Concepts] -- Riding Bicycle",69             "3-2: [Sports Concepts] -- Riding Horse",70             "3-3: [Sports Concepts] -- Lifting Weights",71             "3-4: [Sports Concepts] -- Playing Golf",72             "3-5: [Sports Concepts] -- Skateboarding",73             ],74            label="Select MotionDirector *",75            info="Which MotionDirector would you like to use!"76        )77 78        text_pormpt = gr.Textbox(label="Text Prompt *", value='', placeholder="Input your text prompt here!")79        neg_text_pormpt = gr.Textbox(label="Negative Text Prompt", value='', placeholder="default: None")80 81    submit = gr.Button("Generate")82 83    # when the `submit` button is clicked84    submit.click(85        motiondirector,86        [model_select, text_pormpt, neg_text_pormpt, random_seed, sampling_steps, guidance_scale, baseline_select],87        [generated_video, generated_video_baseline]88    )89 90    gr.Markdown("Note: * denotes required field. Tips: More detailed text prompt is helpful for generating better results.")91    # Examples92    gr.Markdown("## Examples")93    gr.Examples(94        fn=motiondirector,95        examples=[96            ["1-1: [Cinematic Shots] -- Zoom Out", "A spaceman standing on the moon captured with a zoom out.",97             5894219],98            ["1-2: [Cinematic Shots] -- Zoom In", "A polar bear standing at the top of a snowy mountain captured with a zoom in.", 9036551],99            ["1-3: [Cinematic Shots] -- Dolly Zoom (Hitchcockian Zoom) 1", "A panda standing in front of an ancient Chinese temple captured with a dolly zoom.", 150518],100            ["1-4: [Cinematic Shots] -- Dolly Zoom (Hitchcockian Zoom) 2", "A lion sitting on top of a cliff captured with a dolly zoom.", 1675932],101            ["1-5: [Cinematic Shots] -- Follow", "A fireman is walking through fire captured with a follow cinematic shot.", 2927089],102            ["1-6: [Cinematic Shots] -- Reverse Follow", "A fireman is walking through fire captured with a reverse follow cinematic shot.", 271723],103            ["1-7: [Cinematic Shots] -- Chest Transition", "An ancient Roman soldier walks through the crowd on the street captured with a chest transition cinematic shot.", 4126807],104            ["1-8: [Cinematic Shots] -- Mini Jib Reveal",105             "A British Redcoat soldier is walking through the mountains captured with a mini jib reveal cinematic shot.",106             566917],107            ["1-9: [Cinematic Shots] -- Orbit", "A spaceman on the moon captured with an orbit cinematic shot.", 764227],108            ["1-10: [Cinematic Shots] -- Pull Back", "A woman looking at a volcano erupting in the distance captured with a pull back cinematic shot.",109             6878528],110            ["2-1: [Object Trajectory] -- Right to Left", "A tank is running on the moon.", 2047046],111            ["2-2: [Object Trajectory] -- Left to Right", "A lion is running past the pyramids.", 2562209],112            ["3-1: [Sports Concepts] -- Riding Bicycle", "An astronaut is riding a bicycle past the pyramids Mars 4K high quality highly detailed.", 4422954],113            ["3-2: [Sports Concepts] -- Riding Horse", "A man riding an elephant through the jungle.", 6230765],114            ["3-3: [Sports Concepts] -- Lifting Weights", "A panda is lifting weights in a garden.", 1699276],115            ["3-4: [Sports Concepts] -- Playing Golf", "A monkey is playing golf on a field full of flowers.", 4156856],116            ["3-5: [Sports Concepts] -- Skateboarding", "An astronaut is skateboarding on Mars.", 6615212],117        ],118        inputs=[model_select, text_pormpt, random_seed],119        outputs=generated_video,120        examples_per_page=20,121    )122 123demo.queue(max_size=15)124demo.launch(share=False)