Spaces:
Running
Running
File size: 1,013 Bytes
422c1f3 ede3ebe dc16985 422c1f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# app.py - Main entry point for Hugging Face Spaces
import os
import sys
import importlib.util
# Load the FastAPI app from code/app.py via importlib to avoid
# conflicts with the standard-library module named `code`.
HERE = os.path.dirname(__file__)
CODE_DIR = os.path.join(HERE, "code")
app_path = os.path.join(CODE_DIR, "app.py")
# Ensure the `code/` directory is on sys.path so relative imports like
# `from model import ...` inside `code/app.py` resolve correctly.
if CODE_DIR not in sys.path:
sys.path.insert(0, CODE_DIR)
spec = importlib.util.spec_from_file_location("antique_auth_code_app", app_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
# Keep CODE_DIR on sys.path so request-time imports inside `code/app.py`
# (e.g. `from web_scraper_allegro import ...`) continue to work.
# The FastAPI `app` object expected inside code/app.py
app = getattr(module, "app")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)
|