seed-image-ai commited on
Commit
55df0ce
·
verified ·
1 Parent(s): c3e21cd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
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}