Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,6 @@ feature_extractor = ViTFeatureExtractor.from_pretrained("nlpconnect/vit-gpt2-ima
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
7 |
|
8 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
model.to(device)
|
14 |
|
15 |
|
@@ -24,14 +20,10 @@ def predict_step(image_paths):
|
|
24 |
i_image = Image.open(image_path)
|
25 |
if i_image.mode != "RGB":
|
26 |
i_image = i_image.convert(mode="RGB")
|
27 |
-
|
28 |
images.append(i_image)
|
29 |
-
|
30 |
pixel_values = feature_extractor(images=images, return_tensors="pt").pixel_values
|
31 |
pixel_values = pixel_values.to(device)
|
32 |
-
|
33 |
output_ids = model.generate(pixel_values, **gen_kwargs)
|
34 |
-
|
35 |
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
36 |
preds = [pred.strip() for pred in preds]
|
37 |
return preds
|
@@ -52,12 +44,16 @@ description= "NLP Image Understanding"
|
|
52 |
title = "NLP Image Understanding"
|
53 |
article = "nlpconnect/vit-gpt2-image-captioning"
|
54 |
|
|
|
|
|
|
|
|
|
55 |
interface = gr.Interface(
|
56 |
fn=predict,
|
57 |
inputs = input,
|
58 |
theme="grass",
|
59 |
outputs=output,
|
60 |
-
examples =
|
61 |
title=title,
|
62 |
description=description,
|
63 |
article = article,
|
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
7 |
|
8 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
|
|
|
|
|
9 |
model.to(device)
|
10 |
|
11 |
|
|
|
20 |
i_image = Image.open(image_path)
|
21 |
if i_image.mode != "RGB":
|
22 |
i_image = i_image.convert(mode="RGB")
|
|
|
23 |
images.append(i_image)
|
|
|
24 |
pixel_values = feature_extractor(images=images, return_tensors="pt").pixel_values
|
25 |
pixel_values = pixel_values.to(device)
|
|
|
26 |
output_ids = model.generate(pixel_values, **gen_kwargs)
|
|
|
27 |
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
28 |
preds = [pred.strip() for pred in preds]
|
29 |
return preds
|
|
|
44 |
title = "NLP Image Understanding"
|
45 |
article = "nlpconnect/vit-gpt2-image-captioning"
|
46 |
|
47 |
+
input = gr.inputs.Image(label="Upload your Image", type = 'pil', optional=True)
|
48 |
+
output = gr.outputs.Textbox(type="auto",label="Captions")
|
49 |
+
examples = [['35-Favorite-Games.jpg']]
|
50 |
+
|
51 |
interface = gr.Interface(
|
52 |
fn=predict,
|
53 |
inputs = input,
|
54 |
theme="grass",
|
55 |
outputs=output,
|
56 |
+
examples = examples,
|
57 |
title=title,
|
58 |
description=description,
|
59 |
article = article,
|