feat: text_and_image blockbox

This commit is contained in:
superobk
2024-04-25 14:57:08 +08:00
parent 21d159de9b
commit 201d0f374c
3 changed files with 38 additions and 3 deletions

View File

@ -0,0 +1,28 @@
from typing import Any, Coroutine
from fastapi import Request, Response, status
from fastapi.responses import JSONResponse
from .blackbox import Blackbox
class TextAndImage(Blackbox):
def __call__(self, *args, **kwargs):
return self.processing(*args, **kwargs)
def processing(self, text: str, image: bytes):
# TODO: implement the processing logic
return "text and image processing..."
def valid(self, *args, **kwargs) -> bool:
return True
async def fast_api_handler(self, request: Request) -> Response:
# If the request is a form data, you can use the following code
data = (await request.form()).get("image")
if data is None:
return JSONResponse(content={"error": "image is required"}, status_code=status.HTTP_400_BAD_REQUEST)
imageBytes = await data.read()
text = (await request.form()).get("text")
result = self.processing(text, imageBytes)
return JSONResponse(content={"result": result }, status_code=status.HTTP_200_OK)