jree423 commited on
Commit
3885d88
·
verified ·
1 Parent(s): 5810d73

Upload handler.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. handler.py +16 -17
handler.py CHANGED
@@ -7,11 +7,24 @@ import numpy as np
7
  import torch
8
  import json
9
 
10
- class VectorGraphicsHandler:
11
- def __init__(self):
12
  self.initialized = False
 
13
 
14
- def initialize(self, context):
 
 
 
 
 
 
 
 
 
 
 
 
15
  """Initialize the handler."""
16
  self.initialized = True
17
 
@@ -70,17 +83,3 @@ class VectorGraphicsHandler:
70
  def postprocess(self, inference_output):
71
  """Return the output as JSON."""
72
  return inference_output
73
-
74
- _service = VectorGraphicsHandler()
75
-
76
- def handle(data, context):
77
- """Handle a request to the model."""
78
- if not _service.initialized:
79
- _service.initialize(context)
80
-
81
- if data is None:
82
- return None
83
-
84
- inputs = _service.preprocess(data)
85
- outputs = _service.inference(inputs)
86
- return _service.postprocess(outputs)
 
7
  import torch
8
  import json
9
 
10
+ class EndpointHandler:
11
+ def __init__(self, path=""):
12
  self.initialized = False
13
+ self.path = path
14
 
15
+ def __call__(self, data):
16
+ """Handle a request to the model."""
17
+ if not self.initialized:
18
+ self.initialize()
19
+
20
+ if data is None:
21
+ return None
22
+
23
+ inputs = self.preprocess(data)
24
+ outputs = self.inference(inputs)
25
+ return self.postprocess(outputs)
26
+
27
+ def initialize(self):
28
  """Initialize the handler."""
29
  self.initialized = True
30
 
 
83
  def postprocess(self, inference_output):
84
  """Return the output as JSON."""
85
  return inference_output