| from fastapi import FastAPI, UploadFile, File, Form | |
| from typing import List | |
| from image_search import search | |
| app = FastAPI() | |
| async def search_endpoint( | |
| prompt: str = Form(...), | |
| images: List[UploadFile] = File(...) | |
| ): | |
| # read files into memory | |
| img_bytes = [await f.read() for f in images] | |
| out_imgs = search(prompt, img_bytes) | |
| # FastAPI can return a list of dicts with bytes; you’ll JSON‑encode base64 | |
| # to keep things simple for Django: | |
| import base64, json | |
| b64_list = [base64.b64encode(b).decode() for b in out_imgs] | |
| return {"images": b64_list} | |