Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Working AutoTrain solution - bypasses user permission issues | |
| """ | |
| import os | |
| import pwd | |
| import getpass | |
| import sys | |
| # Fix environment variables FIRST | |
| os.environ["OMP_NUM_THREADS"] = "1" | |
| os.environ["MKL_NUM_THREADS"] = "1" | |
| os.environ["NUMEXPR_NUM_THREADS"] = "1" | |
| os.environ["OPENBLAS_NUM_THREADS"] = "1" | |
| os.environ["HF_HOME"] = "/tmp/huggingface_cache" | |
| # Disable authentication checks | |
| os.environ["DISABLE_OAUTH"] = "1" | |
| os.environ["IS_RUNNING_IN_SPACE"] = "false" | |
| print("π§ Environment variables fixed!") | |
| print(f"β OMP_NUM_THREADS = {os.environ.get('OMP_NUM_THREADS')}") | |
| # Create cache and working directories | |
| os.makedirs("/tmp/huggingface_cache", exist_ok=True) | |
| os.makedirs("/tmp/autotrain", exist_ok=True) | |
| # Set working directory for database | |
| os.chdir("/tmp/autotrain") | |
| # Monkey patch the getuser function to fix the permission error | |
| def mock_getuser(): | |
| return "user" | |
| getpass.getuser = mock_getuser | |
| # Also patch pwd.getpwuid for the same issue | |
| original_getpwuid = pwd.getpwuid | |
| def mock_getpwuid(uid): | |
| class MockPwdEntry: | |
| def __init__(self): | |
| self.pw_name = "user" | |
| self.pw_uid = uid | |
| self.pw_gid = uid | |
| self.pw_dir = "/app" | |
| self.pw_shell = "/bin/bash" | |
| def __getitem__(self, index): | |
| if index == 0: | |
| return self.pw_name | |
| elif index == 1: | |
| return "x" # password placeholder | |
| elif index == 2: | |
| return self.pw_uid | |
| elif index == 3: | |
| return self.pw_gid | |
| elif index == 4: | |
| return "User" # gecos | |
| elif index == 5: | |
| return self.pw_dir | |
| elif index == 6: | |
| return self.pw_shell | |
| else: | |
| raise IndexError("list index out of range") | |
| return MockPwdEntry() | |
| pwd.getpwuid = mock_getpwuid | |
| print("π§ User permission patches applied!") | |
| # Patch authentication to bypass login | |
| def mock_user_authentication(): | |
| return { | |
| "username": "user", | |
| "orgs": [], | |
| "token": "fake_token" | |
| } | |
| if __name__ == "__main__": | |
| print("π Starting AutoTrain...") | |
| try: | |
| import uvicorn | |
| from fastapi import FastAPI | |
| from starlette.middleware.sessions import SessionMiddleware | |
| # Import after our patches | |
| import autotrain.app.ui_routes as ui_routes | |
| # Patch the user authentication function | |
| ui_routes.user_authentication = lambda request: mock_user_authentication() | |
| from autotrain.app.ui_routes import ui_router | |
| app = FastAPI(title="AutoTrain Advanced") | |
| # Add session middleware | |
| app.add_middleware(SessionMiddleware, secret_key="autotrain-secret-key") | |
| app.include_router(ui_router) | |
| print("β AutoTrain app created successfully!") | |
| uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| import traceback | |
| traceback.print_exc() |