# uvicorn app:app --host 0.0.0.0 --port 7860 --reload import os import sys # Import sys from fastapi import FastAPI from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles # Optional: Import python-multipart to ensure it's loaded try: import python_multipart except ImportError: print("Warning: python-multipart is not installed. File uploads may fail.") from routes import auth, api_keys, proxies, admin # Import admin router # Environment check: Ensure we are running in the correct Conda environment # This helps catch issues where uvicorn might be using a different python interpreter conda_prefix = os.environ.get("CONDA_PREFIX") if conda_prefix: expected_python_path = os.path.join(conda_prefix, "bin", "python") if sys.executable != expected_python_path: print(f"Warning: Python interpreter is not from the expected Conda environment 'airs'.") print(f"Expected: {expected_python_path}") print(f"Actual: {sys.executable}") # Optionally, you could raise an exception here to prevent startup in wrong environment # raise RuntimeError("Incorrect Python environment detected. Please activate 'airs' conda environment.") else: print("Warning: CONDA_PREFIX environment variable not set. Cannot verify Conda environment.") # Initialize FastAPI app app = FastAPI() # Mount static files app.mount("/static", StaticFiles(directory="static"), name="static") # Include routers app.include_router(auth.router, prefix="/api/auth", tags=["auth"]) app.include_router(api_keys.router, prefix="/api/user", tags=["api_keys"]) app.include_router(proxies.router, prefix="/api/proxies", tags=["proxies"]) app.include_router(admin.router, prefix="/api/admin", tags=["admin"]) # Include admin router # Root and HTML routes @app.get("/", response_class=HTMLResponse) async def read_root(): with open("static/index.html", "r") as f: return f.read() @app.get("/login", response_class=HTMLResponse) async def read_login(): with open("static/login.html", "r") as f: return f.read() @app.get("/reset-password", response_class=HTMLResponse) async def read_reset_password(): with open("static/reset-password.html", "r") as f: return f.read() @app.get("/signup", response_class=HTMLResponse) async def read_signup(): with open("static/signup.html", "r") as f: return f.read() @app.get("/admin", response_class=HTMLResponse) async def read_admin(): with open("static/admin.html", "r") as f: return f.read() @app.get("/admin/users", response_class=HTMLResponse) async def read_admin_users(): with open("static/admin/users.html", "r") as f: return f.read() @app.get("/static/components/admin_navbar.html", response_class=HTMLResponse) async def get_admin_navbar(): with open("static/components/admin_navbar.html", "r") as f: return f.read() @app.get("/admin/pictures", response_class=HTMLResponse) async def read_admin_pictures(): with open("static/admin/pictures.html", "r") as f: return f.read()