Spaces:
Runtime error
Runtime error
+new models
Browse files
app.py
CHANGED
@@ -45,6 +45,7 @@ scheduler = DPMSolverMultistepScheduler(
|
|
45 |
lower_order_final=True,
|
46 |
)
|
47 |
|
|
|
48 |
if is_colab:
|
49 |
models.insert(0, Model("Custom model", "", ""))
|
50 |
custom_model = models[0]
|
@@ -77,7 +78,7 @@ def custom_model_changed(path):
|
|
77 |
global current_model
|
78 |
current_model = models[0]
|
79 |
|
80 |
-
def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""
|
81 |
|
82 |
global current_model
|
83 |
for model in models:
|
@@ -90,9 +91,9 @@ def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0
|
|
90 |
if img is not None:
|
91 |
return img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, width, height, generator)
|
92 |
else:
|
93 |
-
return txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, generator
|
94 |
|
95 |
-
def txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, generator=None
|
96 |
|
97 |
global last_mode
|
98 |
global pipe
|
@@ -110,18 +111,11 @@ def txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, g
|
|
110 |
pipe = pipe.to("cuda")
|
111 |
last_mode = "txt2img"
|
112 |
|
113 |
-
prompt = current_model.prefix + prompt
|
114 |
-
|
115 |
-
if inpaint_image is not None:
|
116 |
-
init_image = inpaint_image["image"].convert("RGB").resize((width, height))
|
117 |
-
mask = inpaint_image["mask"].convert("RGB").resize((width, height))
|
118 |
-
|
119 |
result = pipe(
|
120 |
prompt,
|
121 |
negative_prompt = neg_prompt,
|
122 |
# num_images_per_prompt=n_images,
|
123 |
-
image = init_image,
|
124 |
-
mask_image = mask,
|
125 |
num_inference_steps = int(steps),
|
126 |
guidance_scale = guidance,
|
127 |
width = width,
|
@@ -182,7 +176,7 @@ with gr.Blocks(css=css) as demo:
|
|
182 |
</div>
|
183 |
<p>
|
184 |
Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
|
185 |
-
<a href="https://huggingface.co/nitrosocke/Arcane-Diffusion">Arcane</a>, <a href="https://huggingface.co/nitrosocke/archer-diffusion">Archer</a>, <a href="https://huggingface.co/nitrosocke/elden-ring-diffusion">Elden Ring</a>, <a href="https://huggingface.co/nitrosocke/spider-verse-diffusion">Spider-Verse</a>, <a href="https://huggingface.co/nitrosocke/
|
186 |
</p>
|
187 |
<p>You can skip the queue and load custom models in the colab: <a href="https://colab.research.google.com/gist/qunash/42112fb104509c24fd3aa6d1c11dd6e0/copy-of-fine-tuned-diffusion-gradio.ipynb"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
|
188 |
Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
|
@@ -231,15 +225,12 @@ with gr.Blocks(css=css) as demo:
|
|
231 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
232 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
233 |
|
234 |
-
with gr.Tab("Inpainting"):
|
235 |
-
inpaint_image = gr.Image(source='upload', tool='sketch', type="pil", label="Upload").style(height=256)
|
236 |
-
|
237 |
model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
|
238 |
if is_colab:
|
239 |
custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
|
240 |
# n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
|
241 |
|
242 |
-
inputs = [model_name, prompt, guidance, steps, width, height, seed, image, strength, neg_prompt
|
243 |
prompt.submit(inference, inputs=inputs, outputs=image_out)
|
244 |
generate.click(inference, inputs=inputs, outputs=image_out)
|
245 |
|
@@ -251,12 +242,11 @@ with gr.Blocks(css=css) as demo:
|
|
251 |
[models[5].name, "fantasy portrait painting, digital art", 4.0, 30],
|
252 |
], [model_name, prompt, guidance, steps, seed], image_out, inference, cache_examples=False)
|
253 |
|
254 |
-
gr.
|
255 |
-
Models by
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
''')
|
260 |
|
261 |
if not is_colab:
|
262 |
demo.queue(concurrency_count=1)
|
|
|
45 |
lower_order_final=True,
|
46 |
)
|
47 |
|
48 |
+
custom_model = None
|
49 |
if is_colab:
|
50 |
models.insert(0, Model("Custom model", "", ""))
|
51 |
custom_model = models[0]
|
|
|
78 |
global current_model
|
79 |
current_model = models[0]
|
80 |
|
81 |
+
def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""):
|
82 |
|
83 |
global current_model
|
84 |
for model in models:
|
|
|
91 |
if img is not None:
|
92 |
return img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, width, height, generator)
|
93 |
else:
|
94 |
+
return txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, generator)
|
95 |
|
96 |
+
def txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, generator=None):
|
97 |
|
98 |
global last_mode
|
99 |
global pipe
|
|
|
111 |
pipe = pipe.to("cuda")
|
112 |
last_mode = "txt2img"
|
113 |
|
114 |
+
prompt = current_model.prefix + prompt
|
|
|
|
|
|
|
|
|
|
|
115 |
result = pipe(
|
116 |
prompt,
|
117 |
negative_prompt = neg_prompt,
|
118 |
# num_images_per_prompt=n_images,
|
|
|
|
|
119 |
num_inference_steps = int(steps),
|
120 |
guidance_scale = guidance,
|
121 |
width = width,
|
|
|
176 |
</div>
|
177 |
<p>
|
178 |
Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
|
179 |
+
<a href="https://huggingface.co/nitrosocke/Arcane-Diffusion">Arcane</a>, <a href="https://huggingface.co/nitrosocke/archer-diffusion">Archer</a>, <a href="https://huggingface.co/nitrosocke/elden-ring-diffusion">Elden Ring</a>, <a href="https://huggingface.co/nitrosocke/spider-verse-diffusion">Spider-Verse</a>, <a href="https://huggingface.co/nitrosocke/mo-di-diffusion">Modern Disney</a>, <a href="https://huggingface.co/nitrosocke/classic-anim-diffusion">Classic Disney</a>, <a href="https://huggingface.co/dallinmackay/Van-Gogh-diffusion">Loving Vincent (Van Gogh)</a>, <a href="https://huggingface.co/nitrosocke/redshift-diffusion">Redshift renderer (Cinema4D)</a>, <a href="https://huggingface.co/prompthero/midjourney-v4-diffusion">Midjourney v4 style</a>, <a href="https://huggingface.co/hakurei/waifu-diffusion">Waifu</a>, <a href="https://huggingface.co/lambdalabs/sd-pokemon-diffusers">Pokémon</a>, <a href="https://huggingface.co/AstraliteHeart/pony-diffusion">Pony Diffusion</a>, <a href="https://huggingface.co/nousr/robo-diffusion">Robo Diffusion</a>, <a href="https://huggingface.co/DGSpitzer/Cyberpunk-Anime-Diffusion">Cyberpunk Anime</a>, <a href="https://huggingface.co/dallinmackay/Tron-Legacy-diffusion">Tron Legacy</a> + in colab notebook you can load any other Diffusers 🧨 SD model hosted on HuggingFace 🤗.
|
180 |
</p>
|
181 |
<p>You can skip the queue and load custom models in the colab: <a href="https://colab.research.google.com/gist/qunash/42112fb104509c24fd3aa6d1c11dd6e0/copy-of-fine-tuned-diffusion-gradio.ipynb"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
|
182 |
Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
|
|
|
225 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
226 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
227 |
|
|
|
|
|
|
|
228 |
model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
|
229 |
if is_colab:
|
230 |
custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
|
231 |
# n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
|
232 |
|
233 |
+
inputs = [model_name, prompt, guidance, steps, width, height, seed, image, strength, neg_prompt]
|
234 |
prompt.submit(inference, inputs=inputs, outputs=image_out)
|
235 |
generate.click(inference, inputs=inputs, outputs=image_out)
|
236 |
|
|
|
242 |
[models[5].name, "fantasy portrait painting, digital art", 4.0, 30],
|
243 |
], [model_name, prompt, guidance, steps, seed], image_out, inference, cache_examples=False)
|
244 |
|
245 |
+
gr.HTML("""
|
246 |
+
<p>Models by <a href="https://huggingface.co/nitrosocke">@nitrosocke</a>, <a href="https://twitter.com/haruu1367">@haruu1367</a>, <a href="https://twitter.com/DGSpitzer">@Helixngc7293</a>, <a href="https://twitter.com/dal_mack">@dal_mack</a>, <a href="https://twitter.com/prompthero">@prompthero</a> and others. ❤️</p>
|
247 |
+
<p>Space by: <a href="https://twitter.com/hahahahohohe"><img src="https://img.shields.io/twitter/follow/hahahahohohe?label=%40anzorq&style=social" alt="Twitter Follow"></a></p>
|
248 |
+
<p><img src="https://visitor-badge.glitch.me/badge?page_id=anzorq.finetuned_diffusion" alt="visitors"></p>
|
249 |
+
""")
|
|
|
250 |
|
251 |
if not is_colab:
|
252 |
demo.queue(concurrency_count=1)
|