Add styles (#9)
Browse files- Add styles (55470bd513604ef5467c05d896b9f6949979d62c)
app.py
CHANGED
@@ -9,20 +9,86 @@ import requests
|
|
9 |
import time
|
10 |
from PIL import Image
|
11 |
from io import BytesIO
|
|
|
12 |
|
13 |
import user_history
|
14 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
word_list_dataset = load_dataset("google/word-list-sd", data_files="list.txt", use_auth_token=True)
|
17 |
word_list = word_list_dataset["train"]['text']
|
18 |
|
19 |
#gradio.helpers.CACHED_FOLDER="/data/cache"
|
20 |
|
21 |
-
def infer(prompt, negative="low_quality", scale=7, profile: gr.OAuthProfile | None = None):
|
22 |
for filter in word_list:
|
23 |
if re.search(rf"\b{filter}\b", prompt):
|
24 |
raise gr.Error("Please try again with a different prompt")
|
25 |
-
|
|
|
26 |
images = []
|
27 |
url = os.getenv('JAX_BACKEND_URL')
|
28 |
payload = {'prompt': prompt, 'negative_prompt': negative, 'guidance_scale': scale}
|
@@ -286,6 +352,12 @@ with block:
|
|
286 |
share_button = gr.Button("Share to community", elem_id="share-btn")
|
287 |
|
288 |
with gr.Accordion("Advanced settings", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
negative = gr.Textbox(
|
290 |
label="Enter your negative prompt",
|
291 |
show_label=False,
|
@@ -298,9 +370,9 @@ with block:
|
|
298 |
)
|
299 |
|
300 |
ex = gr.Examples(examples=examples, fn=infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_group], cache_examples=True, postprocess=False)
|
301 |
-
negative.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_group], postprocess=False)
|
302 |
-
text.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_group], postprocess=False)
|
303 |
-
btn.click(infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_group], postprocess=False)
|
304 |
|
305 |
share_button.click(
|
306 |
None,
|
|
|
9 |
import time
|
10 |
from PIL import Image
|
11 |
from io import BytesIO
|
12 |
+
from typing import Tuple
|
13 |
|
14 |
import user_history
|
15 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
16 |
|
17 |
+
|
18 |
+
style_list = [
|
19 |
+
{
|
20 |
+
"name": "(No style)",
|
21 |
+
"prompt": "{prompt}",
|
22 |
+
"negative_prompt": "",
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"name": "Cinematic",
|
26 |
+
"prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
|
27 |
+
"negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"name": "Photographic",
|
31 |
+
"prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
|
32 |
+
"negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"name": "Anime",
|
36 |
+
"prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
|
37 |
+
"negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"name": "Manga",
|
41 |
+
"prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
|
42 |
+
"negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"name": "Digital Art",
|
46 |
+
"prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
|
47 |
+
"negative_prompt": "photo, photorealistic, realism, ugly",
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"name": "Pixel art",
|
51 |
+
"prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
|
52 |
+
"negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"name": "Fantasy art",
|
56 |
+
"prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
|
57 |
+
"negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
|
58 |
+
},
|
59 |
+
{
|
60 |
+
"name": "Neonpunk",
|
61 |
+
"prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
|
62 |
+
"negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"name": "3D Model",
|
66 |
+
"prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
|
67 |
+
"negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
|
68 |
+
},
|
69 |
+
]
|
70 |
+
|
71 |
+
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
72 |
+
STYLE_NAMES = list(styles.keys())
|
73 |
+
DEFAULT_STYLE_NAME = "(No style)"
|
74 |
+
|
75 |
+
|
76 |
+
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
77 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
78 |
+
return p.replace("{prompt}", positive), n + negative
|
79 |
+
|
80 |
+
|
81 |
word_list_dataset = load_dataset("google/word-list-sd", data_files="list.txt", use_auth_token=True)
|
82 |
word_list = word_list_dataset["train"]['text']
|
83 |
|
84 |
#gradio.helpers.CACHED_FOLDER="/data/cache"
|
85 |
|
86 |
+
def infer(prompt, negative="low_quality", scale=7, style_name=None, profile: gr.OAuthProfile | None = None):
|
87 |
for filter in word_list:
|
88 |
if re.search(rf"\b{filter}\b", prompt):
|
89 |
raise gr.Error("Please try again with a different prompt")
|
90 |
+
|
91 |
+
prompt, negative = apply_style(style_name, prompt, negative)
|
92 |
images = []
|
93 |
url = os.getenv('JAX_BACKEND_URL')
|
94 |
payload = {'prompt': prompt, 'negative_prompt': negative, 'guidance_scale': scale}
|
|
|
352 |
share_button = gr.Button("Share to community", elem_id="share-btn")
|
353 |
|
354 |
with gr.Accordion("Advanced settings", open=False):
|
355 |
+
style_selection = gr.Radio(
|
356 |
+
show_label=True, container=True, interactive=True,
|
357 |
+
choices=STYLE_NAMES,
|
358 |
+
value=DEFAULT_STYLE_NAME,
|
359 |
+
label='Image Style'
|
360 |
+
)
|
361 |
negative = gr.Textbox(
|
362 |
label="Enter your negative prompt",
|
363 |
show_label=False,
|
|
|
370 |
)
|
371 |
|
372 |
ex = gr.Examples(examples=examples, fn=infer, inputs=[text, negative, guidance_scale], outputs=[gallery, community_group], cache_examples=True, postprocess=False)
|
373 |
+
negative.submit(infer, inputs=[text, negative, guidance_scale, style_selection], outputs=[gallery, community_group], postprocess=False)
|
374 |
+
text.submit(infer, inputs=[text, negative, guidance_scale, style_selection], outputs=[gallery, community_group], postprocess=False)
|
375 |
+
btn.click(infer, inputs=[text, negative, guidance_scale, style_selection], outputs=[gallery, community_group], postprocess=False)
|
376 |
|
377 |
share_button.click(
|
378 |
None,
|