CoolFace
Apppublic

hysts/ControlNet

sourceHugging Facemitupdated 3y agoView on Hugging Face
993likes
app_pose.py90 linesDownload Raw Back to root
1# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_pose2image.py2# The original license file is LICENSE.ControlNet in this repo.3import gradio as gr4 5 6def create_demo(process, max_images=12, default_num_images=3):7    with gr.Blocks() as demo:8        with gr.Row():9            gr.Markdown('## Control Stable Diffusion with Human Pose')10        with gr.Row():11            with gr.Column():12                input_image = gr.Image(source='upload', type='numpy')13                prompt = gr.Textbox(label='Prompt')14                run_button = gr.Button(label='Run')15                with gr.Accordion('Advanced options', open=False):16                    is_pose_image = gr.Checkbox(label='Is pose image',17                                                value=False)18                    gr.Markdown(19                        'You can use [PoseMaker2](https://huggingface.co/spaces/jonigata/PoseMaker2) to create pose images.'20                    )21                    num_samples = gr.Slider(label='Images',22                                            minimum=1,23                                            maximum=max_images,24                                            value=default_num_images,25                                            step=1)26                    image_resolution = gr.Slider(label='Image Resolution',27                                                 minimum=256,28                                                 maximum=512,29                                                 value=512,30                                                 step=256)31                    detect_resolution = gr.Slider(label='OpenPose Resolution',32                                                  minimum=128,33                                                  maximum=512,34                                                  value=512,35                                                  step=1)36                    num_steps = gr.Slider(label='Steps',37                                          minimum=1,38                                          maximum=100,39                                          value=20,40                                          step=1)41                    guidance_scale = gr.Slider(label='Guidance Scale',42                                               minimum=0.1,43                                               maximum=30.0,44                                               value=9.0,45                                               step=0.1)46                    seed = gr.Slider(label='Seed',47                                     minimum=-1,48                                     maximum=2147483647,49                                     step=1,50                                     randomize=True)51                    a_prompt = gr.Textbox(52                        label='Added Prompt',53                        value='best quality, extremely detailed')54                    n_prompt = gr.Textbox(55                        label='Negative Prompt',56                        value=57                        'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'58                    )59            with gr.Column():60                result = gr.Gallery(label='Output',61                                    show_label=False,62                                    elem_id='gallery').style(grid=2,63                                                             height='auto')64        inputs = [65            input_image,66            prompt,67            a_prompt,68            n_prompt,69            num_samples,70            image_resolution,71            detect_resolution,72            num_steps,73            guidance_scale,74            seed,75            is_pose_image,76        ]77        prompt.submit(fn=process, inputs=inputs, outputs=result)78        run_button.click(fn=process,79                         inputs=inputs,80                         outputs=result,81                         api_name='pose')82    return demo83 84 85if __name__ == '__main__':86    from model import Model87    model = Model()88    demo = create_demo(model.process_pose)89    demo.queue().launch()90