Proteinrequired commited on
Commit
25d1c50
Β·
verified Β·
1 Parent(s): 6f5e8cd

Update train.py

Browse files
Files changed (1) hide show
  1. train.py +26 -29
train.py CHANGED
@@ -1,31 +1,13 @@
1
  # ==========================================
2
- # 0. BRUTE FORCE SETUP & AUTHENTICATION
3
  # ==========================================
4
  import os
5
  import sys
6
- import urllib.request
7
- import subprocess
8
 
9
  # Disable UI prompts at the deepest system level
10
  os.environ["HF_HUB_DISABLE_INTERACTIVE_PROMPTS"] = "1"
11
- os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0" # Sometimes transfer agents cause prompt loops
12
-
13
- HF_USERNAME = "Proteinrequired"
14
- SPACE_NAME = "enterprise-email-triage"
15
-
16
- print("Checking for required environment files...")
17
- # THE FIX: Added openenv.yaml to this list!
18
- files_to_download = ["env.py", "dataset.json", "reward_system.py", "openenv.yaml"]
19
- base_url = f"https://huggingface.co/spaces/{HF_USERNAME}/{SPACE_NAME}/resolve/main/"
20
-
21
- for file in files_to_download:
22
- if not os.path.exists(file):
23
- print(f"Downloading {file} from repository...")
24
- try:
25
- urllib.request.urlretrieve(base_url + file, file)
26
- print(f"βœ… {file} downloaded successfully.")
27
- except Exception as e:
28
- print(f"❌ Failed to download {file}")
29
 
30
  raw_token = os.environ.get("HF_TOKEN")
31
  if not raw_token:
@@ -35,14 +17,29 @@ if not raw_token:
35
  hf_token = raw_token.strip()
36
  os.environ["HF_TOKEN"] = hf_token
37
 
38
- print("πŸ”‘ Forcing System-Level Hugging Face Login...")
39
- # This writes the token directly to the machine's hard drive so no library can ignore it
40
- try:
41
- subprocess.run(["huggingface-cli", "login", "--token", hf_token, "--add-to-git-credential"], check=True)
42
- print("βœ… System Login Successful!")
43
- except subprocess.CalledProcessError:
44
- print("❌ System Login Failed. Check if your token is correct.")
45
- sys.exit(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  # ==========================================
47
  # 1. THE STABLE ENVIRONMENT INSTALL
48
  # ==========================================
 
1
  # ==========================================
2
+ # 0. PURE PYTHON SETUP & AUTO-FETCHER
3
  # ==========================================
4
  import os
5
  import sys
6
+ from huggingface_hub import hf_hub_download, login
 
7
 
8
  # Disable UI prompts at the deepest system level
9
  os.environ["HF_HUB_DISABLE_INTERACTIVE_PROMPTS"] = "1"
10
+ os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  raw_token = os.environ.get("HF_TOKEN")
13
  if not raw_token:
 
17
  hf_token = raw_token.strip()
18
  os.environ["HF_TOKEN"] = hf_token
19
 
20
+ print("πŸ”‘ Authenticating via pure Python...")
21
+ # Python-level login instead of system-level CLI
22
+ login(token=hf_token, add_to_git_credential=True)
23
+
24
+ HF_USERNAME = "Proteinrequired"
25
+ SPACE_NAME = "enterprise-email-triage"
26
+ files_to_download = ["env.py", "dataset.json", "reward_system.py", "openenv.yaml"]
27
+
28
+ print(f"Fetching master environment files from {SPACE_NAME}...")
29
+ for file in files_to_download:
30
+ try:
31
+ # hf_hub_download automatically handles private spaces!
32
+ hf_hub_download(
33
+ repo_id=f"{HF_USERNAME}/{SPACE_NAME}",
34
+ repo_type="space",
35
+ filename=file,
36
+ token=hf_token, # Passes the token securely
37
+ local_dir="." # Saves right next to train.py
38
+ )
39
+ print(f"βœ… {file} downloaded successfully.")
40
+ except Exception as e:
41
+ print(f"❌ Failed to download {file}. Error: {e}")
42
+ sys.exit(1)
43
  # ==========================================
44
  # 1. THE STABLE ENVIRONMENT INSTALL
45
  # ==========================================