コード例 #1
0
 def from_cli(self,
              cli_args: Tuple[str]) -> Iterator[InferenceTask[BinaryIO]]:
     for input_ in parse_cli_input(cli_args):
         bio = io.BytesIO(input_.read())
         bio.name = input_.name
         yield InferenceTask(
             context=InferenceContext(cli_args=cli_args),
             data=bio,
         )
コード例 #2
0
 def from_cli(self, cli_args: Tuple[str]) -> Iterator[InferenceTask[str]]:
     for input_ in parse_cli_input(cli_args):
         try:
             yield InferenceTask(
                 cli_args=cli_args,
                 data=input_.read().decode(),  # charset for cli input
             )
         except UnicodeDecodeError:
             yield InferenceTask().discard(
                 http_status=400,
                 err_msg=f"{self.__class__.__name__}: UnicodeDecodeError",
             )
コード例 #3
0
 def from_cli(self, cli_args: Tuple[str]) -> Iterator[InferenceTask[str]]:
     for input_ in parse_cli_input(cli_args):
         try:
             bytes_ = input_.read()
             charset = chardet.detect(bytes_)['encoding'] or "utf-8"
             yield InferenceTask(
                 cli_args=cli_args,
                 data=bytes_.decode(charset),
             )
         except UnicodeDecodeError:
             yield InferenceTask().discard(
                 http_status=400,
                 err_msg=f"{self.__class__.__name__}: "
                 f"Try decoding with {charset} but failed with DecodeError.",
             )
         except LookupError:
             return InferenceTask().discard(
                 http_status=400,
                 err_msg=
                 f"{self.__class__.__name__}: Unsupported charset {charset}",
             )
コード例 #4
0
 def from_cli(self, cli_args: Tuple[str]) -> Iterator[InferenceTask[bytes]]:
     for json_input in parse_cli_input(cli_args):
         yield InferenceTask(cli_args=cli_args, data=json_input.read())
コード例 #5
0
ファイル: file_input.py プロジェクト: leommiranda/BentoML
 def from_cli(self,
              cli_args: Tuple[str]) -> Iterator[InferenceTask[FileLike]]:
     for f in parse_cli_input(cli_args):
         yield InferenceTask(cli_args=cli_args, data=f)