Spaces:
Runtime error
Runtime error
Commit
•
52ccae8
1
Parent(s):
308a342
Update app.py
Browse files
app.py
CHANGED
@@ -26,19 +26,20 @@ def predict(image, max_length=64, num_beams=4):
|
|
26 |
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
27 |
pred = post_process(preds[0])
|
28 |
return pred
|
29 |
-
|
|
|
30 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
31 |
# Load model.
|
32 |
model = VisionEncoderDecoderModel.from_pretrained(model_name_or_path)
|
33 |
model.to(device)
|
34 |
print("Loaded model")
|
35 |
-
feature_extractor = AutoFeatureExtractor.from_pretrained(
|
36 |
print("Loaded feature_extractor")
|
37 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
38 |
if model.decoder.name_or_path == "gpt2":
|
39 |
-
tokenizer.pad_token = tokenizer.
|
40 |
print("Loaded tokenizer")
|
41 |
-
title = "
|
42 |
description = ""
|
43 |
input = gr.inputs.Image(type="pil")
|
44 |
example_images = sorted([f.as_posix() for f in Path("examples").glob("*.jpg")])
|
|
|
26 |
preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
27 |
pred = post_process(preds[0])
|
28 |
return pred
|
29 |
+
|
30 |
+
model_path = "team-indain-image-caption/hindi-image-captioning"
|
31 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
32 |
# Load model.
|
33 |
model = VisionEncoderDecoderModel.from_pretrained(model_name_or_path)
|
34 |
model.to(device)
|
35 |
print("Loaded model")
|
36 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_path)
|
37 |
print("Loaded feature_extractor")
|
38 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
39 |
if model.decoder.name_or_path == "gpt2":
|
40 |
+
tokenizer.pad_token = tokenizer.bos_token
|
41 |
print("Loaded tokenizer")
|
42 |
+
title = "Hindi Image Captioning"
|
43 |
description = ""
|
44 |
input = gr.inputs.Image(type="pil")
|
45 |
example_images = sorted([f.as_posix() for f in Path("examples").glob("*.jpg")])
|