panda47 commited on
Commit
d81d39e
β€’
1 Parent(s): a62f8ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoProcessor, AutoModelForCausalLM
2
+ from huggingface_hub import hf_hub_download
3
+ from PIL import Image
4
+
5
+ processor = AutoProcessor.from_pretrained("microsoft/git-base-vqav2")
6
+ model = AutoModelForCausalLM.from_pretrained("microsoft/git-base-vqav2")
7
+
8
+ file_path = hf_hub_download(repo_id="Multimodal-Fatima/OK-VQA_train", filename="data", repo_type="dataset")
9
+ image = Image.open(file_path).convert("RGB")
10
+
11
+ pixel_values = processor(images=image, return_tensors="pt").pixel_values
12
+
13
+ question = "How many people are there?"
14
+
15
+ input_ids = processor(text=question, add_special_tokens=False).input_ids
16
+ input_ids = [processor.tokenizer.cls_token_id] + input_ids
17
+ input_ids = torch.tensor(input_ids).unsqueeze(0)
18
+
19
+ generated_ids = model.generate(pixel_values=pixel_values, input_ids=input_ids, max_length=50)
20
+ print(processor.batch_decode(generated_ids, skip_special_tokens=True))