Wynn Watson commited on
Commit
52c45d8
Β·
1 Parent(s): 9243c99

Fix AutoTrain errors: handle _TemplateResponse issue and add missing logo.png

Browse files
Files changed (5) hide show
  1. app.py +46 -17
  2. app.py.backup +110 -0
  3. app.py.old +135 -0
  4. app.py.original +110 -0
  5. static/logo.png +0 -0
app.py CHANGED
@@ -1,6 +1,7 @@
1
  #!/usr/bin/env python3
2
  """
3
  Working AutoTrain solution - bypasses user permission issues
 
4
  """
5
 
6
  import os
@@ -19,7 +20,7 @@ os.environ["HF_HOME"] = "/tmp/huggingface_cache"
19
  os.environ["DISABLE_OAUTH"] = "1"
20
  os.environ["IS_RUNNING_IN_SPACE"] = "false"
21
 
22
- print("πŸ”§ Environment variables fixed!")
23
  print(f"βœ… OMP_NUM_THREADS = {os.environ.get('OMP_NUM_THREADS')}")
24
 
25
  # Create cache and working directories
@@ -68,29 +69,54 @@ def mock_getpwuid(uid):
68
 
69
  pwd.getpwuid = mock_getpwuid
70
 
71
- print("πŸ”§ User permission patches applied!")
72
-
73
- # Patch authentication to bypass login
74
- def mock_user_authentication():
75
- return {
76
- "username": "user",
77
- "orgs": [],
78
- "token": "fake_token"
79
- }
80
 
81
  if __name__ == "__main__":
82
- print("πŸš€ Starting AutoTrain...")
83
 
84
  try:
85
  import uvicorn
86
- from fastapi import FastAPI
 
 
87
  from starlette.middleware.sessions import SessionMiddleware
88
-
89
- # Import after our patches
90
  import autotrain.app.ui_routes as ui_routes
91
 
92
- # Patch the user authentication function
93
- ui_routes.user_authentication = lambda request: mock_user_authentication()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  from autotrain.app.ui_routes import ui_router
96
 
@@ -99,6 +125,9 @@ if __name__ == "__main__":
99
  # Add session middleware
100
  app.add_middleware(SessionMiddleware, secret_key="autotrain-secret-key")
101
 
 
 
 
102
  app.include_router(ui_router)
103
 
104
  print("βœ… AutoTrain app created successfully!")
@@ -107,4 +136,4 @@ if __name__ == "__main__":
107
  except Exception as e:
108
  print(f"❌ Error: {e}")
109
  import traceback
110
- traceback.print_exc()
 
1
  #!/usr/bin/env python3
2
  """
3
  Working AutoTrain solution - bypasses user permission issues
4
+ Fixed version to handle _TemplateResponse error and static files
5
  """
6
 
7
  import os
 
20
  os.environ["DISABLE_OAUTH"] = "1"
21
  os.environ["IS_RUNNING_IN_SPACE"] = "false"
22
 
23
+ print("οΏ½οΏ½οΏ½ Environment variables fixed!")
24
  print(f"βœ… OMP_NUM_THREADS = {os.environ.get('OMP_NUM_THREADS')}")
25
 
26
  # Create cache and working directories
 
69
 
70
  pwd.getpwuid = mock_getpwuid
71
 
72
+ print("οΏ½οΏ½οΏ½ User permission patches applied!")
 
 
 
 
 
 
 
 
73
 
74
  if __name__ == "__main__":
75
+ print("οΏ½οΏ½οΏ½ Starting AutoTrain...")
76
 
77
  try:
78
  import uvicorn
79
+ from fastapi import FastAPI, Request
80
+ from fastapi.responses import HTMLResponse
81
+ from fastapi.staticfiles import StaticFiles
82
  from starlette.middleware.sessions import SessionMiddleware
83
+ from starlette.templating import Jinja2Templates
 
84
  import autotrain.app.ui_routes as ui_routes
85
 
