Spaces:
Runtime error
Runtime error
examples, pin version
Browse files- .gitignore +1 -0
- app.py +34 -21
- images/6.png +3 -0
- images/7.png +3 -0
- images/8.png +3 -0
- requirements.txt +7 -5
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
envs
|
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import random
|
| 3 |
|
|
@@ -6,8 +7,12 @@ import numpy as np
|
|
| 6 |
import PIL.Image
|
| 7 |
import spaces
|
| 8 |
import torch
|
| 9 |
-
from diffusers import (
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
from torchvision.transforms import ToTensor
|
| 12 |
|
| 13 |
# pyright: reportPrivateImportUsage=false
|
|
@@ -15,7 +20,8 @@ from torchvision.transforms import ToTensor
|
|
| 15 |
|
| 16 |
DESCRIPTION = f"""
|
| 17 |
# 🎨 Inversion-InstantStyle 🎨
|
| 18 |
-
This is an interactive demo of
|
|
|
|
| 19 |
"""
|
| 20 |
|
| 21 |
OPEN_SOURCE_PROMO = f"""
|
|
@@ -57,6 +63,8 @@ if gr.NO_RELOAD:
|
|
| 57 |
"stabilityai/stable-diffusion-xl-base-1.0", subfolder="scheduler"
|
| 58 |
)
|
| 59 |
invert_scheduler = DDIMInverseScheduler(**forward_scheduler.config)
|
|
|
|
|
|
|
| 60 |
|
| 61 |
css = """
|
| 62 |
h1 {
|
|
@@ -175,15 +183,20 @@ def generate(
|
|
| 175 |
|
| 176 |
examples_prompts = [
|
| 177 |
"Astronaut in a jungle, detailed, 8k",
|
| 178 |
-
"A
|
| 179 |
-
"A
|
| 180 |
-
"A
|
| 181 |
-
"cactus",
|
| 182 |
-
"A
|
|
|
|
|
|
|
|
|
|
| 183 |
]
|
| 184 |
|
| 185 |
-
examples_images =
|
| 186 |
-
|
|
|
|
|
|
|
| 187 |
examples = [[prompt, image] for prompt, image in zip(examples_prompts, examples_images)]
|
| 188 |
|
| 189 |
with gr.Blocks(css=css) as demo:
|
|
@@ -197,7 +210,17 @@ with gr.Blocks(css=css) as demo:
|
|
| 197 |
|
| 198 |
with gr.Column():
|
| 199 |
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
noise_scale = gr.Slider(
|
| 203 |
label="Noise Scale",
|
|
@@ -210,16 +233,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 210 |
with gr.Blocks():
|
| 211 |
|
| 212 |
with gr.Column():
|
| 213 |
-
with gr.Row():
|
| 214 |
-
prompt = gr.Text(
|
| 215 |
-
label="Prompt",
|
| 216 |
-
show_label=False,
|
| 217 |
-
max_lines=1,
|
| 218 |
-
placeholder="Enter your prompt",
|
| 219 |
-
container=False,
|
| 220 |
-
)
|
| 221 |
-
run_button = gr.Button("Run", scale=0)
|
| 222 |
-
|
| 223 |
result = gr.Image(label="Result", show_label=False)
|
| 224 |
|
| 225 |
with gr.Accordion("Advanced options", open=False):
|
|
|
|
| 1 |
+
import glob
|
| 2 |
import os
|
| 3 |
import random
|
| 4 |
|
|
|
|
| 7 |
import PIL.Image
|
| 8 |
import spaces
|
| 9 |
import torch
|
| 10 |
+
from diffusers import (
|
| 11 |
+
AutoencoderKL,
|
| 12 |
+
DDIMInverseScheduler,
|
| 13 |
+
DDIMScheduler,
|
| 14 |
+
StableDiffusionXLPipeline,
|
| 15 |
+
)
|
| 16 |
from torchvision.transforms import ToTensor
|
| 17 |
|
| 18 |
# pyright: reportPrivateImportUsage=false
|
|
|
|
| 20 |
|
| 21 |
DESCRIPTION = f"""
|
| 22 |
# 🎨 Inversion-InstantStyle 🎨
|
| 23 |
+
This is an interactive demo of [Inversion-InstantStyle](https://gojasper.github.io/style-rank-project/#inversion_instantstyle), which combines DDIM inversion and renoising with the [Instant-Style](https://instantstyle.github.io/) styling method.
|
| 24 |
+
It was proposed in the context of our [Style-Rank](https://gojasper.github.io/style-rank-project) benchmark which evaluates training-free styling methods, by *Eyal Benaroche, Clément Chadebec, Onur Tasar, and Benjamin Aubin* from [Jasper Research](https://www.jasper.ai/) and [Ecole Polytechnique](https://www.polytechnique.edu/).
|
| 25 |
"""
|
| 26 |
|
| 27 |
OPEN_SOURCE_PROMO = f"""
|
|
|
|
| 63 |
"stabilityai/stable-diffusion-xl-base-1.0", subfolder="scheduler"
|
| 64 |
)
|
| 65 |
invert_scheduler = DDIMInverseScheduler(**forward_scheduler.config)
|
| 66 |
+
else:
|
| 67 |
+
raise ValueError("This demo does not work on CPU.")
|
| 68 |
|
| 69 |
css = """
|
| 70 |
h1 {
|
|
|
|
| 183 |
|
| 184 |
examples_prompts = [
|
| 185 |
"Astronaut in a jungle, detailed, 8k",
|
| 186 |
+
"A bird",
|
| 187 |
+
"A tiger",
|
| 188 |
+
"A cat",
|
| 189 |
+
"A cactus",
|
| 190 |
+
"A panda",
|
| 191 |
+
"A duck",
|
| 192 |
+
"An elephant",
|
| 193 |
+
"A dragon head",
|
| 194 |
]
|
| 195 |
|
| 196 |
+
examples_images = glob.glob("./images/*.png")
|
| 197 |
+
assert len(examples_images) == len(
|
| 198 |
+
examples_prompts
|
| 199 |
+
), "Number of example images and prompts should match"
|
| 200 |
examples = [[prompt, image] for prompt, image in zip(examples_prompts, examples_images)]
|
| 201 |
|
| 202 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 210 |
|
| 211 |
with gr.Column():
|
| 212 |
|
| 213 |
+
with gr.Row():
|
| 214 |
+
prompt = gr.Text(
|
| 215 |
+
label="Target prompt",
|
| 216 |
+
show_label=False,
|
| 217 |
+
max_lines=1,
|
| 218 |
+
placeholder="Enter your prompt to generate new content",
|
| 219 |
+
container=False,
|
| 220 |
+
)
|
| 221 |
+
run_button = gr.Button("Run", scale=0)
|
| 222 |
+
|
| 223 |
+
style_image = gr.Image(label="Style reference image")
|
| 224 |
|
| 225 |
noise_scale = gr.Slider(
|
| 226 |
label="Noise Scale",
|
|
|
|
| 233 |
with gr.Blocks():
|
| 234 |
|
| 235 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
result = gr.Image(label="Result", show_label=False)
|
| 237 |
|
| 238 |
with gr.Accordion("Advanced options", open=False):
|
images/6.png
ADDED
|
Git LFS Details
|
images/7.png
ADDED
|
Git LFS Details
|
images/8.png
ADDED
|
Git LFS Details
|
requirements.txt
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
accelerate
|
| 2 |
diffusers
|
|
|
|
|
|
|
| 3 |
gradio==4.37.2
|
| 4 |
numpy==1.26.4
|
|
|
|
|
|
|
|
|
|
| 5 |
spaces
|
| 6 |
-
torch
|
| 7 |
torchvision
|
| 8 |
transformers >= 4.34.0
|
| 9 |
-
xformers
|
| 10 |
-
ftfy
|
| 11 |
-
peft==0.6.0
|
| 12 |
-
optimum
|
|
|
|
| 1 |
accelerate
|
| 2 |
diffusers
|
| 3 |
+
fastapi==0.112.2
|
| 4 |
+
ftfy
|
| 5 |
gradio==4.37.2
|
| 6 |
numpy==1.26.4
|
| 7 |
+
optimum
|
| 8 |
+
peft==0.6.0
|
| 9 |
+
pydantic
|
| 10 |
spaces
|
| 11 |
+
torch>=2.0.1
|
| 12 |
torchvision
|
| 13 |
transformers >= 4.34.0
|
| 14 |
+
xformers
|
|
|
|
|
|
|
|
|