luisresende13
commited on
Commit
•
23ff294
1
Parent(s):
39cf666
update handler.py
Browse files- handler.py +23 -0
handler.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
class EndpointHandler():
|
5 |
+
def __init__(self, path=""):
|
6 |
+
self.pipeline = pipeline("visual-question-answering", model=path)
|
7 |
+
|
8 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
9 |
+
"""
|
10 |
+
data args:
|
11 |
+
inputs (:obj: `str`)
|
12 |
+
date (:obj: `str`)
|
13 |
+
Return:
|
14 |
+
A :obj:`list` | `dict`: will be serialized and returned
|
15 |
+
"""
|
16 |
+
# get inputs
|
17 |
+
image = "https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg"
|
18 |
+
question = data.pop("question", data)
|
19 |
+
# inputs = data.pop("inputs", data)
|
20 |
+
|
21 |
+
# run normal prediction
|
22 |
+
prediction = self.pipeline(image, question, top_k=10)
|
23 |
+
return prediction
|