@@ -52,13 +52,13 @@ def deserialize(self, stream, content_type):
5252 @property
5353 @abc .abstractmethod
5454 def ACCEPT (self ):
55- """The content type that is expected from the inference endpoint."""
55+ """The content types that are expected from the inference endpoint."""
5656
5757
5858class StringDeserializer (BaseDeserializer ):
5959 """Deserialize data from an inference endpoint into a decoded string."""
6060
61- ACCEPT = "application/json"
61+ ACCEPT = ( "application/json" ,)
6262
6363 def __init__ (self , encoding = "UTF-8" ):
6464 """Initialize the string encoding.
@@ -87,7 +87,7 @@ def deserialize(self, stream, content_type):
8787class BytesDeserializer (BaseDeserializer ):
8888 """Deserialize a stream of bytes into a bytes object."""
8989
90- ACCEPT = "*/*"
90+ ACCEPT = ( "*/*" ,)
9191
9292 def deserialize (self , stream , content_type ):
9393 """Read a stream of bytes returned from an inference endpoint.
@@ -108,7 +108,7 @@ def deserialize(self, stream, content_type):
108108class CSVDeserializer (BaseDeserializer ):
109109 """Deserialize a stream of bytes into a list of lists."""
110110
111- ACCEPT = "text/csv"
111+ ACCEPT = ( "text/csv" ,)
112112
113113 def __init__ (self , encoding = "utf-8" ):
114114 """Initialize the string encoding.
@@ -143,7 +143,7 @@ class StreamDeserializer(BaseDeserializer):
143143 reading it.
144144 """
145145
146- ACCEPT = "*/*"
146+ ACCEPT = ( "*/*" ,)
147147
148148 def deserialize (self , stream , content_type ):
149149 """Returns a stream of the response body and the MIME type of the data.
@@ -161,16 +161,17 @@ def deserialize(self, stream, content_type):
161161class NumpyDeserializer (BaseDeserializer ):
162162 """Deserialize a stream of data in the .npy format."""
163163
164- ACCEPT = "application/x-npy"
165-
166- def __init__ (self , dtype = None , allow_pickle = True ):
164+ def __init__ (self , dtype = None , accept = "application/x-npy" , allow_pickle = True ):
167165 """Initialize the dtype and allow_pickle arguments.
168166
169167 Args:
170168 dtype (str): The dtype of the data (default: None).
169+ accept (str): The MIME type that is expected from the inference
170+ endpoint (default: "application/x-npy").
171171 allow_pickle (bool): Allow loading pickled object arrays (default: True).
172172 """
173173 self .dtype = dtype
174+ self .accept = accept
174175 self .allow_pickle = allow_pickle
175176
176177 def deserialize (self , stream , content_type ):
@@ -197,11 +198,21 @@ def deserialize(self, stream, content_type):
197198
198199 raise ValueError ("%s cannot read content type %s." % (__class__ .__name__ , content_type ))
199200
201+ @property
202+ def ACCEPT (self ):
203+ """The content types that are expected from the inference endpoint.
204+
205+ To maintain backwards compatability with legacy images, the
206+ NumpyDeserializer supports sending only one content type in the Accept
207+ header.
208+ """
209+ return (self .accept ,)
210+
200211
201212class JSONDeserializer (BaseDeserializer ):
202213 """Deserialize JSON data from an inference endpoint into a Python object."""
203214
204- ACCEPT = "application/json"
215+ ACCEPT = ( "application/json" ,)
205216
206217 def deserialize (self , stream , content_type ):
207218 """Deserialize JSON data from an inference endpoint into a Python object.
@@ -222,7 +233,7 @@ def deserialize(self, stream, content_type):
222233class PandasDeserializer (BaseDeserializer ):
223234 """Deserialize CSV or JSON data from an inference endpoint into a pandas dataframe."""
224235
225- ACCEPT = "text/csv"
236+ ACCEPT = ( "text/csv" , "application/json" )
226237
227238 def deserialize (self , stream , content_type ):
228239 """Deserialize CSV or JSON data from an inference endpoint into a pandas
@@ -250,7 +261,7 @@ def deserialize(self, stream, content_type):
250261class JSONLinesDeserializer (BaseDeserializer ):
251262 """Deserialize JSON lines data from an inference endpoint."""
252263
253- ACCEPT = "application/jsonlines"
264+ ACCEPT = ( "application/jsonlines" ,)
254265
255266 def deserialize (self , stream , content_type ):
256267 """Deserialize JSON lines data from an inference endpoint.
0 commit comments