hysts/ControlNet
993
1# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_hough2image.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 Hough Line Maps')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 num_samples = gr.Slider(label='Images',17 minimum=1,18 maximum=max_images,19 value=default_num_images,20 step=1)21 image_resolution = gr.Slider(label='Image Resolution',22 minimum=256,23 maximum=512,24 value=512,25 step=256)26 detect_resolution = gr.Slider(label='Hough Resolution',27 minimum=128,28 maximum=512,29 value=512,30 step=1)31 mlsd_value_threshold = gr.Slider(32 label='Hough value threshold (MLSD)',33 minimum=0.01,34 maximum=2.0,35 value=0.1,36 step=0.01)37 mlsd_distance_threshold = gr.Slider(38 label='Hough distance threshold (MLSD)',39 minimum=0.01,40 maximum=20.0,41 value=0.1,42 step=0.01)43 num_steps = gr.Slider(label='Steps',44 minimum=1,45 maximum=100,46 value=20,47 step=1)48 guidance_scale = gr.Slider(label='Guidance Scale',49 minimum=0.1,50 maximum=30.0,51 value=9.0,52 step=0.1)53 seed = gr.Slider(label='Seed',54 minimum=-1,55 maximum=2147483647,56 step=1,57 randomize=True)58 a_prompt = gr.Textbox(59 label='Added Prompt',60 value='best quality, extremely detailed')61 n_prompt = gr.Textbox(62 label='Negative Prompt',63 value=64 'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'65 )66 with gr.Column():67 result = gr.Gallery(label='Output',68 show_label=False,69 elem_id='gallery').style(grid=2,70 height='auto')71 inputs = [72 input_image,73 prompt,74 a_prompt,75 n_prompt,76 num_samples,77 image_resolution,78 detect_resolution,79 num_steps,80 guidance_scale,81 seed,82 mlsd_value_threshold,83 mlsd_distance_threshold,84 ]85 prompt.submit(fn=process, inputs=inputs, outputs=result)86 run_button.click(fn=process,87 inputs=inputs,88 outputs=result,89 api_name='hough')90 return demo91 92 93if __name__ == '__main__':94 from model import Model95 model = Model()96 demo = create_demo(model.process_hough)97 demo.queue().launch()98 