Spaces:
Runtime error
Runtime error
Download model.py from Akbartus/FastAPIExample: direct link, hf CLI and curl.
- Browser
- Download file 566 Bytes
-
https://huggingface.co/spaces/Akbartus/FastAPIExample/resolve/3078c3c905bcec6c9354051b3059f323e0012284/model.py
- Command line
-
hf download hf://spaces/Akbartus/FastAPIExample@3078c3c905bcec6c9354051b3059f323e0012284/model.py
-
curl -L -o model.py https://huggingface.co/spaces/Akbartus/FastAPIExample/resolve/3078c3c905bcec6c9354051b3059f323e0012284/model.py
566 Bytes
| from transformers import ViltProcessor, ViltForQuestionAnswering | |
| from PIL import Image | |
| # 470MB | |
| processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa") | |
| model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa", cache_dir="new_cache_dir/") | |
| def model_pipeline(text: str, image: Image): | |
| # prepare inputs | |
| encoding = processor(image, text, return_tensors="pt") | |
| # forward pass | |
| outputs = model(**encoding) | |
| logits = outputs.logits | |
| idx = logits.argmax(-1).item() | |
| return model.config.id2label[idx] |