File size: 2,481 Bytes
c3b62d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import sys
from utils import load_lora_model
from bg_alpha import adjust_transparency
from lineart import get_pipe
import os
from PIL import Image
import spaces

path = os.getcwd()
output_dir = f"{path}/output"
lora_dir = f"{path}/models/lora"

load_lora_model(lora_dir)

pipe = get_pipe(lora_dir)

@spaces.GPU()
def generate(prompt, negative_prompt):
    default_pos = "((white background)), lineart, <lora:sdxl_BWLine:1.0>, monochrome, "
    default_neg = ""
    prompt = default_pos + prompt 
    negative_prompt = default_neg + negative_prompt

    width, height = 1024, 1024
    color = (255, 255, 255)
    white_bg =  Image.new("RGB", (width, height), color)

    image = pipe(
                prompt=prompt,
                negative_prompt = negative_prompt,
                image=[white_bg],
                num_inference_steps=50,
                controlnet_conditioning_scale=[0.1]
            ).images[0]
    
    return image


class webui:
    def __init__(self):
        self.demo = gr.Blocks()

    def process(self, pos_prompt, neg_prompt):
        image = generate(pos_prompt, neg_prompt)
        image = adjust_transparency(image)
        return [image]

    def launch(self, share):
        with self.demo:
            with gr.Column():
                    with gr.Tab("output"):
                        output_0 = gr.Gallery(format="png")
                    #output_file = gr.File()
            with gr.Column():
                pos_prompt = gr.Textbox(value="1girl, cute, kawaii,  medium breasts,  medium hair,  smile,  mini skirt,  best quality, very aesthetic," ,max_lines=1000, label="positive prompt")                    
                neg_prompt = gr.Textbox(value="bold line, multiple people," ,max_lines=1000, label="negative prompt")

                submit = gr.Button(value="Start")
                
                
            submit.click(
                self.process, 
                inputs=[pos_prompt, neg_prompt], #[input_image, pos_prompt, neg_prompt, alpha_th, thickness, reference_image], 
                outputs=[output_0]
            )

        self.demo.queue()
        self.demo.launch(share=share)


if __name__ == "__main__":
    ui = webui()
    if len(sys.argv) > 1:
        if sys.argv[1] == "share":
            ui.launch(share=True)
        else:
            ui.launch(share=False)
    else:
        ui.launch(share=False)