Spaces:
Sleeping
Sleeping
Commit
·
f2299a3
1
Parent(s):
0dff6d2
Update app.py
Browse files
app.py
CHANGED
@@ -130,7 +130,7 @@ pipe.to(device=DEVICE)
|
|
130 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration, BitsAndBytesConfig
|
131 |
|
132 |
quantization_config = BitsAndBytesConfig(load_in_4bit=True)
|
133 |
-
pali = PaliGemmaForConditionalGeneration.from_pretrained('google/paligemma-3b-pt-224', torch_dtype=dtype, quantization_config=quantization_config).eval()
|
134 |
processor = AutoProcessor.from_pretrained('google/paligemma-3b-pt-224')
|
135 |
|
136 |
|
@@ -566,17 +566,22 @@ scheduler.start()
|
|
566 |
#thread.start()
|
567 |
|
568 |
# TODO shouldn't call this before gradio launch, yeah?
|
569 |
-
@spaces.GPU(duration=
|
570 |
def encode_space(x):
|
|
|
571 |
im_emb, _ = pipe.encode_image(
|
572 |
x, DEVICE, 1, output_hidden_state
|
573 |
)
|
574 |
|
575 |
-
|
|
|
|
|
|
|
576 |
im = torch.nn.functional.interpolate(im, (224, 224))
|
577 |
im = (im - .5) * 2
|
578 |
-
gemb = pali.vision_tower(im.to(
|
579 |
-
|
|
|
580 |
return im_emb.detach().to('cpu').to(torch.float32), gemb
|
581 |
|
582 |
demo.launch(share=True,)
|
|
|
130 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration, BitsAndBytesConfig
|
131 |
|
132 |
quantization_config = BitsAndBytesConfig(load_in_4bit=True)
|
133 |
+
pali = PaliGemmaForConditionalGeneration.from_pretrained('google/paligemma-3b-pt-224', torch_dtype=dtype, quantization_config=quantization_config).eval()
|
134 |
processor = AutoProcessor.from_pretrained('google/paligemma-3b-pt-224')
|
135 |
|
136 |
|
|
|
566 |
#thread.start()
|
567 |
|
568 |
# TODO shouldn't call this before gradio launch, yeah?
|
569 |
+
@spaces.GPU(duration=40)
|
570 |
def encode_space(x):
|
571 |
+
print('encode')
|
572 |
im_emb, _ = pipe.encode_image(
|
573 |
x, DEVICE, 1, output_hidden_state
|
574 |
)
|
575 |
|
576 |
+
print('encoded')
|
577 |
+
|
578 |
+
print('pali_enc')
|
579 |
+
im = torchvision.transforms.ToTensor()(x).to('cuda').unsqueeze(0)
|
580 |
im = torch.nn.functional.interpolate(im, (224, 224))
|
581 |
im = (im - .5) * 2
|
582 |
+
gemb = pali.vision_tower(im.to(dtype)).last_hidden_state.detach().to('cpu').to(torch.float32).mean(1)
|
583 |
+
|
584 |
+
print('pali_enced')
|
585 |
return im_emb.detach().to('cpu').to(torch.float32), gemb
|
586 |
|
587 |
demo.launch(share=True,)
|