Spaces:
Sleeping
Sleeping
Download server/app.py from infoclassifier/InfoClassifier: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/infoclassifier/InfoClassifier/resolve/main/server/app.py
- Command line
-
hf download hf://spaces/infoclassifier/InfoClassifier/server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/infoclassifier/InfoClassifier/resolve/main/server/app.py
1.51 kB
| """ | |
| server/app.py | |
| ============= | |
| Entry point for multi-mode deployment (uv run server / python -m server.app). | |
| Loads the FastAPI app from the root-level server.py via importlib so the | |
| `server` package name does not shadow the root module, and exposes a | |
| main() function for the [project.scripts] console script entry point. | |
| """ | |
| import importlib.util | |
| import os | |
| import sys | |
| import uvicorn | |
| # Load root server.py by absolute path to avoid circular package import | |
| _root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| _spec = importlib.util.spec_from_file_location( | |
| "_server_root", | |
| os.path.join(_root, "server.py"), | |
| ) | |
| _mod = importlib.util.module_from_spec(_spec) | |
| # Ensure the root is on sys.path so root-level imports inside server.py work | |
| if _root not in sys.path: | |
| sys.path.insert(0, _root) | |
| _spec.loader.exec_module(_mod) | |
| app = _mod.app # re-export for ASGI runners (e.g. uvicorn server.app:app) | |
| def main(host: str = "0.0.0.0", port: int = 8000): | |
| """Console script entry point: uv run server / python -m server.app.""" | |
| host = os.getenv("HOST", host) | |
| port = int(os.getenv("PORT", port)) | |
| log_level = os.getenv("LOG_LEVEL", "info") | |
| uvicorn.run(app, host=host, port=port, log_level=log_level) | |
| if __name__ == "__main__": | |
| import argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--host", default="0.0.0.0") | |
| parser.add_argument("--port", type=int, default=8000) | |
| args = parser.parse_args() | |
| main(host=args.host, port=args.port) | |