Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,7 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
-
|
3 |
from __future__ import annotations
|
4 |
-
|
5 |
-
import os
|
6 |
-
import random
|
7 |
-
import glob
|
8 |
from datetime import datetime
|
9 |
-
|
10 |
import gradio as gr
|
11 |
import numpy as np
|
12 |
import PIL.Image
|
@@ -16,19 +11,12 @@ from diffusers import AutoencoderKL, DiffusionPipeline
|
|
16 |
|
17 |
DESCRIPTION = """
|
18 |
# OpenDalle 1.1 with Gallery
|
19 |
-
|
20 |
**Demo by [mrfakename](https://mrfake.name/) - [Twitter](https://twitter.com/realmrfakename) - [GitHub](https://github.com/fakerybakery/) - [Hugging Face](https://huggingface.co/mrfakename)**
|
21 |
-
|
22 |
This is a demo of <a href="https://huggingface.co/dataautogpt3/OpenDalleV1.1">OpenDalle V1.1</a> by @dataautogpt3.
|
23 |
-
|
24 |
It's a merge of several different models and is supposed to provide excellent performance. Try it out!
|
25 |
-
|
26 |
[Not Working?](https://huggingface.co/spaces/mrfakename/OpenDalleV1.1-GPU-Demo/discussions/4)
|
27 |
-
|
28 |
**The code for this demo is based on [@hysts's SD-XL demo](https://huggingface.co/spaces/hysts/SD-XL) running on a A10G GPU.**
|
29 |
-
|
30 |
**NOTE: The model is licensed under a non-commercial license**
|
31 |
-
|
32 |
Also see [OpenDalle Original Demo](https://huggingface.co/spaces/mrfakename/OpenDalle-GPU-Demo/)
|
33 |
"""
|
34 |
if not torch.cuda.is_available():
|
@@ -44,123 +32,48 @@ ENABLE_REFINER = os.getenv("ENABLE_REFINER", "0") == "1"
|
|
44 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
45 |
if torch.cuda.is_available():
|
46 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
47 |
-
pipe = DiffusionPipeline.from_pretrained(
|
48 |
-
"dataautogpt3/OpenDalleV1.1",
|
49 |
-
vae=vae,
|
50 |
-
torch_dtype=torch.float16,
|
51 |
-
use_safetensors=True,
|
52 |
-
variant="fp16",
|
53 |
-
)
|
54 |
if ENABLE_REFINER:
|
55 |
-
refiner = DiffusionPipeline.from_pretrained(
|
56 |
-
"stabilityai/stable-diffusion-xl-refiner-1.0",
|
57 |
-
vae=vae,
|
58 |
-
torch_dtype=torch.float16,
|
59 |
-
use_safetensors=True,
|
60 |
-
variant="fp16",
|
61 |
-
)
|
62 |
-
|
63 |
if ENABLE_CPU_OFFLOAD:
|
64 |
pipe.enable_model_cpu_offload()
|
65 |
-
if ENABLE_REFINER:
|
66 |
-
refiner.enable_model_cpu_offload()
|
67 |
else:
|
68 |
pipe.to(device)
|
69 |
-
if ENABLE_REFINER:
|
70 |
-
refiner.to(device)
|
71 |
-
|
72 |
if USE_TORCH_COMPILE:
|
73 |
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
74 |
-
if ENABLE_REFINER:
|
75 |
-
refiner.unet = torch.compile(refiner.unet, mode="reduce-overhead", fullgraph=True)
|
76 |
|
77 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
78 |
-
if randomize_seed
|
79 |
-
seed = random.randint(0, MAX_SEED)
|
80 |
-
return seed
|
81 |
|
82 |
def save_image(image: PIL.Image.Image, prompt: str) -> str:
|
83 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
84 |
-
|
|
|
85 |
image.save(filename)
|
86 |
return filename
|
87 |
|
88 |
def get_image_gallery():
|
89 |
-
|
90 |
-
image_files.sort(key=os.path.getmtime, reverse=True)
|
91 |
-
return image_files
|
92 |
|
93 |
@spaces.GPU(enable_queue=True)
|
94 |
-
def generate(
|
95 |
-
prompt: str,
|
96 |
-
negative_prompt: str = "",
|
97 |
-
prompt_2: str = "",
|
98 |
-
negative_prompt_2: str = "",
|
99 |
-
use_negative_prompt: bool = False,
|
100 |
-
use_prompt_2: bool = False,
|
101 |
-
use_negative_prompt_2: bool = False,
|
102 |
-
seed: int = 0,
|
103 |
-
width: int = 1024,
|
104 |
-
height: int = 1024,
|
105 |
-
guidance_scale_base: float = 5.0,
|
106 |
-
guidance_scale_refiner: float = 5.0,
|
107 |
-
num_inference_steps_base: int = 25,
|
108 |
-
num_inference_steps_refiner: int = 25,
|
109 |
-
apply_refiner: bool = False,
|
110 |
-
progress=gr.Progress(track_tqdm=True),
|
111 |
-
) -> PIL.Image.Image:
|
112 |
print(f"** Generating image for: \"{prompt}\" **")
|
113 |
generator = torch.Generator().manual_seed(seed)
|
114 |
-
|
115 |
-
if not
|
116 |
-
|
117 |
-
if not use_prompt_2:
|
118 |
-
prompt_2 = None # type: ignore
|
119 |
-
if not use_negative_prompt_2:
|
120 |
-
negative_prompt_2 = None # type: ignore
|
121 |
-
|
122 |
if not apply_refiner:
|
123 |
-
image = pipe(
|
124 |
-
prompt=prompt,
|
125 |
-
negative_prompt=negative_prompt,
|
126 |
-
prompt_2=prompt_2,
|
127 |
-
negative_prompt_2=negative_prompt_2,
|
128 |
-
width=width,
|
129 |
-
height=height,
|
130 |
-
guidance_scale=guidance_scale_base,
|
131 |
-
num_inference_steps=num_inference_steps_base,
|
132 |
-
generator=generator,
|
133 |
-
output_type="pil",
|
134 |
-
).images[0]
|
135 |
else:
|
136 |
-
latents = pipe(
|
137 |
-
|
138 |
-
negative_prompt=negative_prompt,
|
139 |
-
prompt_2=prompt_2,
|
140 |
-
negative_prompt_2=negative_prompt_2,
|
141 |
-
width=width,
|
142 |
-
height=height,
|
143 |
-
guidance_scale=guidance_scale_base,
|
144 |
-
num_inference_steps=num_inference_steps_base,
|
145 |
-
generator=generator,
|
146 |
-
output_type="latent",
|
147 |
-
).images
|
148 |
-
image = refiner(
|
149 |
-
prompt=prompt,
|
150 |
-
negative_prompt=negative_prompt,
|
151 |
-
prompt_2=prompt_2,
|
152 |
-
negative_prompt_2=negative_prompt_2,
|
153 |
-
guidance_scale=guidance_scale_refiner,
|
154 |
-
num_inference_steps=num_inference_steps_refiner,
|
155 |
-
image=latents,
|
156 |
-
generator=generator,
|
157 |
-
).images[0]
|
158 |
-
|
159 |
save_image(image, prompt)
|
160 |
return image, get_image_gallery()
|
161 |
|
162 |
-
examples = [
|
163 |
-
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} painting of a majestic lighthouse on a rocky coast. Use bold brushstrokes and a vibrant color palette to capture the interplay of light and shadow as the lighthouse beam cuts through a stormy night sky.",
|
164 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} still life featuring a pair of vintage eyeglasses. Focus on the intricate details of the frames and lenses, using a warm color scheme to evoke a sense of nostalgia and wisdom.",
|
165 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} depiction of a rustic wooden stool in a sunlit artist's studio. Emphasize the texture of the wood and the interplay of light and shadow, using a mix of earthy tones and highlights.",
|
166 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} scene viewed through an ornate window frame. Contrast the intricate details of the window with a dreamy, soft-focus landscape beyond, using a palette that transitions from cool interior tones to warm exterior hues.",
|
@@ -169,27 +82,14 @@ examples = [
|
|
169 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} interpretation of heaven. Create an ethereal atmosphere with soft, billowing clouds and radiant light, using a palette of celestial blues, golds, and whites.",
|
170 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} portrayal of an ancient, mystical gate. Combine architectural details with elements of fantasy, using a rich, jewel-toned palette to create an air of mystery and magic.",
|
171 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} portrait of a curious cat. Focus on capturing the feline's expressive eyes and sleek form, using a mix of bold and subtle colors to bring out the cat's personality.",
|
172 |
-
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} abstract representation of toes in sand. Use textured brushstrokes to convey the feeling of warm sand, with a palette inspired by a sun-drenched beach."
|
173 |
-
]
|
174 |
|
175 |
-
theme = gr.themes.Base(
|
176 |
-
font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
|
177 |
-
)
|
178 |
with gr.Blocks(css="footer{display:none !important}", theme=theme) as demo:
|
179 |
gr.Markdown(DESCRIPTION)
|
180 |
-
gr.DuplicateButton(
|
181 |
-
value="Duplicate Space for private use",
|
182 |
-
elem_id="duplicate-button",
|
183 |
-
visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
|
184 |
-
)
|
185 |
with gr.Group():
|
186 |
-
prompt = gr.Text(
|
187 |
-
label="Prompt",
|
188 |
-
show_label=False,
|
189 |
-
max_lines=1,
|
190 |
-
container=False,
|
191 |
-
placeholder="Enter your prompt",
|
192 |
-
)
|
193 |
run_button = gr.Button("Generate")
|
194 |
result = gr.Image(label="Result", show_label=False)
|
195 |
gallery = gr.Gallery(label="Generated Images", show_label=True, columns=4, height="auto")
|
@@ -198,152 +98,34 @@ with gr.Blocks(css="footer{display:none !important}", theme=theme) as demo:
|
|
198 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False)
|
199 |
use_prompt_2 = gr.Checkbox(label="Use prompt 2", value=False)
|
200 |
use_negative_prompt_2 = gr.Checkbox(label="Use negative prompt 2", value=False)
|
201 |
-
negative_prompt = gr.Text(
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
visible=False,
|
206 |
-
)
|
207 |
-
prompt_2 = gr.Text(
|
208 |
-
label="Prompt 2",
|
209 |
-
max_lines=1,
|
210 |
-
placeholder="Enter your prompt",
|
211 |
-
visible=False,
|
212 |
-
)
|
213 |
-
negative_prompt_2 = gr.Text(
|
214 |
-
label="Negative prompt 2",
|
215 |
-
max_lines=1,
|
216 |
-
placeholder="Enter a negative prompt",
|
217 |
-
visible=False,
|
218 |
-
)
|
219 |
-
|
220 |
-
seed = gr.Slider(
|
221 |
-
label="Seed",
|
222 |
-
minimum=0,
|
223 |
-
maximum=MAX_SEED,
|
224 |
-
step=1,
|
225 |
-
value=0,
|
226 |
-
)
|
227 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
228 |
with gr.Row():
|
229 |
-
width = gr.Slider(
|
230 |
-
|
231 |
-
minimum=256,
|
232 |
-
maximum=MAX_IMAGE_SIZE,
|
233 |
-
step=32,
|
234 |
-
value=1024,
|
235 |
-
)
|
236 |
-
height = gr.Slider(
|
237 |
-
label="Height",
|
238 |
-
minimum=256,
|
239 |
-
maximum=MAX_IMAGE_SIZE,
|
240 |
-
step=32,
|
241 |
-
value=1024,
|
242 |
-
)
|
243 |
apply_refiner = gr.Checkbox(label="Apply refiner", value=False, visible=ENABLE_REFINER)
|
244 |
with gr.Row():
|
245 |
-
guidance_scale_base = gr.Slider(
|
246 |
-
|
247 |
-
minimum=1,
|
248 |
-
maximum=20,
|
249 |
-
step=0.1,
|
250 |
-
value=5.0,
|
251 |
-
)
|
252 |
-
num_inference_steps_base = gr.Slider(
|
253 |
-
label="Number of inference steps for base",
|
254 |
-
minimum=10,
|
255 |
-
maximum=100,
|
256 |
-
step=1,
|
257 |
-
value=25,
|
258 |
-
)
|
259 |
with gr.Row(visible=False) as refiner_params:
|
260 |
-
guidance_scale_refiner = gr.Slider(
|
261 |
-
|
262 |
-
minimum=1,
|
263 |
-
maximum=20,
|
264 |
-
step=0.1,
|
265 |
-
value=5.0,
|
266 |
-
)
|
267 |
-
num_inference_steps_refiner = gr.Slider(
|
268 |
-
label="Number of inference steps for refiner",
|
269 |
-
minimum=10,
|
270 |
-
maximum=100,
|
271 |
-
step=1,
|
272 |
-
value=25,
|
273 |
-
)
|
274 |
|
275 |
-
gr.Examples(
|
276 |
-
examples=examples,
|
277 |
-
inputs=prompt,
|
278 |
-
outputs=[result, gallery],
|
279 |
-
fn=generate,
|
280 |
-
cache_examples=CACHE_EXAMPLES,
|
281 |
-
)
|
282 |
|
283 |
-
use_negative_prompt.change(
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
queue=False,
|
288 |
-
api_name=False,
|
289 |
-
)
|
290 |
-
use_prompt_2.change(
|
291 |
-
fn=lambda x: gr.update(visible=x),
|
292 |
-
inputs=use_prompt_2,
|
293 |
-
outputs=prompt_2,
|
294 |
-
queue=False,
|
295 |
-
api_name=False,
|
296 |
-
)
|
297 |
-
use_negative_prompt_2.change(
|
298 |
-
fn=lambda x: gr.update(visible=x),
|
299 |
-
inputs=use_negative_prompt_2,
|
300 |
-
outputs=negative_prompt_2,
|
301 |
-
queue=False,
|
302 |
-
api_name=False,
|
303 |
-
)
|
304 |
-
apply_refiner.change(
|
305 |
-
fn=lambda x: gr.update(visible=x),
|
306 |
-
inputs=apply_refiner,
|
307 |
-
outputs=refiner_params,
|
308 |
-
queue=False,
|
309 |
-
api_name=False,
|
310 |
-
)
|
311 |
|
312 |
-
gr.on(
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
negative_prompt_2.submit,
|
318 |
-
run_button.click,
|
319 |
-
],
|
320 |
-
fn=randomize_seed_fn,
|
321 |
-
inputs=[seed, randomize_seed],
|
322 |
-
outputs=seed,
|
323 |
-
queue=False,
|
324 |
-
api_name=False,
|
325 |
-
).then(
|
326 |
-
fn=generate,
|
327 |
-
inputs=[
|
328 |
-
prompt,
|
329 |
-
negative_prompt,
|
330 |
-
prompt_2,
|
331 |
-
negative_prompt_2,
|
332 |
-
use_negative_prompt,
|
333 |
-
use_prompt_2,
|
334 |
-
use_negative_prompt_2,
|
335 |
-
seed,
|
336 |
-
width,
|
337 |
-
height,
|
338 |
-
guidance_scale_base,
|
339 |
-
guidance_scale_refiner,
|
340 |
-
num_inference_steps_base,
|
341 |
-
num_inference_steps_refiner,
|
342 |
-
apply_refiner,
|
343 |
-
],
|
344 |
-
outputs=[result, gallery],
|
345 |
-
api_name="run",
|
346 |
-
)
|
347 |
|
348 |
demo.load(fn=get_image_gallery, outputs=gallery)
|
349 |
|
|
|
1 |
#!/usr/bin/env python
|
|
|
2 |
from __future__ import annotations
|
3 |
+
import os, random, glob, re
|
|
|
|
|
|
|
4 |
from datetime import datetime
|
|
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
import PIL.Image
|
|
|
11 |
|
12 |
DESCRIPTION = """
|
13 |
# OpenDalle 1.1 with Gallery
|
|
|
14 |
**Demo by [mrfakename](https://mrfake.name/) - [Twitter](https://twitter.com/realmrfakename) - [GitHub](https://github.com/fakerybakery/) - [Hugging Face](https://huggingface.co/mrfakename)**
|
|
|
15 |
This is a demo of <a href="https://huggingface.co/dataautogpt3/OpenDalleV1.1">OpenDalle V1.1</a> by @dataautogpt3.
|
|
|
16 |
It's a merge of several different models and is supposed to provide excellent performance. Try it out!
|
|
|
17 |
[Not Working?](https://huggingface.co/spaces/mrfakename/OpenDalleV1.1-GPU-Demo/discussions/4)
|
|
|
18 |
**The code for this demo is based on [@hysts's SD-XL demo](https://huggingface.co/spaces/hysts/SD-XL) running on a A10G GPU.**
|
|
|
19 |
**NOTE: The model is licensed under a non-commercial license**
|
|
|
20 |
Also see [OpenDalle Original Demo](https://huggingface.co/spaces/mrfakename/OpenDalle-GPU-Demo/)
|
21 |
"""
|
22 |
if not torch.cuda.is_available():
|
|
|
32 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
33 |
if torch.cuda.is_available():
|
34 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
35 |
+
pipe = DiffusionPipeline.from_pretrained("dataautogpt3/OpenDalleV1.1", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
if ENABLE_REFINER:
|
37 |
+
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
if ENABLE_CPU_OFFLOAD:
|
39 |
pipe.enable_model_cpu_offload()
|
40 |
+
if ENABLE_REFINER: refiner.enable_model_cpu_offload()
|
|
|
41 |
else:
|
42 |
pipe.to(device)
|
43 |
+
if ENABLE_REFINER: refiner.to(device)
|
|
|
|
|
44 |
if USE_TORCH_COMPILE:
|
45 |
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
46 |
+
if ENABLE_REFINER: refiner.unet = torch.compile(refiner.unet, mode="reduce-overhead", fullgraph=True)
|
|
|
47 |
|
48 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
49 |
+
return random.randint(0, MAX_SEED) if randomize_seed else seed
|
|
|
|
|
50 |
|
51 |
def save_image(image: PIL.Image.Image, prompt: str) -> str:
|
52 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
53 |
+
clean_prompt = re.sub(r'[^\w\-_\. ]', '_', prompt)[:50]
|
54 |
+
filename = f"{timestamp}_{clean_prompt}.png"
|
55 |
image.save(filename)
|
56 |
return filename
|
57 |
|
58 |
def get_image_gallery():
|
59 |
+
return sorted(glob.glob("*.png"), key=os.path.getmtime, reverse=True)
|
|
|
|
|
60 |
|
61 |
@spaces.GPU(enable_queue=True)
|
62 |
+
def generate(prompt: str, negative_prompt: str = "", prompt_2: str = "", negative_prompt_2: str = "", use_negative_prompt: bool = False, use_prompt_2: bool = False, use_negative_prompt_2: bool = False, seed: int = 0, width: int = 1024, height: int = 1024, guidance_scale_base: float = 5.0, guidance_scale_refiner: float = 5.0, num_inference_steps_base: int = 25, num_inference_steps_refiner: int = 25, apply_refiner: bool = False, progress=gr.Progress(track_tqdm=True)) -> PIL.Image.Image:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
print(f"** Generating image for: \"{prompt}\" **")
|
64 |
generator = torch.Generator().manual_seed(seed)
|
65 |
+
if not use_negative_prompt: negative_prompt = None
|
66 |
+
if not use_prompt_2: prompt_2 = None
|
67 |
+
if not use_negative_prompt_2: negative_prompt_2 = None
|
|
|
|
|
|
|
|
|
|
|
68 |
if not apply_refiner:
|
69 |
+
image = pipe(prompt=prompt, negative_prompt=negative_prompt, prompt_2=prompt_2, negative_prompt_2=negative_prompt_2, width=width, height=height, guidance_scale=guidance_scale_base, num_inference_steps=num_inference_steps_base, generator=generator, output_type="pil").images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
else:
|
71 |
+
latents = pipe(prompt=prompt, negative_prompt=negative_prompt, prompt_2=prompt_2, negative_prompt_2=negative_prompt_2, width=width, height=height, guidance_scale=guidance_scale_base, num_inference_steps=num_inference_steps_base, generator=generator, output_type="latent").images
|
72 |
+
image = refiner(prompt=prompt, negative_prompt=negative_prompt, prompt_2=prompt_2, negative_prompt_2=negative_prompt_2, guidance_scale=guidance_scale_refiner, num_inference_steps=num_inference_steps_refiner, image=latents, generator=generator).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
save_image(image, prompt)
|
74 |
return image, get_image_gallery()
|
75 |
|
76 |
+
examples = [f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} painting of a majestic lighthouse on a rocky coast. Use bold brushstrokes and a vibrant color palette to capture the interplay of light and shadow as the lighthouse beam cuts through a stormy night sky.",
|
|
|
77 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} still life featuring a pair of vintage eyeglasses. Focus on the intricate details of the frames and lenses, using a warm color scheme to evoke a sense of nostalgia and wisdom.",
|
78 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} depiction of a rustic wooden stool in a sunlit artist's studio. Emphasize the texture of the wood and the interplay of light and shadow, using a mix of earthy tones and highlights.",
|
79 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} scene viewed through an ornate window frame. Contrast the intricate details of the window with a dreamy, soft-focus landscape beyond, using a palette that transitions from cool interior tones to warm exterior hues.",
|
|
|
82 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} interpretation of heaven. Create an ethereal atmosphere with soft, billowing clouds and radiant light, using a palette of celestial blues, golds, and whites.",
|
83 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} portrayal of an ancient, mystical gate. Combine architectural details with elements of fantasy, using a rich, jewel-toned palette to create an air of mystery and magic.",
|
84 |
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} portrait of a curious cat. Focus on capturing the feline's expressive eyes and sleek form, using a mix of bold and subtle colors to bring out the cat's personality.",
|
85 |
+
f"{random.choice(['Impressionist', 'Cubist', 'Surrealist', 'Abstract Expressionist', 'Pop Art', 'Minimalist', 'Baroque', 'Art Nouveau', 'Pointillist', 'Fauvism'])} abstract representation of toes in sand. Use textured brushstrokes to convey the feeling of warm sand, with a palette inspired by a sun-drenched beach."]
|
|
|
86 |
|
87 |
+
theme = gr.themes.Base(font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'])
|
|
|
|
|
88 |
with gr.Blocks(css="footer{display:none !important}", theme=theme) as demo:
|
89 |
gr.Markdown(DESCRIPTION)
|
90 |
+
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button", visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1")
|
|
|
|
|
|
|
|
|
91 |
with gr.Group():
|
92 |
+
prompt = gr.Text(label="Prompt", show_label=False, max_lines=1, container=False, placeholder="Enter your prompt")
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
run_button = gr.Button("Generate")
|
94 |
result = gr.Image(label="Result", show_label=False)
|
95 |
gallery = gr.Gallery(label="Generated Images", show_label=True, columns=4, height="auto")
|
|
|
98 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False)
|
99 |
use_prompt_2 = gr.Checkbox(label="Use prompt 2", value=False)
|
100 |
use_negative_prompt_2 = gr.Checkbox(label="Use negative prompt 2", value=False)
|
101 |
+
negative_prompt = gr.Text(label="Negative prompt", max_lines=1, placeholder="Enter a negative prompt", visible=False)
|
102 |
+
prompt_2 = gr.Text(label="Prompt 2", max_lines=1, placeholder="Enter your prompt", visible=False)
|
103 |
+
negative_prompt_2 = gr.Text(label="Negative prompt 2", max_lines=1, placeholder="Enter a negative prompt", visible=False)
|
104 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
106 |
with gr.Row():
|
107 |
+
width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
108 |
+
height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
apply_refiner = gr.Checkbox(label="Apply refiner", value=False, visible=ENABLE_REFINER)
|
110 |
with gr.Row():
|
111 |
+
guidance_scale_base = gr.Slider(label="Guidance scale for base", minimum=1, maximum=20, step=0.1, value=5.0)
|
112 |
+
num_inference_steps_base = gr.Slider(label="Number of inference steps for base", minimum=10, maximum=100, step=1, value=25)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
with gr.Row(visible=False) as refiner_params:
|
114 |
+
guidance_scale_refiner = gr.Slider(label="Guidance scale for refiner", minimum=1, maximum=20, step=0.1, value=5.0)
|
115 |
+
num_inference_steps_refiner = gr.Slider(label="Number of inference steps for refiner", minimum=10, maximum=100, step=1, value=25)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
gr.Examples(examples=examples, inputs=prompt, outputs=[result, gallery], fn=generate, cache_examples=CACHE_EXAMPLES)
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
+
use_negative_prompt.change(fn=lambda x: gr.update(visible=x), inputs=use_negative_prompt, outputs=negative_prompt, queue=False, api_name=False)
|
120 |
+
use_prompt_2.change(fn=lambda x: gr.update(visible=x), inputs=use_prompt_2, outputs=prompt_2, queue=False, api_name=False)
|
121 |
+
use_negative_prompt_2.change(fn=lambda x: gr.update(visible=x), inputs=use_negative_prompt_2, outputs=negative_prompt_2, queue=False, api_name=False)
|
122 |
+
apply_refiner.change(fn=lambda x: gr.update(visible=x), inputs=apply_refiner, outputs=refiner_params, queue=False, api_name=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
+
gr.on(triggers=[prompt.submit, negative_prompt.submit, prompt_2.submit, negative_prompt_2.submit, run_button.click],
|
125 |
+
fn=randomize_seed_fn, inputs=[seed, randomize_seed], outputs=seed, queue=False, api_name=False).then(
|
126 |
+
fn=generate, inputs=[prompt, negative_prompt, prompt_2, negative_prompt_2, use_negative_prompt, use_prompt_2, use_negative_prompt_2,
|
127 |
+
seed, width, height, guidance_scale_base, guidance_scale_refiner, num_inference_steps_base, num_inference_steps_refiner, apply_refiner],
|
128 |
+
outputs=[result, gallery], api_name="run")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
demo.load(fn=get_image_gallery, outputs=gallery)
|
131 |
|