mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 00:53:25 +00:00
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from typing import Any, Coroutine
|
|
|
|
from fastapi import Request, Response, status
|
|
from fastapi.responses import JSONResponse
|
|
from .blackbox import Blackbox
|
|
|
|
from injector import singleton
|
|
@singleton
|
|
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) |