86
+ # Create a mock user authentication that returns the right format
87
+ def mock_user_authentication(request: Request = None):
88
+ # Return a tuple or list that has len() method
89
+ return ("user", []) # (username, orgs)
90
+
91
+ # Patch the authentication function before importing ui_router
92
+ ui_routes.user_authentication = mock_user_authentication
93
+
94
+ # Also patch the load_index function to handle the authentication properly
95
+ original_load_index = ui_routes.load_index
96
+
97
+ def patched_load_index(request: Request):
98
+ try:
99
+ # Set a mock user in the request session
100
+ request.session["user"] = "user"
101
+ request.session["orgs"] = []
102
+
103
+ # Call the original function
104
+ return original_load_index(request)
105
+ except Exception as e:
106
+ print(f"ERROR in load_index: {e}")
107
+ # Return a simple HTML response if there's an error
108
+ return HTMLResponse(content="""
109
+ <html>
110
+ <head><title>AutoTrain Advanced</title></head>
111
+ <body>
112
+ <h1>AutoTrain Advanced</h1>
113
+ <p>Welcome to AutoTrain! The application is starting up...</p>
114
+ <p>If you see this message, the server is running but there may be authentication issues.</p>
115
+ </body>
116
+ </html>
117
+ """)
118
+
119
+ ui_routes.load_index = patched_load_index
120
 
121
  from autotrain.app.ui_routes import ui_router
122
 
 
125
  # Add session middleware
126
  app.add_middleware(SessionMiddleware, secret_key="autotrain-secret-key")
127
 
128
+ # Mount static files
129
+ app.mount("/static", StaticFiles(directory="static"), name="static")
130
+
131
  app.include_router(ui_router)
132
 
133
  print("βœ… AutoTrain app created successfully!")
 
136
  except Exception as e:
137
  print(f"❌ Error: {e}")
138
  import traceback
