File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
src/huggingface_inference_toolkit Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 1+ from huggingface_inference_toolkit .const import HF_TASK
12from huggingface_inference_toolkit .serialization .audio_utils import Audioer
23from huggingface_inference_toolkit .serialization .image_utils import Imager
34from huggingface_inference_toolkit .serialization .json_utils import Jsoner
3839
3940class ContentType :
4041 @staticmethod
41- def get_deserializer (content_type : str ):
42+ def get_deserializer (content_type : str , task : str ):
43+ if content_type .lower ().startswith ("application/octet-stream" ):
44+ if "audio" in task or "speech" in task :
45+ return Audioer
46+ elif "image" in task :
47+ return Imager
48+
4249 # Extract media type from content type
4350 extracted = content_type .split (";" )[0 ]
4451 if extracted in content_type_mapping :
Original file line number Diff line number Diff line change @@ -89,10 +89,11 @@ async def metrics(request):
8989async def predict (request ):
9090 global INFERENCE_HANDLERS
9191 try :
92+ task = request .path_params .get ("task" , HF_TASK )
9293 # extracts content from request
9394 content_type = request .headers .get ("content-Type" , os .environ .get ("DEFAULT_CONTENT_TYPE" )).lower ()
9495 # try to deserialize payload
95- deserialized_body = ContentType .get_deserializer (content_type ).deserialize (
96+ deserialized_body = ContentType .get_deserializer (content_type , task ).deserialize (
9697 await request .body ()
9798 )
9899 # checks if input schema is correct
@@ -108,7 +109,7 @@ async def predict(request):
108109 )
109110
110111 # We lazily load pipelines for alt tasks
111- task = request . path_params . get ( "task" , HF_TASK )
112+
112113 if task == "feature-extraction" and HF_TASK in [
113114 "sentence-similarity" ,
114115 "sentence-embeddings" ,
You can’t perform that action at this time.
0 commit comments