wynnwatson commited on
Commit
dc8f3c2
·
verified ·
1 Parent(s): 485a5de

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +40 -0
  2. README.md +25 -11
  3. app.py +93 -0
  4. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # Fix the environment variable issue at the container level
4
+ ENV OMP_NUM_THREADS=1
5
+ ENV MKL_NUM_THREADS=1
6
+ ENV NUMEXPR_NUM_THREADS=1
7
+ ENV OPENBLAS_NUM_THREADS=1
8
+ ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
9
+ ENV HF_HOME=/tmp/huggingface_cache
10
+
11
+ # Create user to fix the getpwuid error
12
+ RUN useradd --create-home --uid 1000 --shell /bin/bash user
13
+
14
+ # Install system dependencies
15
+ RUN apt-get update && apt-get install -y \
16
+ git \
17
+ && rm -rf /var/lib/apt/lists/*
18
+
19
+ # Set working directory
20
+ WORKDIR /app
21
+
22
+ # Copy requirements and install Python dependencies
23
+ COPY requirements.txt .
24
+ RUN pip install --no-cache-dir -r requirements.txt
25
+
26
+ # Copy application code
27
+ COPY . .
28
+
29
+ # Create cache directories and set permissions
30
+ RUN mkdir -p /tmp/transformers_cache /tmp/huggingface_cache && \
31
+ chown -R user:user /app /tmp/transformers_cache /tmp/huggingface_cache
32
+
33
+ # Switch to user
34
+ USER user
35
+
36
+ # Expose port
37
+ EXPOSE 7860
38
+
39
+ # Run the application
40
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -1,11 +1,25 @@
1
- ---
2
- title: Autotrain Fixed
3
- emoji: 👁
4
- colorFrom: yellow
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
8
- license: apache-2.0
9
- ---
10
-
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: AutoTrain Advanced
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ license: apache-2.0
9
+ duplicated_from: huggingface/autotrain-advanced
10
+ ---
11
+
12
+ # AutoTrain Advanced
13
+
14
+ This is a custom AutoTrain Advanced setup with fixes for:
15
+ - OMP_NUM_THREADS environment variable issues
16
+ - User permission problems
17
+ - Container compatibility
18
+
19
+ ## Usage
20
+
21
+ This Space provides the AutoTrain Advanced interface for training models on Hugging Face.
22
+
23
+ ## Authentication
24
+
25
+ This Space uses Hugging Face OAuth for authentication. Make sure you're logged into Hugging Face to access the interface.
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Working AutoTrain solution - bypasses user permission issues
4
+ """
5
+
6
+ import os
7
+ import pwd
8
+ import getpass
9
+ import sys
10
+
11
+ # Fix environment variables FIRST
12
+ os.environ["OMP_NUM_THREADS"] = "1"
13
+ os.environ["MKL_NUM_THREADS"] = "1"
14
+ os.environ["NUMEXPR_NUM_THREADS"] = "1"
15
+ os.environ["OPENBLAS_NUM_THREADS"] = "1"
16
+ os.environ["HF_HOME"] = "/tmp/huggingface_cache"
17
+
18
+ print("🔧 Environment variables fixed!")
19
+ print(f"✅ OMP_NUM_THREADS = {os.environ.get('OMP_NUM_THREADS')}")
20
+
21
+ # Create cache and working directories
22
+ os.makedirs("/tmp/huggingface_cache", exist_ok=True)
23
+ os.makedirs("/tmp/autotrain", exist_ok=True)
24
+
25
+ # Set working directory for database
26
+ os.chdir("/tmp/autotrain")
27
+
28
+ # Monkey patch the getuser function to fix the permission error
29
+ def mock_getuser():
30
+ return "user"
31
+
32
+ getpass.getuser = mock_getuser
33
+
34
+ # Also patch pwd.getpwuid for the same issue
35
+ original_getpwuid = pwd.getpwuid
36
+ def mock_getpwuid(uid):
37
+ class MockPwdEntry:
38
+ def __init__(self):
39
+ self.pw_name = "user"
40
+ self.pw_uid = uid
41
+ self.pw_gid = uid
42
+ self.pw_dir = "/app"
43
+ self.pw_shell = "/bin/bash"
44
+
45
+ def __getitem__(self, index):
46
+ if index == 0:
47
+ return self.pw_name
48
+ elif index == 1:
49
+ return "x" # password placeholder
50
+ elif index == 2:
51
+ return self.pw_uid
52
+ elif index == 3:
53
+ return self.pw_gid
54
+ elif index == 4:
55
+ return "User" # gecos
56
+ elif index == 5:
57
+ return self.pw_dir
58
+ elif index == 6:
59
+ return self.pw_shell
60
+ else:
61
+ raise IndexError("list index out of range")
62
+
63
+ return MockPwdEntry()
64
+
65
+ pwd.getpwuid = mock_getpwuid
66
+
67
+ print("🔧 User permission patches applied!")
68
+
69
+ if __name__ == "__main__":
70
+ print("🚀 Starting AutoTrain...")
71
+
72
+ try:
73
+ import uvicorn
74
+ from fastapi import FastAPI
75
+ from starlette.middleware.sessions import SessionMiddleware
76
+
77
+ # Import after our patches
78
+ from autotrain.app.ui_routes import ui_router
79
+
80
+ app = FastAPI(title="AutoTrain Advanced")
81
+
82
+ # Add session middleware
83
+ app.add_middleware(SessionMiddleware, secret_key="autotrain-secret-key")
84
+
85
+ app.include_router(ui_router)
86
+
87
+ print("✅ AutoTrain app created successfully!")
88
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
89
+
90
+ except Exception as e:
91
+ print(f"❌ Error: {e}")
92
+ import traceback
93
+ traceback.print_exc()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ autotrain-advanced>=0.8.36
2
+ torch>=2.0.0
3
+ transformers>=4.30.0
4
+ accelerate>=0.20.0
5
+ datasets>=2.10.0
6
+ huggingface_hub>=0.15.0