Spaces:
No application file
No application file
Download server.py from aniketkumar1106/ORBITT: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/aniketkumar1106/ORBITT/resolve/main/server.py
- Command line
-
hf download hf://spaces/aniketkumar1106/ORBITT/server.py
-
curl -L -o server.py https://huggingface.co/spaces/aniketkumar1106/ORBITT/resolve/main/server.py
1.08 kB
| 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() | |
| 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) | |