Add training script with authentication
Browse files
openllm_training_with_auth.py
CHANGED
|
@@ -26,21 +26,38 @@ class OpenLLMTrainingManager:
|
|
| 26 |
self.username = None
|
| 27 |
|
| 28 |
def setup_authentication(self):
|
| 29 |
-
"""Setup authentication using
|
| 30 |
-
print("π Setting up
|
| 31 |
|
| 32 |
try:
|
| 33 |
-
#
|
| 34 |
-
# The Space's access token is used by default
|
| 35 |
user_info = whoami()
|
| 36 |
self.username = user_info.get('name', 'unknown')
|
| 37 |
-
print(f"β
|
| 38 |
-
print(f"π€
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
-
print(f"β
|
| 42 |
-
print("
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def create_model_config(self, model_size="small", steps=8000):
|
| 46 |
"""Create model configuration file."""
|
|
|
|
| 26 |
self.username = None
|
| 27 |
|
| 28 |
def setup_authentication(self):
|
| 29 |
+
"""Setup authentication using Space's built-in access token."""
|
| 30 |
+
print("π Setting up Space authentication...")
|
| 31 |
|
| 32 |
try:
|
| 33 |
+
# Try Space's built-in authentication first (primary method)
|
|
|
|
| 34 |
user_info = whoami()
|
| 35 |
self.username = user_info.get('name', 'unknown')
|
| 36 |
+
print(f"β
Space built-in authentication successful!")
|
| 37 |
+
print(f"π€ User: {self.username}")
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
+
print(f"β Space built-in authentication failed: {e}")
|
| 41 |
+
print("π Trying HF access token...")
|
| 42 |
+
|
| 43 |
+
# Fallback to HF access token
|
| 44 |
+
hf_token = os.environ.get('HF_TOKEN')
|
| 45 |
+
if hf_token:
|
| 46 |
+
try:
|
| 47 |
+
from huggingface_hub import login
|
| 48 |
+
login(token=hf_token)
|
| 49 |
+
user_info = whoami()
|
| 50 |
+
self.username = user_info.get('name', 'unknown')
|
| 51 |
+
print(f"β
HF access token authentication successful!")
|
| 52 |
+
print(f"π€ User: {self.username}")
|
| 53 |
+
except Exception as e2:
|
| 54 |
+
print(f"β HF access token authentication failed: {e2}")
|
| 55 |
+
print("π‘ Please check Space authentication configuration")
|
| 56 |
+
sys.exit(1)
|
| 57 |
+
else:
|
| 58 |
+
print("β No authentication method available")
|
| 59 |
+
print("π‘ Please set HF_TOKEN in Space settings or check Space permissions")
|
| 60 |
+
sys.exit(1)
|
| 61 |
|
| 62 |
def create_model_config(self, model_size="small", steps=8000):
|
| 63 |
"""Create model configuration file."""
|