Spaces:
Running
on
L4
Running
on
L4
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ sys.path.append('./latent-diffusion')
|
|
9 |
from taming.models import vqgan
|
10 |
from ldm.util import instantiate_from_config
|
11 |
from huggingface_hub import hf_hub_download
|
|
|
12 |
|
13 |
model_path_e = hf_hub_download(repo_id="multimodalart/compvis-latent-diffusion-text2img-large", filename="txt2img-f8-large.ckpt")
|
14 |
|
@@ -100,6 +101,7 @@ model = model.to(device)
|
|
100 |
safety_model = load_safety_model("ViT-B/32")
|
101 |
clip_model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pretrained='openai')
|
102 |
|
|
|
103 |
def run(prompt, steps, width, height, images, scale):
|
104 |
opt = argparse.Namespace(
|
105 |
prompt = prompt,
|
@@ -179,20 +181,23 @@ def run(prompt, steps, width, height, images, scale):
|
|
179 |
grid = 255. * rearrange(grid, 'c h w -> h w c').cpu().numpy()
|
180 |
|
181 |
Image.fromarray(grid.astype(np.uint8)).save(os.path.join(outpath, f'{prompt.replace(" ", "-")}.png'))
|
182 |
-
return(Image.fromarray(grid.astype(np.uint8)),
|
183 |
|
184 |
-
image = gr.
|
185 |
css = ".output-image{height: 528px !important} .output-carousel .output-image{height:272px !important} a{text-decoration: underline}"
|
186 |
iface = gr.Interface(fn=run, inputs=[
|
187 |
-
gr.
|
188 |
-
gr.
|
189 |
-
gr.
|
190 |
-
gr.
|
191 |
-
gr.
|
192 |
-
gr.
|
193 |
#gr.inputs.Slider(label="ETA - between 0 and 1. Lower values can provide better quality, higher values can be more diverse",default=0.0,minimum=0.0, maximum=1.0,step=0.1),
|
194 |
],
|
195 |
-
outputs=[
|
|
|
|
|
|
|
196 |
css=css,
|
197 |
title="Generate images from text with Latent Diffusion LAION-400M",
|
198 |
description="<div>By typing a prompt and pressing submit you can generate images based on this prompt. <a href='https://github.com/CompVis/latent-diffusion' target='_blank'>Latent Diffusion</a> is a text-to-image model created by <a href='https://github.com/CompVis' target='_blank'>CompVis</a>, trained on the <a href='https://laion.ai/laion-400-open-dataset/'>LAION-400M dataset.</a><br>This UI to the model was assembled by <a style='color: rgb(245, 158, 11);font-weight:bold' href='https://twitter.com/multimodalart' target='_blank'>@multimodalart</a></div>",
|
|
|
9 |
from taming.models import vqgan
|
10 |
from ldm.util import instantiate_from_config
|
11 |
from huggingface_hub import hf_hub_download
|
12 |
+
import spaces
|
13 |
|
14 |
model_path_e = hf_hub_download(repo_id="multimodalart/compvis-latent-diffusion-text2img-large", filename="txt2img-f8-large.ckpt")
|
15 |
|
|
|
101 |
safety_model = load_safety_model("ViT-B/32")
|
102 |
clip_model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pretrained='openai')
|
103 |
|
104 |
+
@spaces.GPU
|
105 |
def run(prompt, steps, width, height, images, scale):
|
106 |
opt = argparse.Namespace(
|
107 |
prompt = prompt,
|
|
|
181 |
grid = 255. * rearrange(grid, 'c h w -> h w c').cpu().numpy()
|
182 |
|
183 |
Image.fromarray(grid.astype(np.uint8)).save(os.path.join(outpath, f'{prompt.replace(" ", "-")}.png'))
|
184 |
+
return(all_samples_images,Image.fromarray(grid.astype(np.uint8)),None)
|
185 |
|
186 |
+
image = gr.Image(type="pil", label="Image Grid")
|
187 |
css = ".output-image{height: 528px !important} .output-carousel .output-image{height:272px !important} a{text-decoration: underline}"
|
188 |
iface = gr.Interface(fn=run, inputs=[
|
189 |
+
gr.Textbox(label="Prompt - try adding increments to your prompt such as 'oil on canvas', 'a painting', 'a book cover'",default="chalk pastel drawing of a dog wearing a funny hat"),
|
190 |
+
gr.Slider(label="Steps - more steps can increase quality but will take longer to generate",default=45,maximum=50,minimum=1,step=1),
|
191 |
+
gr.Radio(label="Width", choices=[32,64,128,256],default=256),
|
192 |
+
gr.Radio(label="Height", choices=[32,64,128,256],default=256),
|
193 |
+
gr.Slider(label="Images - How many images you wish to generate", default=2, step=1, minimum=1, maximum=4),
|
194 |
+
gr.Slider(label="Diversity scale - How different from one another you wish the images to be",default=5.0, minimum=1.0, maximum=15.0),
|
195 |
#gr.inputs.Slider(label="ETA - between 0 and 1. Lower values can provide better quality, higher values can be more diverse",default=0.0,minimum=0.0, maximum=1.0,step=0.1),
|
196 |
],
|
197 |
+
outputs=[gr.Gallery(label="Individual images"),
|
198 |
+
image,
|
199 |
+
gr.Textbox(label="Error")
|
200 |
+
],
|
201 |
css=css,
|
202 |
title="Generate images from text with Latent Diffusion LAION-400M",
|
203 |
description="<div>By typing a prompt and pressing submit you can generate images based on this prompt. <a href='https://github.com/CompVis/latent-diffusion' target='_blank'>Latent Diffusion</a> is a text-to-image model created by <a href='https://github.com/CompVis' target='_blank'>CompVis</a>, trained on the <a href='https://laion.ai/laion-400-open-dataset/'>LAION-400M dataset.</a><br>This UI to the model was assembled by <a style='color: rgb(245, 158, 11);font-weight:bold' href='https://twitter.com/multimodalart' target='_blank'>@multimodalart</a></div>",
|