Spaces:
Sleeping
Sleeping
File size: 4,207 Bytes
fa71535 5ed5eda bea529c fa71535 dce4839 dbebde5 dce4839 5cd8336 e2d7ac8 dce4839 dbebde5 1e32deb fa71535 97ab466 9c2d32b 9f61c1e b84b8a1 9f61c1e bfc85f9 fa71535 ca89467 fa71535 3794395 bfc85f9 3794395 ca89467 3794395 b84b8a1 98256ec cd34980 98256ec b84b8a1 9f61c1e 84839aa 97ab466 fa71535 5cd8336 fa71535 ca89467 5cd8336 ca89467 d0f700c ca89467 fa71535 9b843da |
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 |
import gradio as gr
from PIL import Image, ImageOps
import numpy as np
#SER_SKETCH=Image.fromarray(np.zeros((1024,1024)))
def get_img_from_sketchpad(img):
#global SER_SKETCH
return Image.fromarray(img["composite"]) #ImageOps.invert(Image.fromarray((img["composite"])))#,'L')
#def set_ser_sketch(img):
#global SER_SKETCH
#SER_SKETCH=img
def ui(controller):#get_first_result,get_second_result): #controller):
with gr.Blocks() as ui:
with gr.Row():
with gr.Column():
sketch=gr.Sketchpad(sources = 'upload', label='Sketch', type='numpy', image_mode="L", brush=gr.Brush()) #gr.Image(sources = 'upload', label='Sketch', type = 'pil')
ser_image=gr.Image(type="pil")#, visible=False)
with gr.Column():
improved_sketch_view = gr.Image(type="pil", label="Improved Sketch")
#with gr.Row():
with gr.Column():
result=gr.Image(type="pil", label="Colored Image")
with gr.Row():
with gr.Column():
first_prompt = gr.Textbox(label="Prompt to Improve Sketch", lines=3)
first_negative_prompt = gr.Textbox(label="Negative prompt", lines=3, value="sketch, lowres, error, extra digit, fewer digits, cropped, worst quality,low quality, normal quality, jpeg artifacts, blurry")
firts_prompt_helper = gr.Button(value="Prompt Helper", variant="primary")
#controlnet_scale = gr.Slider(minimum=0.5, maximum=1.25, value=0.5, step=0.01, label="Contr")
improve_sketch = gr.Button(value="Improve Sketch", variant="primary")
with gr.Column():
second_prompt = gr.Textbox(label="Prompt to Coloring Image", lines=3)
second_negative_prompt = gr.Textbox(label="Negative prompt", lines=3, value="disfigured, extra digit, fewer digits, cropped, worst quality, low quality")
second_prompt_helper = gr.Button(value="Prompt Helper", variant="primary")
result_button = gr.Button(value="Paint It", variant="primary")
with gr.Row():
gr.Examples(examples=[["./examples/sketch.png",
"solo, open mouth, white background, standing, tail, full body,bmonochrome, greyscale, from side, no humans, animal, dog, animal focus, realistic, walk on the street, add city on the backstage, city street",
"solo, open mouth, simple background, grey background, standing, full body, monochrome, greyscale, from side, no humans, animal, dog, animal focus, lineart, wolf"],
["./examples/cat.png",
"solo, simple background, animal ears, monochrome, greyscale, no humans, cat, white background",
"solo, looking at viewer, simple background, white background, monochrome, greyscale, no humans, animal, cat, slit pupils, animal focus, lineart, whiskers"]],
inputs=[sketch, first_prompt, second_prompt],
label='Examples. Be concrete as much as possible.')
sketch.apply(fn=get_img_from_sketchpad, inputs=sketch, outputs=ser_image, show_progress="full")
improve_sketch.click(fn=controller.get_first_result,
inputs=[ser_image, first_prompt, first_negative_prompt], #[sketch, first_prompt, first_negative_prompt],
outputs=improved_sketch_view)
result_button.click(fn=controller.get_second_result,
inputs=[improved_sketch_view, second_prompt, second_negative_prompt],
outputs=result)
firts_prompt_helper.click(fn=controller.get_help_w_prompt,
inputs=[ser_image], #[sketch],
outputs=first_prompt)
second_prompt_helper.click(fn=controller.get_help_w_prompt,
inputs=[improved_sketch_view],
outputs=second_prompt)
ui.queue().launch(debug=True) |