luisresende13 commited on
Commit
60f69ac
1 Parent(s): 23ff294

update handler.py

Browse files
Files changed (2) hide show
  1. handler-test.py +20 -0
  2. handler.py +4 -3
handler-test.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pip install -r requirements.txt
2
+
3
+ from handler import EndpointHandler
4
+
5
+ # init handler
6
+ my_handler = EndpointHandler(path=".")
7
+
8
+ # prepare sample payload
9
+ payload = {
10
+ "inputs": {
11
+ "question": "What's in the image?",
12
+ "image": "https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg"
13
+ }
14
+ }
15
+
16
+ # test the handler
17
+ result = my_handler(payload)
18
+
19
+ # show results
20
+ print("result:", result)
handler.py CHANGED
@@ -14,9 +14,10 @@ class EndpointHandler():
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)
 
14
  A :obj:`list` | `dict`: will be serialized and returned
15
  """
16
  # get inputs
17
+ inputs = data.pop("inputs", data)
18
+ top_k = inputs.get("top_k", 10)
19
+ question = inputs.get("question", 'Whats the negative of "You provided a question"?')
20
+ image = inputs.get("image", "https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg")
21
 
22
  # run normal prediction
23
  prediction = self.pipeline(image, question, top_k=10)