Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File, Form
|
| 2 |
+
from typing import List
|
| 3 |
+
from image_search import search
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
@app.post("/search/")
|
| 8 |
+
async def search_endpoint(
|
| 9 |
+
prompt: str = Form(...),
|
| 10 |
+
images: List[UploadFile] = File(...)
|
| 11 |
+
):
|
| 12 |
+
# read files into memory
|
| 13 |
+
img_bytes = [await f.read() for f in images]
|
| 14 |
+
out_imgs = search(prompt, img_bytes)
|
| 15 |
+
|
| 16 |
+
# FastAPI can return a list of dicts with bytes; you’ll JSON‑encode base64
|
| 17 |
+
# to keep things simple for Django:
|
| 18 |
+
import base64, json
|
| 19 |
+
b64_list = [base64.b64encode(b).decode() for b in out_imgs]
|
| 20 |
+
return {"images": b64_list}
|