139
+ traceback.print_exc()
app.py.backup ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Disable authentication checks
19
+ os.environ["DISABLE_OAUTH"] = "1"
20
+ os.environ["IS_RUNNING_IN_SPACE"] = "false"
21
+
22
+ print("πŸ”§ Environment variables fixed!")
23
+ print(f"βœ… OMP_NUM_THREADS = {os.environ.get('OMP_NUM_THREADS')}")
24
+
25
+ # Create cache and working directories
26
+ os.makedirs("/tmp/huggingface_cache", exist_ok=True)
27
+ os.makedirs("/tmp/autotrain", exist_ok=True)
28
+
29
+ # Set working directory for database
30
+ os.chdir("/tmp/autotrain")
31
+
32
+ # Monkey patch the getuser function to fix the permission error
33
+ def mock_getuser():
34
+ return "user"
35
+
36
+ getpass.getuser = mock_getuser
37
+
38
+ # Also patch pwd.getpwuid for the same issue
39
+ original_getpwuid = pwd.getpwuid
40
+ def mock_getpwuid(uid):
41
+ class MockPwdEntry:
42
+ def __init__(self):
43
+ self.pw_name = "user"
44
+ self.pw_uid = uid
45
+ self.pw_gid = uid
46
+ self.pw_dir = "/app"
47
+ self.pw_shell = "/bin/bash"
48
+
49
+ def __getitem__(self, index):
50
+ if index == 0:
51
+ return self.pw_name
52
+ elif index == 1:
53
+ return "x" # password placeholder
54
+ elif index == 2:
55
+ return self.pw_uid
56
+ elif index == 3:
57
+ return self.pw_gid
58
+ elif index == 4:
59
+ return "User" # gecos
60
+ elif index == 5:
61
+ return self.pw_dir
62
+ elif index == 6:
63
+ return self.pw_shell
64
+ else:
65
+ raise IndexError("list index out of range")
66
+
67
+ return MockPwdEntry()
68
+
69
+ pwd.getpwuid = mock_getpwuid
70
+
71
+ print("πŸ”§ User permission patches applied!")
72
+
73
+ # Patch authentication to bypass login
74
+ def mock_user_authentication():
75
+ return {
76
+ "username": "user",
77
+ "orgs": [],
78
+ "token": "fake_token"
79
+ }
80
+
81
+ if __name__ == "__main__":
82
+ print("πŸš€ Starting AutoTrain...")
83
+
84
+ try:
85
+ import uvicorn
86
+ from fastapi import FastAPI
87
+ from starlette.middleware.sessions import SessionMiddleware
88
+
89
+ # Import after our patches
90
+ import autotrain.app.ui_routes as ui_routes
91
+
92
+ # Patch the user authentication function
93
+ ui_routes.user_authentication = lambda request: mock_user_authentication()
94
+
95
+ from autotrain.app.ui_routes import ui_router
96
+
97
+ app = FastAPI(title="AutoTrain Advanced")
98
+
99
+ # Add session middleware
100
+ app.add_middleware(SessionMiddleware, secret_key="autotrain-secret-key")
101
+
102
+ app.include_router(ui_router)
103
+
104
+ print("βœ… AutoTrain app created successfully!")
105
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
106
+
107
+ except Exception as e:
108
+ print(f"❌ Error: {e}")
109
+ import traceback
110
+ traceback.print_exc()
app.py.old ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Working AutoTrain solution - bypasses user permission issues
4
+ Fixed version to handle _TemplateResponse error
5
+ """
6
+
7
+ import os
8
+ import pwd
9
+ import getpass
10
+ import sys
11
+
12
+ # Fix environment variables FIRST
13
+ os.environ["OMP_NUM_THREADS"] = "1"
14
+ os.environ["MKL_NUM_THREADS"] = "1"
15
+ os.environ["NUMEXPR_NUM_THREADS"] = "1"
16
+ os.environ["OPENBLAS_NUM_THREADS"] = "1"
17
+ os.environ["HF_HOME"] = "/tmp/huggingface_cache"
18
+
19
+ # Disable authentication checks
20
+ os.environ["DISABLE_OAUTH"] = "1"
21
+ os.environ["IS_RUNNING_IN_SPACE"] = "false"
22
+
23
+ print("οΏ½οΏ½οΏ½ Environment variables fixed!")
24
+ print(f"βœ… OMP_NUM_THREADS = {os.environ.get('OMP_NUM_THREADS')}")
25
+
26
+ # Create cache and working directories
27
+ os.makedirs("/tmp/huggingface_cache", exist_ok=True)
28
+ os.makedirs("/tmp/autotrain", exist_ok=True)
29
+
30
+ # Set working directory for database
31
+ os.chdir("/tmp/autotrain")
32
+
33
+ # Monkey patch the getuser function to fix the permission error
34
+ def mock_getuser():
35
+ return "user"
36
+
37
+ getpass.getuser = mock_getuser
38
+
39
+ # Also patch pwd.getpwuid for the same issue
40
+ original_getpwuid = pwd.getpwuid
41
+ def mock_getpwuid(uid):
42
+ class MockPwdEntry:
43
+ def __init__(self):
44
+ self.pw_name = "user"
45
+ self.pw_uid = uid
46
+ self.pw_gid = uid
47
+ self.pw_dir = "/app"
48
+ self.pw_shell = "/bin/bash"
49
+
50
+ def __getitem__(self, index):
51
+ if index == 0:
52
+ return self.pw_name
53
+ elif index == 1:
54
+ return "x" # password placeholder
55
+ elif index == 2:
56
+ return self.pw_uid
57
+ elif index == 3:
58
+ return self.pw_gid
59
+ elif index == 4:
60
+ return "User" # gecos
61
+ elif index == 5:
62
+ return self.pw_dir
63
+ elif index == 6:
64
+ return self.pw_shell
65
+ else:
66
+ raise IndexError("list index out of range")
67
+
68
+ return MockPwdEntry()
69
+
70
+ pwd.getpwuid = mock_getpwuid
71
+
72
+ print("οΏ½οΏ½οΏ½ User permission patches applied!")
73
+
74
+ if __name__ == "__main__":
75
+ print("οΏ½οΏ½οΏ½ Starting AutoTrain...")
76
+
77
+ try:
78
+ import uvicorn
79
+ from fastapi import FastAPI, Request
80
+ from fastapi.responses import HTMLResponse
81
+ from starlette.middleware.sessions import SessionMiddleware
82
+ from starlette.templating import Jinja2Templates
83
+ import autotrain.app.ui_routes as ui_routes
84
+
85
+ # Create a mock user authentication that returns the right format
86
+ def mock_user_authentication(request: Request = None):
87
+ # Return a tuple or list that has len() method
88
+ return ("user", []) # (username, orgs)
89
+
90
+ # Patch the authentication function before importing ui_router
91
+ ui_routes.user_authentication = mock_user_authentication
92
+
93
+ # Also patch the load_index function to handle the authentication properly
94
+ original_load_index = ui_routes.load_index
95
+
96
+ def patched_load_index(request: Request):
97
+ try:
98
+ # Set a mock user in the request session
99
+ request.session["user"] = "user"
100
+ request.session["orgs"] = []
101
+
102
+ # Call the original function
103
+ return original_load_index(request)
104
+ except Exception as e:
105
+ print(f"ERROR in load_index: {e}")
106
+ # Return a simple HTML response if there's an error
107
+ return HTMLResponse(content="""
108
+ <html>
109
+ <head><title>AutoTrain Advanced</title></head>
110
+ <body>
111
+ <h1>AutoTrain Advanced</h1>
112
+ <p>Welcome to AutoTrain! The application is starting up...</p>
113
+ <p>If you see this message, the server is running but there may be authentication issues.</p>
114
+ </body>
115
+ </html>
116
+ """)
117
+
118
+ ui_routes.load_index = patched_load_index
119
+
120
+ from autotrain.app.ui_routes import ui_router
121
+
122
+ app = FastAPI(title="AutoTrain Advanced")
123
+
124
+ # Add session middleware
125
+ app.add_middleware(SessionMiddleware, secret_key="autotrain-secret-key")
126
+
127
+ app.include_router(ui_router)
128
+
129
+ print("βœ… AutoTrain app created successfully!")
130
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
131
+
132
+ except Exception as e:
133
+ print(f"❌ Error: {e}")
134
+ import traceback
135
+ traceback.print_exc()
app.py.original ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Disable authentication checks
19
+ os.environ["DISABLE_OAUTH"] = "1"
20
+ os.environ["IS_RUNNING_IN_SPACE"] = "false"
21
+
22
+ print("πŸ”§ Environment variables fixed!")
23
+ print(f"βœ… OMP_NUM_THREADS = {os.environ.get('OMP_NUM_THREADS')}")
24
+
25
+ # Create cache and working directories
26
+ os.makedirs("/tmp/huggingface_cache", exist_ok=True)
27
+ os.makedirs("/tmp/autotrain", exist_ok=True)
28
+
29
+ # Set working directory for database
30
+ os.chdir("/tmp/autotrain")
31
+
32
+ # Monkey patch the getuser function to fix the permission error
33
+ def mock_getuser():
34
+ return "user"
35
+
36
+ getpass.getuser = mock_getuser
37
+
38
+ # Also patch pwd.getpwuid for the same issue
39
+ original_getpwuid = pwd.getpwuid
40
+ def mock_getpwuid(uid):
41
+ class MockPwdEntry:
42
+ def __init__(self):
43
+ self.pw_name = "user"
44
+ self.pw_uid = uid
45
+ self.pw_gid = uid
46
+ self.pw_dir = "/app"
47
+ self.pw_shell = "/bin/bash"
48
+
49
+ def __getitem__(self, index):
50
+ if index == 0:
51
+ return self.pw_name
52
+ elif index == 1:
53
+ return "x" # password placeholder
54
+ elif index == 2:
55
+ return self.pw_uid
56
+ elif index == 3:
57
+ return self.pw_gid
58
+ elif index == 4:
59
+ return "User" # gecos
60
+ elif index == 5:
61
+ return self.pw_dir
62
+ elif index == 6:
63
+ return self.pw_shell
64
+ else:
65
+ raise IndexError("list index out of range")
66
+
67
+ return MockPwdEntry()
68
+
69
+ pwd.getpwuid = mock_getpwuid
70
+
71
+ print("πŸ”§ User permission patches applied!")
72
+
73
+ # Patch authentication to bypass login
74
+ def mock_user_authentication():
75
+ return {
76
+ "username": "user",
77
+ "orgs": [],
78
+ "token": "fake_token"
79
+ }
80
+
81
+ if __name__ == "__main__":
82
+ print("πŸš€ Starting AutoTrain...")
83
+
84
+ try:
85
+ import uvicorn
86
+ from fastapi import FastAPI
87
+ from starlette.middleware.sessions import SessionMiddleware
88
+
89
+ # Import after our patches
90
+ import autotrain.app.ui_routes as ui_routes
91
+
92
+ # Patch the user authentication function
93
+ ui_routes.user_authentication = lambda request: mock_user_authentication()
94
+
95
+ from autotrain.app.ui_routes import ui_router
96
+
97
+ app = FastAPI(title="AutoTrain Advanced")
98
+
99
+ # Add session middleware
100
+ app.add_middleware(SessionMiddleware, secret_key="autotrain-secret-key")
101
+
102
+ app.include_router(ui_router)
103
+
104
+ print("βœ… AutoTrain app created successfully!")
105
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
106
+
107
+ except Exception as e:
108
+ print(f"❌ Error: {e}")
109
+ import traceback
110
+ traceback.print_exc()
static/logo.png ADDED