This commit is contained in:
commit
da316b9c48
|
@ -0,0 +1,10 @@
|
|||
FROM python:3.8.13
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
|
||||
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
CMD ["python", "app.py"]
|
|
@ -0,0 +1,39 @@
|
|||
from transformers import ViltProcessor, ViltForQuestionAnswering
|
||||
from PIL import Image
|
||||
import gradio as gr
|
||||
import torch
|
||||
from gradio.themes.utils import sizes
|
||||
|
||||
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
||||
block_label_text_color = '#4D63FF',
|
||||
block_title_text_color = '#4D63FF',
|
||||
button_primary_text_color = '#4D63FF',
|
||||
button_primary_background_fill='#FFFFFF',
|
||||
button_primary_border_color='#4D63FF',
|
||||
button_primary_background_fill_hover='#EDEFFF',
|
||||
)
|
||||
processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
|
||||
model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
|
||||
|
||||
|
||||
def vqa(image, question):
|
||||
inp = Image.fromarray(image.astype('uint8'), 'RGB')
|
||||
inputs = processor(inp, question, return_tensors="pt")
|
||||
|
||||
outputs = model(**inputs)
|
||||
logits = outputs.logits
|
||||
idx = logits.argmax(-1).item()
|
||||
|
||||
return model.config.id2label[idx]
|
||||
|
||||
|
||||
demo = gr.Interface(fn=vqa,
|
||||
inputs=['image', 'text'],
|
||||
outputs='text',
|
||||
title = "vqa",
|
||||
theme=theme,
|
||||
examples = [['soccer.jpg', 'how many people in the picture?']])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3).launch()
|
|
@ -0,0 +1,4 @@
|
|||
gradio
|
||||
transformers
|
||||
torch
|
||||
Pillow
|
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
Loading…
Reference in New Issue