Spaces:
Runtime error
Runtime error
Update
Browse files- README.md +1 -1
- app.py +33 -14
- requirements.txt +3 -2
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🚀
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.43.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -21,6 +21,11 @@ if not torch.cuda.is_available():
|
|
21 |
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
|
22 |
|
23 |
style_list = [
|
|
|
|
|
|
|
|
|
|
|
24 |
{
|
25 |
"name": "Cinematic",
|
26 |
"prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
|
@@ -56,16 +61,25 @@ style_list = [
|
|
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 |
|
61 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
62 |
-
|
63 |
-
|
64 |
-
style_names = list(styles.keys())
|
65 |
|
66 |
|
67 |
def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
|
68 |
-
p, n = styles.get(style_name,
|
69 |
return p.replace("{prompt}", positive), n + negative
|
70 |
|
71 |
|
@@ -101,12 +115,13 @@ def run(
|
|
101 |
image: PIL.Image.Image,
|
102 |
prompt: str,
|
103 |
negative_prompt: str,
|
104 |
-
style_name: str =
|
105 |
num_steps: int = 25,
|
106 |
guidance_scale: float = 5,
|
107 |
adapter_conditioning_scale: float = 0.8,
|
108 |
-
|
109 |
seed: int = 0,
|
|
|
110 |
) -> PIL.Image.Image:
|
111 |
image = image.convert("RGB")
|
112 |
image = TF.to_tensor(image) > 0.5
|
@@ -123,7 +138,7 @@ def run(
|
|
123 |
generator=generator,
|
124 |
guidance_scale=guidance_scale,
|
125 |
adapter_conditioning_scale=adapter_conditioning_scale,
|
126 |
-
|
127 |
).images[0]
|
128 |
return out
|
129 |
|
@@ -150,10 +165,13 @@ with gr.Blocks(css="style.css") as demo:
|
|
150 |
height=600,
|
151 |
)
|
152 |
prompt = gr.Textbox(label="Prompt")
|
|
|
153 |
run_button = gr.Button("Run")
|
154 |
with gr.Accordion("Advanced options", open=False):
|
155 |
-
|
156 |
-
|
|
|
|
|
157 |
num_steps = gr.Slider(
|
158 |
label="Number of steps",
|
159 |
minimum=1,
|
@@ -169,14 +187,15 @@ with gr.Blocks(css="style.css") as demo:
|
|
169 |
value=5,
|
170 |
)
|
171 |
adapter_conditioning_scale = gr.Slider(
|
172 |
-
label="Adapter
|
173 |
minimum=0.5,
|
174 |
maximum=1,
|
175 |
step=0.1,
|
176 |
value=0.8,
|
177 |
)
|
178 |
-
|
179 |
-
label="
|
|
|
180 |
minimum=0.5,
|
181 |
maximum=1,
|
182 |
step=0.1,
|
@@ -201,7 +220,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
201 |
num_steps,
|
202 |
guidance_scale,
|
203 |
adapter_conditioning_scale,
|
204 |
-
|
205 |
seed,
|
206 |
]
|
207 |
prompt.submit(
|
@@ -238,7 +257,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
238 |
fn=run,
|
239 |
inputs=inputs,
|
240 |
outputs=result,
|
241 |
-
api_name=
|
242 |
)
|
243 |
|
244 |
if __name__ == "__main__":
|
|
|
21 |
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
|
22 |
|
23 |
style_list = [
|
24 |
+
{
|
25 |
+
"name": "(No style)",
|
26 |
+
"prompt": "{prompt}",
|
27 |
+
"negative_prompt": "",
|
28 |
+
},
|
29 |
{
|
30 |
"name": "Cinematic",
|
31 |
"prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
|
|
|
61 |
"prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
|
62 |
"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",
|
63 |
},
|
64 |
+
{
|
65 |
+
"name": "Neonpunk",
|
66 |
+
"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",
|
67 |
+
"negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"name": "Manga",
|
71 |
+
"prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
|
72 |
+
"negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
|
73 |
+
},
|
74 |
]
|
75 |
|
76 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
77 |
+
STYLE_NAMES = list(styles.keys())
|
78 |
+
DEFAULT_STYLE_NAME = "(No style)"
|
|
|
79 |
|
80 |
|
81 |
def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
|
82 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
83 |
return p.replace("{prompt}", positive), n + negative
|
84 |
|
85 |
|
|
|
115 |
image: PIL.Image.Image,
|
116 |
prompt: str,
|
117 |
negative_prompt: str,
|
118 |
+
style_name: str = DEFAULT_STYLE_NAME,
|
119 |
num_steps: int = 25,
|
120 |
guidance_scale: float = 5,
|
121 |
adapter_conditioning_scale: float = 0.8,
|
122 |
+
adapter_conditioning_factor: float = 0.8,
|
123 |
seed: int = 0,
|
124 |
+
progress=gr.Progress(track_tqdm=True),
|
125 |
) -> PIL.Image.Image:
|
126 |
image = image.convert("RGB")
|
127 |
image = TF.to_tensor(image) > 0.5
|
|
|
138 |
generator=generator,
|
139 |
guidance_scale=guidance_scale,
|
140 |
adapter_conditioning_scale=adapter_conditioning_scale,
|
141 |
+
adapter_conditioning_factor=adapter_conditioning_factor,
|
142 |
).images[0]
|
143 |
return out
|
144 |
|
|
|
165 |
height=600,
|
166 |
)
|
167 |
prompt = gr.Textbox(label="Prompt")
|
168 |
+
style = gr.Dropdown(label="Style", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
|
169 |
run_button = gr.Button("Run")
|
170 |
with gr.Accordion("Advanced options", open=False):
|
171 |
+
negative_prompt = gr.Textbox(
|
172 |
+
label="Negative prompt",
|
173 |
+
value=" extra digit, fewer digits, cropped, worst quality, low quality, glitch, deformed, mutated, ugly, disfigured",
|
174 |
+
)
|
175 |
num_steps = gr.Slider(
|
176 |
label="Number of steps",
|
177 |
minimum=1,
|
|
|
187 |
value=5,
|
188 |
)
|
189 |
adapter_conditioning_scale = gr.Slider(
|
190 |
+
label="Adapter conditioning scale",
|
191 |
minimum=0.5,
|
192 |
maximum=1,
|
193 |
step=0.1,
|
194 |
value=0.8,
|
195 |
)
|
196 |
+
adapter_conditioning_factor = gr.Slider(
|
197 |
+
label="Adapter conditioning factor",
|
198 |
+
info="Fraction of timesteps for which adapter should be applied",
|
199 |
minimum=0.5,
|
200 |
maximum=1,
|
201 |
step=0.1,
|
|
|
220 |
num_steps,
|
221 |
guidance_scale,
|
222 |
adapter_conditioning_scale,
|
223 |
+
adapter_conditioning_factor,
|
224 |
seed,
|
225 |
]
|
226 |
prompt.submit(
|
|
|
257 |
fn=run,
|
258 |
inputs=inputs,
|
259 |
outputs=result,
|
260 |
+
api_name=False,
|
261 |
)
|
262 |
|
263 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
accelerate==0.22.0
|
2 |
git+https://github.com/huggingface/diffusers@t2iadapterxl
|
3 |
-
gradio==3.
|
4 |
Pillow==10.0.0
|
5 |
safetensors==0.3.3
|
6 |
torch==2.0.1
|
7 |
torchvision==0.15.2
|
8 |
-
transformers==4.33.
|
|
|
|
1 |
accelerate==0.22.0
|
2 |
git+https://github.com/huggingface/diffusers@t2iadapterxl
|
3 |
+
gradio==3.43.1
|
4 |
Pillow==10.0.0
|
5 |
safetensors==0.3.3
|
6 |
torch==2.0.1
|
7 |
torchvision==0.15.2
|
8 |
+
transformers==4.33.1
|
9 |
+
xformers==0.0.20
|