Download backend/run.py from arvind112/vision_ai: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/spaces/arvind112/vision_ai/resolve/main/backend/run.py
- Command line
-
hf download hf://spaces/arvind112/vision_ai/backend/run.py
-
curl -L -o run.py https://huggingface.co/spaces/arvind112/vision_ai/resolve/main/backend/run.py
1.52 kB
| """Run the API + the built web app on ONE port: python run.py (from the backend/ directory). | |
| http://127.0.0.1:8000 web app (served from ../frontend/dist; run `npm run build` after UI changes) | |
| http://127.0.0.1:8000/docs API docs | |
| http://127.0.0.1:8000/api/… API | |
| `npm run dev` (port 5173) is only needed while editing the frontend; it forwards /api to port 8000. | |
| Another port: PORT=8010 venv/bin/python run.py | |
| """ | |
| import os | |
| import socket | |
| import sys | |
| import uvicorn | |
| HOST = os.getenv("HOST", "127.0.0.1") | |
| PORT = int(os.getenv("PORT", "8000")) | |
| def port_free(host: str, port: int) -> bool: | |
| """True if nothing is listening on host:port (another app there would answer the web page's /api calls).""" | |
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
| s.settimeout(0.5) | |
| return s.connect_ex((host if host not in ("0.0.0.0", "") else "127.0.0.1", port)) != 0 | |
| if __name__ == "__main__": | |
| if not port_free(HOST, PORT): | |
| print(f"\n Port {PORT} is already used by another program, so Vision AI can't start there.\n" | |
| f" Find it: lsof -iTCP:{PORT} -sTCP:LISTEN\n" | |
| f" Stop it (kill <PID> or Ctrl+C in its terminal), or start Vision AI on another port:\n" | |
| f" PORT=8010 venv/bin/python run.py\n", file=sys.stderr) | |
| sys.exit(1) | |
| print(f"\n Vision AI → open http://{HOST}:{PORT} (API docs: http://{HOST}:{PORT}/docs)\n") | |
| uvicorn.run("app.main:app", host=HOST, port=PORT, reload=True) | |