Spaces:
Runtime error
Runtime error
Commit
·
f3a61ac
1
Parent(s):
98f3ae6
Revert "Updated UDOP code"
Browse filesThis reverts commit 6dd82f593228df1734a5007b0fd4872976053ab7.
- .gitignore +1 -2
- app.py +18 -14
- packages.txt +0 -1
- requirements.txt +1 -3
.gitignore
CHANGED
@@ -2,5 +2,4 @@ venv
|
|
2 |
venv/
|
3 |
*.ipynb
|
4 |
flagged
|
5 |
-
*.jpg
|
6 |
-
VilT
|
|
|
2 |
venv/
|
3 |
*.ipynb
|
4 |
flagged
|
5 |
+
*.jpg
|
|
app.py
CHANGED
@@ -1,29 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
import torch
|
4 |
|
5 |
torch.hub.download_url_to_file('http://images.cocodataset.org/val2017/000000039769.jpg', 'cats.jpg')
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
model = UdopForConditionalGeneration.from_pretrained(repo_id)
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
return
|
18 |
|
19 |
image = gr.Image(type="pil")
|
20 |
question = gr.Textbox(label="Question")
|
21 |
answer = gr.Textbox(label="Predicted answer")
|
22 |
examples = [["cats.jpg", "How many cats are there?"]]
|
23 |
|
24 |
-
title = "Interactive demo:
|
25 |
-
description = "Gradio Demo for
|
26 |
-
|
27 |
|
28 |
interface = gr.Interface(fn=answer_question,
|
29 |
inputs=[image, question],
|
@@ -31,5 +35,5 @@ interface = gr.Interface(fn=answer_question,
|
|
31 |
examples=examples,
|
32 |
title=title,
|
33 |
description=description,
|
34 |
-
article=
|
35 |
interface.launch(debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import ViltProcessor, ViltForQuestionAnswering
|
3 |
import torch
|
4 |
|
5 |
torch.hub.download_url_to_file('http://images.cocodataset.org/val2017/000000039769.jpg', 'cats.jpg')
|
6 |
|
7 |
+
processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
|
8 |
+
model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
|
|
|
9 |
|
10 |
+
def answer_question(image, text):
|
11 |
+
encoding = processor(image, text, return_tensors="pt")
|
12 |
+
|
13 |
+
# forward pass
|
14 |
+
with torch.no_grad():
|
15 |
+
outputs = model(**encoding)
|
16 |
+
|
17 |
+
logits = outputs.logits
|
18 |
+
idx = logits.argmax(-1).item()
|
19 |
+
predicted_answer = model.config.id2label[idx]
|
20 |
|
21 |
+
return predicted_answer
|
22 |
|
23 |
image = gr.Image(type="pil")
|
24 |
question = gr.Textbox(label="Question")
|
25 |
answer = gr.Textbox(label="Predicted answer")
|
26 |
examples = [["cats.jpg", "How many cats are there?"]]
|
27 |
|
28 |
+
title = "Interactive demo: ViLT"
|
29 |
+
description = "Gradio Demo for ViLT (Vision and Language Transformer), fine-tuned on VQAv2, a model that can answer questions from images. To use it, simply upload your image and type a question and click 'submit', or click one of the examples to load them. Read more at the links below."
|
30 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2102.03334' target='_blank'>ViLT: Vision-and-Language Transformer Without Convolution or Region Supervision</a> | <a href='https://github.com/dandelin/ViLT' target='_blank'>Github Repo</a></p>"
|
31 |
|
32 |
interface = gr.Interface(fn=answer_question,
|
33 |
inputs=[image, question],
|
|
|
35 |
examples=examples,
|
36 |
title=title,
|
37 |
description=description,
|
38 |
+
article=article)
|
39 |
interface.launch(debug=True)
|
packages.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
tesseract-ocr
|
|
|
|
requirements.txt
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
gradio
|
2 |
torch
|
3 |
-
git+https://github.com/huggingface/transformers.git
|
4 |
-
sentencepiece
|
5 |
-
pytesseract
|
|
|
1 |
gradio
|
2 |
torch
|
3 |
+
git+https://github.com/huggingface/transformers.git
|
|
|
|