Update app.py
Browse files
app.py
CHANGED
@@ -27,9 +27,11 @@ from src.pipelines.pipeline_kandinsky_subject_prior import KandinskyPriorPipelin
|
|
27 |
from diffusers import DiffusionPipeline
|
28 |
from PIL import Image
|
29 |
|
|
|
|
|
30 |
class Model:
|
31 |
def __init__(self):
|
32 |
-
self.device =
|
33 |
|
34 |
self.text_encoder = (
|
35 |
CLIPTextModelWithProjection.from_pretrained(
|
@@ -39,7 +41,7 @@ class Model:
|
|
39 |
)
|
40 |
.eval()
|
41 |
.requires_grad_(False)
|
42 |
-
).to(
|
43 |
|
44 |
self.tokenizer = CLIPTokenizer.from_pretrained(
|
45 |
"laion/CLIP-ViT-bigG-14-laion2B-39B-b160k",
|
@@ -99,7 +101,7 @@ class Model:
|
|
99 |
plt.savefig('image_testt2.png')
|
100 |
plt.show()
|
101 |
|
102 |
-
mask_img = self.image_processor(image, return_tensors="pt").to(
|
103 |
vision_feats = self.vision_encoder(
|
104 |
**mask_img
|
105 |
).image_embeds
|
@@ -111,7 +113,7 @@ class Model:
|
|
111 |
print(indices)
|
112 |
|
113 |
if image2 is not None:
|
114 |
-
mask_img2 = self.image_processor(image2, return_tensors="pt").to(
|
115 |
vision_feats2 = self.vision_encoder(
|
116 |
**mask_img2
|
117 |
).image_embeds
|
@@ -123,9 +125,9 @@ class Model:
|
|
123 |
print(indices)
|
124 |
|
125 |
text_feats = {
|
126 |
-
"prompt_embeds": new_feats.text_embeds.to(
|
127 |
-
"text_encoder_hidden_states": torch.tensor(new_last_hidden_states).unsqueeze(0).to(
|
128 |
-
"text_mask": txt_items["attention_mask"].to(
|
129 |
}
|
130 |
return text_feats
|
131 |
|
@@ -219,4 +221,4 @@ def create_demo():
|
|
219 |
|
220 |
if __name__ == '__main__':
|
221 |
demo = create_demo()
|
222 |
-
demo.queue(
|
|
|
27 |
from diffusers import DiffusionPipeline
|
28 |
from PIL import Image
|
29 |
|
30 |
+
__device__ = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
+
|
32 |
class Model:
|
33 |
def __init__(self):
|
34 |
+
self.device = __device__
|
35 |
|
36 |
self.text_encoder = (
|
37 |
CLIPTextModelWithProjection.from_pretrained(
|
|
|
41 |
)
|
42 |
.eval()
|
43 |
.requires_grad_(False)
|
44 |
+
).to(self.device)
|
45 |
|
46 |
self.tokenizer = CLIPTokenizer.from_pretrained(
|
47 |
"laion/CLIP-ViT-bigG-14-laion2B-39B-b160k",
|
|
|
101 |
plt.savefig('image_testt2.png')
|
102 |
plt.show()
|
103 |
|
104 |
+
mask_img = self.image_processor(image, return_tensors="pt").to(__device__)
|
105 |
vision_feats = self.vision_encoder(
|
106 |
**mask_img
|
107 |
).image_embeds
|
|
|
113 |
print(indices)
|
114 |
|
115 |
if image2 is not None:
|
116 |
+
mask_img2 = self.image_processor(image2, return_tensors="pt").to(__device__)
|
117 |
vision_feats2 = self.vision_encoder(
|
118 |
**mask_img2
|
119 |
).image_embeds
|
|
|
125 |
print(indices)
|
126 |
|
127 |
text_feats = {
|
128 |
+
"prompt_embeds": new_feats.text_embeds.to(__device__),
|
129 |
+
"text_encoder_hidden_states": torch.tensor(new_last_hidden_states).unsqueeze(0).to(__device__),
|
130 |
+
"text_mask": txt_items["attention_mask"].to(__device__),
|
131 |
}
|
132 |
return text_feats
|
133 |
|
|
|
221 |
|
222 |
if __name__ == '__main__':
|
223 |
demo = create_demo()
|
224 |
+
demo.queue(api_open=False).launch(share=True)
|