Download web_server.py from cursorpro/upd: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/cursorpro/upd/resolve/main/web_server.py
- Command line
-
hf download hf://spaces/cursorpro/upd/web_server.py
-
curl -L -o web_server.py https://huggingface.co/spaces/cursorpro/upd/resolve/main/web_server.py
1.26 kB
| from fastapi import FastAPI, Request | |
| from fastapi.templating import Jinja2Templates | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import HTMLResponse | |
| import uvicorn | |
| from proxy_manager import ProxyManager | |
| from updater import ProxyUpdater | |
| import logging | |
| app = FastAPI() | |
| templates = Jinja2Templates(directory="templates") | |
| # These will be injected from main.py | |
| proxy_manager: ProxyManager = None | |
| updater: ProxyUpdater = None | |
| def init_app(pm: ProxyManager, up: ProxyUpdater): | |
| global proxy_manager, updater | |
| proxy_manager = pm | |
| updater = up | |
| async def read_root(request: Request): | |
| return templates.TemplateResponse("index.html", {"request": request}) | |
| async def get_status(): | |
| if not proxy_manager: | |
| return {"best_proxy": None, "total_available": 0} | |
| best = proxy_manager.best_proxy.to_dict() if proxy_manager.best_proxy else None | |
| return { | |
| "best_proxy": best, | |
| "total_available": len(proxy_manager.proxies) | |
| } | |
| async def get_proxies(): | |
| if not proxy_manager: | |
| return {"proxies": []} | |
| # Return top 50 proxies | |
| return {"proxies": [p.to_dict() for p in proxy_manager.proxies[:50]]} | |