
'''simple docstring'''






from argparse import ArgumentParser, Namespace
from typing import Any, List, Optional

from ..pipelines import Pipeline, get_supported_tasks, pipeline
from ..utils import logging
from . import BaseTransformersCLICommand


try:
					from fastapi import Body, FastAPI, HTTPException
					from fastapi.routing import APIRoute
					from pydantic import BaseModel
					from starlette.responses import JSONResponse
					from uvicorn import run

					A			      =      True
except (ImportError, AttributeError):
					A			      =      object





					def    UpperCAmelCase							(  *UpperCAmelCase__							:							Any       ,							**UpperCAmelCase__							:							Union[str, Any]):
									pass


					A			      =      False


A			      =      logging.get_logger('transformers-cli/serving')





def    UpperCAmelCase							(  UpperCAmelCase__							:							Namespace):
				lowerCamelCase					:			List[Any]									= pipeline(
				    task=args.task       ,							model=args.model if args.model else None       ,							config=args.config       ,							tokenizer=args.tokenizer       ,							device=args.device       ,							)
				return ServeCommand(UpperCAmelCase__       ,							args.host       ,							args.port       ,							args.workers)




class     __snake_case		(   a__):
					_lowerCAmelCase			     =	42





class     __snake_case		(   a__):
					_lowerCAmelCase			     =	42
					_lowerCAmelCase			     =	42





class     __snake_case		(   a__):
					_lowerCAmelCase			     =	42





class     __snake_case		(   a__):
					_lowerCAmelCase			     =	42





class     __snake_case		(   a__):
					@staticmethod
					def     UpperCAmelCase_							(     A      ):

									"""simple docstring"""


									lowerCamelCase					:			Any									= parser.add_parser(
									    'serve',    help='CLI tool to run inference requests through REST and GraphQL endpoints.'      )
									serve_parser.add_argument(
									    '--task',    type=A,    choices=get_supported_tasks(),    help='The task to run the pipeline on',    )
									serve_parser.add_argument('--host',    type=A,    default='localhost',    help='Interface the server will listen on.'      )
									serve_parser.add_argument('--port',    type=A,    default=8888,    help='Port the serving will listen to.'      )
									serve_parser.add_argument('--workers',    type=A,    default=1,    help='Number of http workers'      )
									serve_parser.add_argument('--model',    type=A,    help='Model\'s name or path to stored model.'      )
									serve_parser.add_argument('--config',    type=A,    help='Model\'s config name or path to stored model.'      )
									serve_parser.add_argument('--tokenizer',    type=A,    help='Tokenizer name to use.'      )
									serve_parser.add_argument(
									    '--device',    type=A,    default=-1,    help='Indicate the device to run onto, -1 indicates CPU, >= 0 indicates GPU (default: -1)',    )
									serve_parser.set_defaults(func=A      )
					def __init__(     self,    A,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= pipeline

									lowerCamelCase					:			int									= host
									lowerCamelCase					:			str									= port
									lowerCamelCase					:			str									= workers

									if not _serve_dependencies_installed:
													raise RuntimeError(
													    'Using serve command requires FastAPI and uvicorn. '
													    'Please install transformers with [serving]: pip install "transformers[serving]".'
													    'Or install FastAPI and uvicorn separately.'      )
									else:
													logger.info(F'''Serving model over {host}:{port}'''      )
													lowerCamelCase					:			List[str]									= FastAPI(
													    routes=[
													        APIRoute(
													            '/',    self.model_info,    response_model=A,    response_class=A,    methods=['GET'],    ),
													        APIRoute(
													            '/tokenize',    self.tokenize,    response_model=A,    response_class=A,    methods=['POST'],    ),
													        APIRoute(
													            '/detokenize',    self.detokenize,    response_model=A,    response_class=A,    methods=['POST'],    ),
													        APIRoute(
													            '/forward',    self.forward,    response_model=A,    response_class=A,    methods=['POST'],    ),
													    ],    timeout=600,    )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									run(self._app,    host=self.host,    port=self.port,    workers=self.workers      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return ServeModelInfoResult(infos=vars(self._pipeline.model.config      )      )
					def     UpperCAmelCase_							(     self,    A = Body(A,    embed=A      ),    A = Body(A,    embed=A      )      ):

									"""simple docstring"""


									try:
													lowerCamelCase					:			int									= self._pipeline.tokenizer.tokenize(A      )

													if return_ids:
																	lowerCamelCase					:			Dict									= self._pipeline.tokenizer.convert_tokens_to_ids(A      )
																	return ServeTokenizeResult(tokens=A,    tokens_ids=A      )
													else:
																	return ServeTokenizeResult(tokens=A      )

									except Exception as e:
													raise HTTPException(status_code=500,    detail={'model': '', 'error': str(A      )}      )
					def     UpperCAmelCase_							(     self,    A = Body(A,    embed=A      ),    A = Body(A,    embed=A      ),    A = Body(A,    embed=A      ),    ):

									"""simple docstring"""


									try:
													lowerCamelCase					:			Optional[Any]									= self._pipeline.tokenizer.decode(A,    A,    A      )
													return ServeDeTokenizeResult(model='',    text=A      )
									except Exception as e:
													raise HTTPException(status_code=500,    detail={'model': '', 'error': str(A      )}      )




					async def     UpperCAmelCase_							(     self,    A=Body(A,    embed=A      )      ):

									"""simple docstring"""


									if len(A      ) == 0:
													return ServeForwardResult(output=[],    attention=[]      )

									try:
													# Forward through the model
													lowerCamelCase					:			Optional[Any]									= self._pipeline(A      )
													return ServeForwardResult(output=A      )
									except Exception as e:
													raise HTTPException(500,    {'error': str(A      )}      )


'''simple docstring'''






def    UpperCAmelCase							(  UpperCAmelCase__							:							int = 10_00):
				lowerCamelCase					:			Optional[Any]									= 2**power
				lowerCamelCase					:			str									= str(UpperCAmelCase__)
				lowerCamelCase					:			Union[str, Any]									= list(UpperCAmelCase__)
				lowerCamelCase					:			Optional[Any]									= 0

				for i in list_num:
								sum_of_num += int(UpperCAmelCase__)

				return sum_of_num


if __name__ == "__main__":
					A			      =      int(input('Enter the power of 2: ').strip())
					print('2 ^ ', power, ' = ', 2**power)
					A			      =      solution(power)
					print('Sum of the digits is: ', result)
