Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,9 @@ sys.path.append('./taming-transformers')
|
|
8 |
sys.path.append('./latent-diffusion')
|
9 |
from taming.models import vqgan
|
10 |
from ldm.util import instantiate_from_config
|
|
|
11 |
|
12 |
-
|
13 |
|
14 |
#@title Import stuff
|
15 |
import argparse, os, sys, glob
|
@@ -91,7 +92,7 @@ def is_unsafe(safety_model, embeddings, threshold=0.5):
|
|
91 |
return True if x > threshold else False
|
92 |
|
93 |
config = OmegaConf.load("latent-diffusion/configs/latent-diffusion/txt2img-1p4B-eval.yaml")
|
94 |
-
model = load_model_from_config(config,
|
95 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
96 |
model = model.to(device)
|
97 |
|
@@ -160,7 +161,7 @@ def run(prompt, steps, width, height, images, scale):
|
|
160 |
image_features = clip_model.encode_image(image_preprocess)
|
161 |
image_features /= image_features.norm(dim=-1, keepdim=True)
|
162 |
query = image_features.cpu().detach().numpy().astype("float32")
|
163 |
-
|
164 |
unsafe=False
|
165 |
if(not unsafe):
|
166 |
all_samples_images.append(image_vector)
|
@@ -195,6 +196,6 @@ iface = gr.Interface(fn=run, inputs=[
|
|
195 |
outputs=[image,gr.outputs.Carousel(label="Individual images",components=["image"]),gr.outputs.Textbox(label="Error")],
|
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
|
199 |
article="<h4 style='font-size: 110%;margin-top:.5em'>Biases acknowledgment</h4><div>Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exarcbates societal biases. According to the <a href='https://arxiv.org/abs/2112.10752' target='_blank'>Latent Diffusion paper</a>:<i> \"Deep learning modules tend to reproduce or exacerbate biases that are already present in the data\"</i>. The model was trained on an unfiltered version the LAION-400M dataset, which scrapped non-curated image-text-pairs from the internet (the exception being the the removal of illegal content) and is meant to be used for research purposes, such as this one. <a href='https://laion.ai/laion-400-open-dataset/' target='_blank'>You can read more on LAION's website</a></div><h4 style='font-size: 110%;margin-top:1em'>Who owns the images produced by this demo?</h4><div>Definetly not me! Probably you do. I say probably because the Copyright discussion about AI generated art is ongoing. So <a href='https://www.theverge.com/2022/2/21/22944335/us-copyright-office-reject-ai-generated-art-recent-entrance-to-paradise' target='_blank'>it may be the case that everything produced here falls automatically into the public domain</a>. But in any case it is either yours or is in the public domain.</div>")
|
200 |
iface.launch(enable_queue=True)
|
|
|
8 |
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 |
|
15 |
#@title Import stuff
|
16 |
import argparse, os, sys, glob
|
|
|
92 |
return True if x > threshold else False
|
93 |
|
94 |
config = OmegaConf.load("latent-diffusion/configs/latent-diffusion/txt2img-1p4B-eval.yaml")
|
95 |
+
model = load_model_from_config(config,model_path_e)
|
96 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
97 |
model = model.to(device)
|
98 |
|
|
|
161 |
image_features = clip_model.encode_image(image_preprocess)
|
162 |
image_features /= image_features.norm(dim=-1, keepdim=True)
|
163 |
query = image_features.cpu().detach().numpy().astype("float32")
|
164 |
+
unsafe = is_unsafe(safety_model,query,0.5)
|
165 |
unsafe=False
|
166 |
if(not unsafe):
|
167 |
all_samples_images.append(image_vector)
|
|
|
196 |
outputs=[image,gr.outputs.Carousel(label="Individual images",components=["image"]),gr.outputs.Textbox(label="Error")],
|
197 |
css=css,
|
198 |
title="Generate images from text with Latent Diffusion LAION-400M",
|
199 |
+
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> nsfw filter desactivated</div>",
|
200 |
article="<h4 style='font-size: 110%;margin-top:.5em'>Biases acknowledgment</h4><div>Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exarcbates societal biases. According to the <a href='https://arxiv.org/abs/2112.10752' target='_blank'>Latent Diffusion paper</a>:<i> \"Deep learning modules tend to reproduce or exacerbate biases that are already present in the data\"</i>. The model was trained on an unfiltered version the LAION-400M dataset, which scrapped non-curated image-text-pairs from the internet (the exception being the the removal of illegal content) and is meant to be used for research purposes, such as this one. <a href='https://laion.ai/laion-400-open-dataset/' target='_blank'>You can read more on LAION's website</a></div><h4 style='font-size: 110%;margin-top:1em'>Who owns the images produced by this demo?</h4><div>Definetly not me! Probably you do. I say probably because the Copyright discussion about AI generated art is ongoing. So <a href='https://www.theverge.com/2022/2/21/22944335/us-copyright-office-reject-ai-generated-art-recent-entrance-to-paradise' target='_blank'>it may be the case that everything produced here falls automatically into the public domain</a>. But in any case it is either yours or is in the public domain.</div>")
|
201 |
iface.launch(enable_queue=True)
|