Update app.py
Browse files
app.py
CHANGED
@@ -8,53 +8,7 @@ model_path = "microsoft/git-base-vqav2"
|
|
8 |
dataset_name = "Multimodal-Fatima/OK-VQA_train"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
10 |
|
11 |
-
|
12 |
-
"What was the machine beside the bowl used for?",
|
13 |
-
"What kind of cars are in the photo?",
|
14 |
-
"What is the hairstyle of the blond called?",
|
15 |
-
"How old do you have to be in canada to do this?",
|
16 |
-
"Can you guess the place where the man is playing?",
|
17 |
-
"What loony tune character is in this photo?",
|
18 |
-
"Whose birthday is being celebrated?",
|
19 |
-
"Where can that toilet seat be bought?",
|
20 |
-
"What do you call the kind of pants that the man on the right is wearing?"]
|
21 |
-
|
22 |
-
processor = AutoProcessor.from_pretrained(model_path)
|
23 |
-
model = AutoModelForVisualQuestionAnswering.from_pretrained(model_path)
|
24 |
-
|
25 |
-
|
26 |
-
def main(select_exemple_num):
|
27 |
-
selectednum = select_exemple_num
|
28 |
-
exemple_img = f"image{selectednum}.jpg"
|
29 |
-
img = Image.open(exemple_img)
|
30 |
-
question = questions[selectednum - 1]
|
31 |
-
|
32 |
-
encoding = processor(img, question, return_tensors='pt')
|
33 |
-
|
34 |
-
outputs = model(**encoding)
|
35 |
-
logits = outputs.logits
|
36 |
-
|
37 |
-
# ---
|
38 |
-
output_str = 'pridicted : \n'
|
39 |
-
predicted_classes = torch.sigmoid(logits)
|
40 |
-
|
41 |
-
probs, classes = torch.topk(predicted_classes, 5)
|
42 |
-
ans = ''
|
43 |
-
|
44 |
-
for prob, class_idx in zip(probs.squeeze().tolist(), classes.squeeze().tolist()):
|
45 |
-
print(prob, model.config.id2label[class_idx])
|
46 |
-
output_str += str(prob)
|
47 |
-
output_str += " "
|
48 |
-
output_str += model.config.id2label[class_idx]
|
49 |
-
output_str += "\n"
|
50 |
-
if not ans:
|
51 |
-
ans = model.config.id2label[class_idx]
|
52 |
-
|
53 |
-
print(ans)
|
54 |
-
# ---
|
55 |
-
output_str += f"\nso I think it's answer is : \n{ans}"
|
56 |
-
|
57 |
-
return exemple_img, question, output_str
|
58 |
|
59 |
|
60 |
demo = gr.Interface(
|
|
|
8 |
dataset_name = "Multimodal-Fatima/OK-VQA_train"
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
10 |
|
11 |
+
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
demo = gr.Interface(
|