Spaces:
Running
Running
File size: 3,489 Bytes
a660631 f521e88 a660631 84448a9 a660631 b5515fe f521e88 d5479f6 f521e88 d5479f6 f521e88 a660631 b5515fe f521e88 a660631 b5515fe f521e88 da031b9 f521e88 8fad46e a660631 f521e88 a660631 af5481e a660631 ae34a8d 3c4344e a660631 3c4344e a660631 ae34a8d 3c4344e a660631 f521e88 a660631 f521e88 a660631 f521e88 a660631 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
#!/usr/bin/env python
import gradio as gr
from settings import (
DEFAULT_IMAGE_RESOLUTION,
DEFAULT_NUM_IMAGES,
MAX_IMAGE_RESOLUTION,
MAX_NUM_IMAGES,
MAX_SEED,
)
from utils import randomize_seed_fn
def create_demo(process):
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
image = gr.Image(value='images/canny_demo.jpg')
prompt = gr.Textbox(label="Prompt", value='BEAUTIFUL PORTRAIT PAINTINGS BY EMMA UBER')
run_button = gr.Button("Run")
with gr.Accordion("Advanced options", open=False):
num_samples = gr.Slider(
label="Number of images", minimum=1, maximum=MAX_NUM_IMAGES, value=DEFAULT_NUM_IMAGES, step=1
)
image_resolution = gr.Slider(
label="Image resolution",
minimum=256,
maximum=MAX_IMAGE_RESOLUTION,
value=DEFAULT_IMAGE_RESOLUTION,
step=256,
)
canny_low_threshold = gr.Slider(
label="Canny low threshold", minimum=0, maximum=1.0, value=0.1, step=0.05
)
canny_high_threshold = gr.Slider(
label="Canny high threshold", minimum=0, maximum=1.0, value=0.2, step=0.05
)
num_steps = gr.Slider(label="Number of steps", minimum=1, maximum=100, value=20, step=1)
guidance_scale = gr.Slider(label="Guidance scale", minimum=0.1, maximum=30.0, value=7.5, step=0.1)
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
a_prompt = gr.Textbox(label="Additional prompt", value="high-quality, extremely detailed, 4K")
n_prompt = gr.Textbox(
label="Negative prompt",
value="longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
)
with gr.Column():
result = gr.Gallery(label="Output", show_label=False, columns=2, object_fit="scale-down")
inputs = [
image,
prompt,
a_prompt,
n_prompt,
num_samples,
image_resolution,
num_steps,
guidance_scale,
seed,
canny_low_threshold,
canny_high_threshold,
]
prompt.submit(
fn=randomize_seed_fn,
inputs=[seed, randomize_seed],
outputs=seed,
queue=False,
api_name=False,
).then(
fn=process,
inputs=inputs,
outputs=result,
api_name=False,
)
run_button.click(
fn=randomize_seed_fn,
inputs=[seed, randomize_seed],
outputs=seed,
queue=False,
api_name=False,
).then(
fn=process,
inputs=inputs,
outputs=result,
api_name="canny",
)
return demo
if __name__ == "__main__":
from model import Model
model = Model(task_name="Canny")
demo = create_demo(model.process_canny)
demo.queue().launch()
|