Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
from transformers import
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
|
5 |
-
model =
|
6 |
-
|
7 |
-
tokenizer =
|
8 |
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
model.to(device)
|
@@ -21,11 +21,10 @@ def predict_caption(image_paths):
|
|
21 |
image = image.convert(mode="RGB")
|
22 |
images.append(image)
|
23 |
|
24 |
-
pixel_values = feature_extractor(images=images,
|
25 |
pixel_values = pixel_values.to(device)
|
26 |
|
27 |
output_ids = model.generate(pixel_values, **gen_kwargs)
|
28 |
|
29 |
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
30 |
return preds
|
31 |
-
|
|
|
1 |
+
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
|
5 |
+
model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
6 |
+
feature_extractor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
8 |
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
model.to(device)
|
|
|
21 |
image = image.convert(mode="RGB")
|
22 |
images.append(image)
|
23 |
|
24 |
+
pixel_values = feature_extractor(images=images, return_tensors="pt").pixel_values
|
25 |
pixel_values = pixel_values.to(device)
|
26 |
|
27 |
output_ids = model.generate(pixel_values, **gen_kwargs)
|
28 |
|
29 |
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
30 |
return preds
|
|