Download app.py from T7yrttrd/Spark.4.5.Text.Image.File.Search.Connectors: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/spaces/T7yrttrd/Spark.4.5.Text.Image.File.Search.Connectors/resolve/main/app.py
- Command line
-
hf download hf://spaces/T7yrttrd/Spark.4.5.Text.Image.File.Search.Connectors/app.py
-
curl -L -o app.py https://huggingface.co/spaces/T7yrttrd/Spark.4.5.Text.Image.File.Search.Connectors/resolve/main/app.py
1.52 kB
| import httpx | |
| from fastapi import FastAPI, Request | |
| from fastapi.responses import StreamingResponse | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| from routes_auth import router as auth_router | |
| from service_chat import stream_chat_pipeline | |
| from connector_browser import sync_user_cookies | |
| app = FastAPI(title="Omni 4.8 Connectors API") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| if hasattr(auth_router, "prefix") and not auth_router.prefix: | |
| app.include_router(auth_router, prefix="/auth") | |
| else: | |
| app.include_router(auth_router) | |
| class CookieSyncRequest(BaseModel): | |
| user_id: str | |
| cookies: str | |
| url: str | |
| async def root(): | |
| return {"status": "ok", "service": "Omni 4.8 Backend"} | |
| async def sync_cookies_endpoint(data: CookieSyncRequest): | |
| success = await sync_user_cookies(data.user_id, data.cookies, data.url) | |
| return {"status": "success" if success else "failed", "synced": success} | |
| async def generate_endpoint(request: Request): | |
| body = await request.json() | |
| client = httpx.AsyncClient(timeout=180.0) | |
| async def stream_wrapper(): | |
| try: | |
| async for chunk in stream_chat_pipeline(request, body, client): | |
| yield chunk | |
| finally: | |
| await client.aclose() | |
| return StreamingResponse(stream_wrapper(), media_type="text/event-stream") | |