Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ import urllib.parse
|
|
| 10 |
from datetime import datetime
|
| 11 |
from contextlib import asynccontextmanager
|
| 12 |
from fastapi import FastAPI, Query, Request, UploadFile, File
|
| 13 |
-
from fastapi.responses import JSONResponse
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
| 15 |
from huggingface_hub import hf_hub_download
|
| 16 |
from rank_bm25 import BM25Okapi
|
|
@@ -218,7 +218,8 @@ async def lifespan(app: FastAPI):
|
|
| 218 |
asyncio.create_task(asyncio.to_thread(load_ai_models))
|
| 219 |
yield
|
| 220 |
|
| 221 |
-
app = FastAPI(title="Nebulix Advanced SEO & Visual Engine", lifespan=lifespan)
|
|
|
|
| 222 |
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
|
| 223 |
|
| 224 |
@app.middleware("http")
|
|
@@ -240,13 +241,10 @@ async def rate_limit_middleware(request: Request, call_next):
|
|
| 240 |
|
| 241 |
return await call_next(request)
|
| 242 |
|
| 243 |
-
#
|
| 244 |
-
@app.get("/"
|
| 245 |
-
async def
|
| 246 |
-
|
| 247 |
-
with open("index.html", "r", encoding="utf-8") as f:
|
| 248 |
-
return f.read()
|
| 249 |
-
return "<h1>UI Not Found</h1><p>Please save your frontend code as <b>index.html</b> in the same folder as this main.py file.</p>"
|
| 250 |
|
| 251 |
@app.get("/search")
|
| 252 |
async def pure_search(q: str = Query(...)):
|
|
@@ -285,7 +283,7 @@ async def ai_mode_chat(q: str = Query(...)):
|
|
| 285 |
|
| 286 |
@app.post("/image-search")
|
| 287 |
async def reverse_image_search(file: UploadFile = File(...)):
|
| 288 |
-
if not vision_model:
|
| 289 |
return {"error": "Vision AI Model is still loading."}
|
| 290 |
|
| 291 |
req_id = str(uuid.uuid4())
|
|
|
|
| 10 |
from datetime import datetime
|
| 11 |
from contextlib import asynccontextmanager
|
| 12 |
from fastapi import FastAPI, Query, Request, UploadFile, File
|
| 13 |
+
from fastapi.responses import JSONResponse
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
| 15 |
from huggingface_hub import hf_hub_download
|
| 16 |
from rank_bm25 import BM25Okapi
|
|
|
|
| 218 |
asyncio.create_task(asyncio.to_thread(load_ai_models))
|
| 219 |
yield
|
| 220 |
|
| 221 |
+
app = FastAPI(title="Nebulix Advanced SEO & Visual API Engine", lifespan=lifespan)
|
| 222 |
+
# CORS Enabled for your separate UI
|
| 223 |
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
|
| 224 |
|
| 225 |
@app.middleware("http")
|
|
|
|
| 241 |
|
| 242 |
return await call_next(request)
|
| 243 |
|
| 244 |
+
# Health Check API Endpoint (No HTML)
|
| 245 |
+
@app.get("/")
|
| 246 |
+
async def health_check():
|
| 247 |
+
return {"status": "ok", "message": "Nebulix API Engine is running smoothly."}
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
@app.get("/search")
|
| 250 |
async def pure_search(q: str = Query(...)):
|
|
|
|
| 283 |
|
| 284 |
@app.post("/image-search")
|
| 285 |
async def reverse_image_search(file: UploadFile = File(...)):
|
| 286 |
+
if not vision_model:
|
| 287 |
return {"error": "Vision AI Model is still loading."}
|
| 288 |
|
| 289 |
req_id = str(uuid.uuid4())
|