from fastapi import FastAPI, File, UploadFile, Form from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles from orbiitt_engine import OrbiittEngine import shutil import os app = FastAPI() app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]) # Mount your specific folder app.mount("/Productimages", StaticFiles(directory="Productimages"), name="Productimages") engine = OrbiittEngine() @app.post("/search") async def search_endpoint(text: str = Form(None), weight: float = Form(0.5), file: UploadFile = File(None)): temp_path = None if file: temp_path = f"temp_{file.filename}" with open(temp_path, "wb") as buffer: shutil.copyfileobj(file.file, buffer) results = engine.search(text_query=text, image_file=temp_path, text_weight=weight) if temp_path and os.path.exists(temp_path): os.remove(temp_path) return {"results": results} if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)