Veda_Sahaja commited on
Commit ·
1319924
1
Parent(s): f0454f1
Update space
Browse files
app.py
CHANGED
|
@@ -3,6 +3,68 @@ import numpy as np
|
|
| 3 |
import random
|
| 4 |
from diffusers import DiffusionPipeline
|
| 5 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
|
|
@@ -78,12 +140,18 @@ with gr.Blocks(css=css) as demo:
|
|
| 78 |
result = gr.Image(label="Result", show_label=False)
|
| 79 |
|
| 80 |
with gr.Accordion("Advanced Settings", open=False):
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
max_lines=1,
|
| 85 |
placeholder="Enter a negative prompt",
|
| 86 |
-
|
| 87 |
)
|
| 88 |
|
| 89 |
seed = gr.Slider(
|
|
|
|
| 3 |
import random
|
| 4 |
from diffusers import DiffusionPipeline
|
| 5 |
import torch
|
| 6 |
+
from typing import Tuple
|
| 7 |
+
|
| 8 |
+
style_list = [
|
| 9 |
+
{
|
| 10 |
+
"name": "(No style)",
|
| 11 |
+
"prompt": "{prompt}",
|
| 12 |
+
"negative_prompt": "",
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"name": "Cinematic",
|
| 16 |
+
"prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
|
| 17 |
+
"negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"name": "Photographic",
|
| 21 |
+
"prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
|
| 22 |
+
"negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"name": "Anime",
|
| 26 |
+
"prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
|
| 27 |
+
"negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"name": "Manga",
|
| 31 |
+
"prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
|
| 32 |
+
"negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"name": "Digital Art",
|
| 36 |
+
"prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
|
| 37 |
+
"negative_prompt": "photo, photorealistic, realism, ugly",
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"name": "Pixel art",
|
| 41 |
+
"prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
|
| 42 |
+
"negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"name": "Fantasy art",
|
| 46 |
+
"prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
|
| 47 |
+
"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",
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "Neonpunk",
|
| 51 |
+
"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",
|
| 52 |
+
"negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"name": "3D Model",
|
| 56 |
+
"prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
|
| 57 |
+
"negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
|
| 58 |
+
},
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
| 62 |
+
STYLE_NAMES = list(styles.keys())
|
| 63 |
+
DEFAULT_STYLE_NAME = "(No style)"
|
| 64 |
+
|
| 65 |
+
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 66 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 67 |
+
return p.replace("{prompt}", positive), n + negative
|
| 68 |
|
| 69 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 70 |
|
|
|
|
| 140 |
result = gr.Image(label="Result", show_label=False)
|
| 141 |
|
| 142 |
with gr.Accordion("Advanced Settings", open=False):
|
| 143 |
+
style_selection = gr.Radio(
|
| 144 |
+
show_label=True, container=True, interactive=True,
|
| 145 |
+
choices=STYLE_NAMES,
|
| 146 |
+
value=DEFAULT_STYLE_NAME,
|
| 147 |
+
label='Image Style'
|
| 148 |
+
)
|
| 149 |
+
negative_prompt = gr.Textbox(
|
| 150 |
+
label="Enter your negative prompt",
|
| 151 |
+
show_label=False,
|
| 152 |
max_lines=1,
|
| 153 |
placeholder="Enter a negative prompt",
|
| 154 |
+
elem_id="negative-prompt-text-input",
|
| 155 |
)
|
| 156 |
|
| 157 |
seed = gr.Slider(
|