Update app.py
Browse files
app.py
CHANGED
@@ -7,12 +7,10 @@ os.environ['CURL_CA_BUNDLE'] = ''
|
|
7 |
|
8 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
9 |
|
10 |
-
config =
|
11 |
-
model =
|
12 |
model.load_state_dict(torch.load("pytorch_model.bin", map_location=device))
|
13 |
-
processor =
|
14 |
-
processor.tokenizer.padding_side = 'left'
|
15 |
-
processor.tokenizer.pad_token_id = processor.tokenizer.eos_token_id
|
16 |
|
17 |
title = "Generate Image Captions With CLIP And GPT2"
|
18 |
|
@@ -28,11 +26,12 @@ def generate_image_captions(image, text):
|
|
28 |
attention_mask=attention_mask,
|
29 |
max_new_tokens=50
|
30 |
)
|
31 |
-
|
|
|
32 |
prediction_text = processor.decode(prediction[0], skip_special_tokens=True)
|
|
|
33 |
return prediction_text
|
34 |
|
35 |
-
|
36 |
article = "This demo is originated from this paper: [original paper](https://arxiv.org/abs/2209.15162)"
|
37 |
description = """
|
38 |
### Expand GPT2's language capabilities to vision with CLIP!
|
|
|
7 |
|
8 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
9 |
|
10 |
+
config = CLIPGPT2Config(image_from_pretrained=False, text_from_pretrained=False)
|
11 |
+
model = CLIPGPT2(config)
|
12 |
model.load_state_dict(torch.load("pytorch_model.bin", map_location=device))
|
13 |
+
processor = CLIPGPT2Processor(config)
|
|
|
|
|
14 |
|
15 |
title = "Generate Image Captions With CLIP And GPT2"
|
16 |
|
|
|
26 |
attention_mask=attention_mask,
|
27 |
max_new_tokens=50
|
28 |
)
|
29 |
+
processor.tokenizer.padding_side = 'left'
|
30 |
+
processor.tokenizer.pad_token_id = processor.tokenizer.eos_token_id
|
31 |
prediction_text = processor.decode(prediction[0], skip_special_tokens=True)
|
32 |
+
|
33 |
return prediction_text
|
34 |
|
|
|
35 |
article = "This demo is originated from this paper: [original paper](https://arxiv.org/abs/2209.15162)"
|
36 |
description = """
|
37 |
### Expand GPT2's language capabilities to vision with CLIP!
|