mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 17:13:25 +00:00
feat: text_and_image blockbox
This commit is contained in:
28
src/blackbox/text_and_image.py
Normal file
28
src/blackbox/text_and_image.py
Normal 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)
|
||||
Reference in New Issue
Block a user