update app.py for exhibition
Browse files
app.py
CHANGED
@@ -1,31 +1,25 @@
|
|
1 |
PATH = 'harpomaxx/deeplili' #stable diffusion 1.5
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
6 |
from tqdm.auto import tqdm
|
7 |
import random
|
8 |
import gradio as gr
|
9 |
-
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
guidance_scale = 8.5 # Scale for classifier-free guidance
|
14 |
-
|
15 |
-
|
16 |
-
pipe = StableDiffusionPipeline.from_pretrained(PATH,local_files_only=False ).to("cpu")
|
17 |
-
guidance_scale = 8.5
|
18 |
|
19 |
def generate_images(prompt, guidance_scale, n_samples, num_inference_steps):
|
20 |
seeds = [random.randint(1, 10000) for _ in range(n_samples)]
|
21 |
-
images = []
|
22 |
for seed in tqdm(seeds):
|
23 |
torch.manual_seed(seed)
|
24 |
-
image = pipe(prompt, num_inference_steps=num_inference_steps,guidance_scale=guidance_scale).images[0]
|
25 |
images.append(image)
|
26 |
return images
|
27 |
|
28 |
-
def gr_generate_images(prompt: str, num_images
|
29 |
prompt = prompt + "sks style"
|
30 |
images = generate_images(prompt, guidance_scale, num_images, num_inference)
|
31 |
return images
|
@@ -35,36 +29,37 @@ with gr.Blocks() as demo:
|
|
35 |
[
|
36 |
'A black and white cute character on top of a hill',
|
37 |
1,
|
38 |
-
|
39 |
],
|
40 |
[
|
41 |
'Bubbles and mountains in the sky',
|
42 |
1,
|
43 |
-
|
44 |
],
|
45 |
[
|
46 |
'A tree with multiple eyes and a small flower muted colors',
|
47 |
1,
|
48 |
-
|
49 |
],
|
50 |
[
|
51 |
"3d character on top of a hill",
|
52 |
1,
|
53 |
-
|
54 |
],
|
55 |
[
|
56 |
"a poster of a large forest with black and white characters",
|
57 |
1,
|
58 |
-
|
59 |
],
|
60 |
]
|
61 |
gr.Markdown(
|
62 |
"""
|
63 |
<img src="https://github.com/harpomaxx/DeepLili/raw/main/images/lilifiallo/660.png" width="150" height="150">
|
64 |
|
65 |
-
# #DeepLili v0.
|
66 |
|
67 |
## Enter your prompt and generate a work of art in the style of Lili's Toy Art paintings.
|
|
|
68 |
"""
|
69 |
)
|
70 |
|
@@ -78,39 +73,75 @@ with gr.Blocks() as demo:
|
|
78 |
).style(
|
79 |
container=False,
|
80 |
)
|
81 |
-
|
82 |
with gr.Row(variant="compact"):
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
btn = gr.Button("Generate image").style(full_width=False)
|
100 |
-
|
101 |
gallery = gr.Gallery(
|
102 |
label="Generated images", show_label=False, elem_id="gallery"
|
103 |
-
).style(columns=[
|
|
|
|
|
|
|
|
|
104 |
|
105 |
-
btn.click(gr_generate_images, [text
|
106 |
gr.Examples(examples, inputs=[text])
|
107 |
gr.HTML(
|
108 |
"""
|
109 |
<h6><a href="https://harpomaxx.github.io/"> harpomaxx </a></h6>
|
110 |
-
<h6> This space is running on CPU. So it gonna be very slow!!!! </h6>
|
111 |
"""
|
112 |
)
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
PATH = 'harpomaxx/deeplili' #stable diffusion 1.5
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
+
import torch.distributed as dist
|
5 |
+
import torch.multiprocessing as mp
|
6 |
+
import argparse
|
7 |
+
|
8 |
+
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
|
9 |
from tqdm.auto import tqdm
|
10 |
import random
|
11 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def generate_images(prompt, guidance_scale, n_samples, num_inference_steps):
|
14 |
seeds = [random.randint(1, 10000) for _ in range(n_samples)]
|
15 |
+
images = []
|
16 |
for seed in tqdm(seeds):
|
17 |
torch.manual_seed(seed)
|
18 |
+
image = pipe(prompt, num_inference_steps=num_inference_steps,guidance_scale=guidance_scale).images[0]
|
19 |
images.append(image)
|
20 |
return images
|
21 |
|
22 |
+
def gr_generate_images(prompt: str, num_images = 1, num_inference = 20, guidance_scale = 8 ):
|
23 |
prompt = prompt + "sks style"
|
24 |
images = generate_images(prompt, guidance_scale, num_images, num_inference)
|
25 |
return images
|
|
|
29 |
[
|
30 |
'A black and white cute character on top of a hill',
|
31 |
1,
|
32 |
+
30
|
33 |
],
|
34 |
[
|
35 |
'Bubbles and mountains in the sky',
|
36 |
1,
|
37 |
+
20
|
38 |
],
|
39 |
[
|
40 |
'A tree with multiple eyes and a small flower muted colors',
|
41 |
1,
|
42 |
+
20
|
43 |
],
|
44 |
[
|
45 |
"3d character on top of a hill",
|
46 |
1,
|
47 |
+
20
|
48 |
],
|
49 |
[
|
50 |
"a poster of a large forest with black and white characters",
|
51 |
1,
|
52 |
+
20
|
53 |
],
|
54 |
]
|
55 |
gr.Markdown(
|
56 |
"""
|
57 |
<img src="https://github.com/harpomaxx/DeepLili/raw/main/images/lilifiallo/660.png" width="150" height="150">
|
58 |
|
59 |
+
# #DeepLili v0.5b
|
60 |
|
61 |
## Enter your prompt and generate a work of art in the style of Lili's Toy Art paintings.
|
62 |
+
## (English, Spanish)
|
63 |
"""
|
64 |
)
|
65 |
|
|
|
73 |
).style(
|
74 |
container=False,
|
75 |
)
|
76 |
+
|
77 |
with gr.Row(variant="compact"):
|
78 |
+
# num_images_slider = gr.Slider(
|
79 |
+
# minimum=1,
|
80 |
+
# maximum=10,
|
81 |
+
# step=1,
|
82 |
+
# value=1,
|
83 |
+
# label="Number of Images",
|
84 |
+
# )
|
85 |
+
|
86 |
+
# num_inference_steps_slider = gr.Slider(
|
87 |
+
# minimum=1,
|
88 |
+
# maximum=25,
|
89 |
+
# step=1,
|
90 |
+
# value=20,
|
91 |
+
# label="Inference Steps",
|
92 |
+
# )
|
93 |
+
|
94 |
+
# guidance_slider = gr.Slider(
|
95 |
+
# minimum=1,
|
96 |
+
# maximum=14,
|
97 |
+
# step=1,
|
98 |
+
# value=8,
|
99 |
+
# label="Guidance Scale",
|
100 |
+
# )
|
101 |
+
|
102 |
+
|
103 |
|
104 |
btn = gr.Button("Generate image").style(full_width=False)
|
105 |
+
|
106 |
gallery = gr.Gallery(
|
107 |
label="Generated images", show_label=False, elem_id="gallery"
|
108 |
+
).style(columns=[1], rows=[1], object_fit="contain", height="512px", width="512px")
|
109 |
+
|
110 |
+
num_images_slider = 1
|
111 |
+
num_inference_steps_slider = 20
|
112 |
+
guidance_slider = 8
|
113 |
|
114 |
+
btn.click(gr_generate_images, [text], gallery)
|
115 |
gr.Examples(examples, inputs=[text])
|
116 |
gr.HTML(
|
117 |
"""
|
118 |
<h6><a href="https://harpomaxx.github.io/"> harpomaxx </a></h6>
|
|
|
119 |
"""
|
120 |
)
|
121 |
|
122 |
if __name__ == "__main__":
|
123 |
+
|
124 |
+
parser = argparse.ArgumentParser()
|
125 |
+
|
126 |
+
parser.add_argument(
|
127 |
+
"--ip",
|
128 |
+
default="0.0.0.0",
|
129 |
+
help="The IP address to of the server"
|
130 |
+
)
|
131 |
+
parser.add_argument(
|
132 |
+
"--port",
|
133 |
+
type=int,
|
134 |
+
default=7860,
|
135 |
+
help="The port used"
|
136 |
+
)
|
137 |
+
parser.add_argument(
|
138 |
+
"--gpuid",
|
139 |
+
default="0",
|
140 |
+
help="The gpu id"
|
141 |
+
)
|
142 |
+
|
143 |
+
args = parser.parse_args()
|
144 |
+
pipe = StableDiffusionPipeline.from_single_file(PATH,torch_dtype=torch.float16).to(f"cuda:{args.gpuid}")
|
145 |
+
demo.queue(concurrency_count=2,
|
146 |
+
).launch(server_name = args.ip, server_port = args.port)
|
147 |
+
~
|