#!/usr/bin/env python3 """ AutoTrain solution with complete authentication bypass """ 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 completely os.environ["DISABLE_OAUTH"] = "1" os.environ["IS_RUNNING_IN_SPACE"] = "false" os.environ["AUTOTRAIN_USERNAME"] = "user" os.environ["AUTOTRAIN_TOKEN"] = "fake_token" 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!") if __name__ == "__main__": print(" Starting AutoTrain...") try: import uvicorn from fastapi import FastAPI, Request, Depends from fastapi.responses import HTMLResponse, RedirectResponse from fastapi.staticfiles import StaticFiles from starlette.middleware.sessions import SessionMiddleware # Import and patch autotrain modules BEFORE creating the app import autotrain.app.ui_routes as ui_routes # Completely bypass authentication def mock_user_authentication(request: Request = None): return ("user", []) def mock_get_user_and_orgs(request: Request): return ("user", []) # Patch all authentication functions ui_routes.user_authentication = mock_user_authentication ui_routes.get_user_and_orgs = mock_get_user_and_orgs # Override the load_index function completely def bypass_load_index(request: Request): # Set session data request.session["user"] = "user" request.session["orgs"] = [] # Return the main AutoTrain interface directly return HTMLResponse(content="""
Train state-of-the-art machine learning models with your own data using AutoTrain's automated pipeline.
Start TrainingUpload and manage your datasets for training. Supports various formats including CSV, JSON, and text files.
Manage DatasetsView and manage your training projects, monitor progress, and download trained models.
View ProjectsAutoTrain Advanced - Automated Machine Learning Platform
Running in bypass mode for Hugging Face Spaces