lemms commited on
Commit
4e62d72
Β·
verified Β·
1 Parent(s): ef76768

Add training script with authentication

Browse files
Files changed (1) hide show
  1. openllm_training_with_auth.py +26 -9
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 HF access token."""
30
- print("πŸ” Setting up HF authentication...")
31
 
32
  try:
33
- # In Hugging Face Spaces, authentication should be automatic
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"βœ… HF authentication successful!")
38
- print(f"πŸ‘€ HF User: {self.username}")
39
 
40
  except Exception as e:
41
- print(f"❌ HF authentication failed: {e}")
42
- print("πŸ’‘ Make sure HF_TOKEN is set in Space settings with HF access token")
43
- sys.exit(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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."""