コード例 #1
0
ファイル: api_login.py プロジェクト: sngnt/fastapi-base
 def __init__(
         self,
         username: str = Form(...),
         password: str = Form(...),
 ):
     self.username = username
     self.password = password
コード例 #2
0
 def __init__(
         self,
         grant_type: str = Form(None),
         scope: str = Form(""),
         client_id: Optional[str] = Form(None),
         client_secret: Optional[str] = Form(None),
 ):
     self.grant_type = grant_type
     self.scopes = scope.split()
     self.client_id = client_id
     self.client_secret = client_secret
コード例 #3
0
ファイル: auth.py プロジェクト: leplatrem/ctms-api
 def __init__(
         self,
         grant_type: str = Form(
             None, regex="^(client_credentials|refresh_token)$"),
         scope: str = Form(""),
         client_id: Optional[str] = Form(None),
         client_secret: Optional[str] = Form(None),
 ):
     self.grant_type = grant_type
     self.scopes = scope.split()
     self.client_id = client_id
     self.client_secret = client_secret
コード例 #4
0
async def create_token_files(ttl: int = Form(...),
                             links_number: int = Form(...),
                             file: UploadFile = File(...)):
    meta = {'filename': file.filename}
    content = await file.read()
    tokens, used = token_handler.set_bytes(
        content,
        ttl,
        nb_tokens=links_number,
        expires=ttl != 0,
        meta=meta,
    )
    return {
        'tokens': tokens,
        'used': used,
    }
コード例 #5
0
ファイル: auth.py プロジェクト: Butterthon/fastapi_sample
    def __init__(
        self,
        username: str = Form(..., max_length=MAX_LENGTH_USERNAME),
        password: str = Form(..., max_length=MAX_LENGTH_PASSWORD)
    ):
        """ 初期処理

        Args:
            username (str):
                ・ユーザー名
                ・必須パラメータ

            password (str):
                ・パスワード
                ・必須パラメータ
        """
        self.username = username
        self.password = password
コード例 #6
0
ファイル: oauth2.py プロジェクト: thonguyenduc2010/fastapi
 def __init__(
     self,
     grant_type: str = Form(None, regex="password"),
     username: str = Form(...),
     password: str = Form(...),
     scope: str = Form(""),
     client_id: Optional[str] = Form(None),
     client_secret: Optional[str] = Form(None),
 ):
     self.grant_type = grant_type
     self.username = username
     self.password = password
     self.scopes = scope.split()
     self.client_id = client_id
     self.client_secret = client_secret
コード例 #7
0
ファイル: account.py プロジェクト: dnguyenngoc/shop
 def __init__(
         self,
         email: str = Form(...),
         password: str = Form(...),
         re_password: str = Form(...),
         first_name: Optional[str] = Form(None),
         last_name: Optional[str] = Form(None),
         phone: Optional[str] = Form(None),
 ):
     self.email = email
     self.password = password
     self.re_password = re_password
     self.first_name = first_name
     self.last_name = last_name
     self.phone = phone
コード例 #8
0
ファイル: oauth2.py プロジェクト: thonguyenduc2010/fastapi
 def __init__(
     self,
     grant_type: str = Form(..., regex="password"),
     username: str = Form(...),
     password: str = Form(...),
     scope: str = Form(""),
     client_id: Optional[str] = Form(None),
     client_secret: Optional[str] = Form(None),
 ):
     super().__init__(
         grant_type=grant_type,
         username=username,
         password=password,
         scope=scope,
         client_id=client_id,
         client_secret=client_secret,
     )
コード例 #9
0
ファイル: inference.py プロジェクト: NIKZ3/fewshot
async def run_inference(task: Task,
                        background_tasks: BackgroundTasks,
                        id: int = Form(...),
                        file: UploadFile = File(...),
                        user_data: dict = Depends(get_current_user),
                        db: Session = Depends(get_db)):

    username = user_data['username']
    network: Network = await networkRepository.get_network_by_id(db,
                                                                 network_id=id)
    user: User = await userRepository.get_by_username(db, username)

    if network is None:
        raise HTTPException(
            status_code=400,
            detail="The requested model is no longer available!")
    if network.owner_id != user.id and not network.public_access:
        raise HTTPException(status_code=401,
                            detail="User does not have access to this model")
    if network.task != task:
        raise HTTPException(
            status_code=400,
            detail=
            f"You have requested for {task} to be run, but the selected model is for {network.task}!"
        )

    known_classes: List[str] = list(set(network.known_classes.split(",")))
    engine.set_classes(known_classes)

    image = await img_util.decode(file)
    output_image = engine.run(image, task)
    result = await img_util.encode(output_image, file.content_type)

    background_tasks.add_task(img_util.store_file_and_metadata, [file],
                              user.id, db)
    return StreamingResponse(io.BytesIO(result.tobytes()),
                             media_type=file.content_type)