Spaces:
Sleeping
Sleeping
Commit
·
3aff4ae
1
Parent(s):
34db193
css
Browse files
app.py
CHANGED
@@ -171,22 +171,15 @@ def save_image(img):
|
|
171 |
img.save(unique_name)
|
172 |
return unique_name
|
173 |
|
174 |
-
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
175 |
-
if randomize_seed:
|
176 |
-
seed = random.randint(0, MAX_SEED)
|
177 |
-
return seed
|
178 |
-
|
179 |
@spaces.GPU(enable_queue=True)
|
180 |
def generate(
|
181 |
prompt: str,
|
182 |
negative_prompt: str = "",
|
183 |
use_negative_prompt: bool = False,
|
184 |
style: str = DEFAULT_STYLE_NAME,
|
185 |
-
seed: int = 0,
|
186 |
width: int = 1024,
|
187 |
height: int = 1024,
|
188 |
guidance_scale: float = 3,
|
189 |
-
randomize_seed: bool = False,
|
190 |
use_resolution_binning: bool = True,
|
191 |
progress=gr.Progress(track_tqdm=True),
|
192 |
):
|
@@ -194,8 +187,7 @@ def generate(
|
|
194 |
raise ValueError("Prompt contains restricted words.")
|
195 |
|
196 |
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
197 |
-
|
198 |
-
generator = torch.Generator().manual_seed(seed)
|
199 |
|
200 |
if not use_negative_prompt:
|
201 |
negative_prompt = "" # type: ignore
|
@@ -217,7 +209,7 @@ def generate(
|
|
217 |
images = pipe(**options).images + pipe2(**options).images
|
218 |
|
219 |
image_paths = [save_image(img) for img in images]
|
220 |
-
return image_paths
|
221 |
|
222 |
examples = [
|
223 |
"A grand Dungeons & Dragons quest scene: A heroic party of adventurers standing at the entrance of a towering, ancient stone castle covered in vines, under a sky lit by the fading orange hues of a setting sun. The characters include a fierce elven warrior in ornate armor, a wise wizard with a glowing staff, a stealthy halfling rogue with a bow, and a mighty dwarf cleric with a shining warhammer. In the background, a dark forest looms, and mist begins to rise from the ground. The ground around the castle is scattered with enchanted symbols and ancient runes. The atmosphere is tense and filled with magic, adventure, and mystery."
|
@@ -334,15 +326,6 @@ with gr.Blocks(css=css) as demo:
|
|
334 |
step=1,
|
335 |
value=2,
|
336 |
)
|
337 |
-
seed = gr.Slider(
|
338 |
-
label="🎲 Random Seed",
|
339 |
-
minimum=0,
|
340 |
-
maximum=10000,
|
341 |
-
step=1,
|
342 |
-
value=42,
|
343 |
-
visible=True
|
344 |
-
)
|
345 |
-
randomize_seed = gr.Checkbox(label="🌟 Randomize Seed", value=True)
|
346 |
with gr.Row(visible=True):
|
347 |
width = gr.Slider(
|
348 |
label="Width (px)",
|
@@ -376,7 +359,7 @@ with gr.Blocks(css=css) as demo:
|
|
376 |
gr.Examples(
|
377 |
examples=examples,
|
378 |
inputs=prompt,
|
379 |
-
outputs=
|
380 |
fn=generate,
|
381 |
cache_examples=CACHE_EXAMPLES,
|
382 |
)
|
@@ -400,15 +383,13 @@ with gr.Blocks(css=css) as demo:
|
|
400 |
negative_prompt,
|
401 |
use_negative_prompt,
|
402 |
style_selection,
|
403 |
-
seed,
|
404 |
width,
|
405 |
height,
|
406 |
guidance_scale,
|
407 |
-
randomize_seed,
|
408 |
],
|
409 |
-
outputs=
|
410 |
api_name="run",
|
411 |
)
|
412 |
|
413 |
if __name__ == "__main__":
|
414 |
-
demo.queue(max_size=20).launch()
|
|
|
171 |
img.save(unique_name)
|
172 |
return unique_name
|
173 |
|
|
|
|
|
|
|
|
|
|
|
174 |
@spaces.GPU(enable_queue=True)
|
175 |
def generate(
|
176 |
prompt: str,
|
177 |
negative_prompt: str = "",
|
178 |
use_negative_prompt: bool = False,
|
179 |
style: str = DEFAULT_STYLE_NAME,
|
|
|
180 |
width: int = 1024,
|
181 |
height: int = 1024,
|
182 |
guidance_scale: float = 3,
|
|
|
183 |
use_resolution_binning: bool = True,
|
184 |
progress=gr.Progress(track_tqdm=True),
|
185 |
):
|
|
|
187 |
raise ValueError("Prompt contains restricted words.")
|
188 |
|
189 |
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
190 |
+
generator = torch.Generator().manual_seed(42) # Fixed seed for reproducibility
|
|
|
191 |
|
192 |
if not use_negative_prompt:
|
193 |
negative_prompt = "" # type: ignore
|
|
|
209 |
images = pipe(**options).images + pipe2(**options).images
|
210 |
|
211 |
image_paths = [save_image(img) for img in images]
|
212 |
+
return image_paths
|
213 |
|
214 |
examples = [
|
215 |
"A grand Dungeons & Dragons quest scene: A heroic party of adventurers standing at the entrance of a towering, ancient stone castle covered in vines, under a sky lit by the fading orange hues of a setting sun. The characters include a fierce elven warrior in ornate armor, a wise wizard with a glowing staff, a stealthy halfling rogue with a bow, and a mighty dwarf cleric with a shining warhammer. In the background, a dark forest looms, and mist begins to rise from the ground. The ground around the castle is scattered with enchanted symbols and ancient runes. The atmosphere is tense and filled with magic, adventure, and mystery."
|
|
|
326 |
step=1,
|
327 |
value=2,
|
328 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
with gr.Row(visible=True):
|
330 |
width = gr.Slider(
|
331 |
label="Width (px)",
|
|
|
359 |
gr.Examples(
|
360 |
examples=examples,
|
361 |
inputs=prompt,
|
362 |
+
outputs=result,
|
363 |
fn=generate,
|
364 |
cache_examples=CACHE_EXAMPLES,
|
365 |
)
|
|
|
383 |
negative_prompt,
|
384 |
use_negative_prompt,
|
385 |
style_selection,
|
|
|
386 |
width,
|
387 |
height,
|
388 |
guidance_scale,
|
|
|
389 |
],
|
390 |
+
outputs=result,
|
391 |
api_name="run",
|
392 |
)
|
393 |
|
394 |
if __name__ == "__main__":
|
395 |
+
demo.queue(max_size=20).launch()
|