Limbicnation commited on
Commit
dd8e2a1
·
verified ·
1 Parent(s): 9f58399

Upload train_flux_lora_v9.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_flux_lora_v9.py +53 -0
train_flux_lora_v9.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = [
4
+ # "torch>=2.0.0",
5
+ # "diffusers>=0.25.0",
6
+ # "transformers>=4.35.0",
7
+ # "accelerate>=0.24.0",
8
+ # "peft>=0.7.0",
9
+ # "huggingface-hub>=0.20.0",
10
+ # "safetensors>=0.4.0",
11
+ # "Pillow>=10.0.0",
12
+ # "numpy>=1.24.0",
13
+ # "tqdm>=4.66.0",
14
+ # ]
15
+ # ///
16
+
17
+ import os
18
+ import sys
19
+ print("="*70)
20
+ print("FLUX LoRA Training v9 - Token Fix")
21
+ print("="*70)
22
+
23
+ # Get token - try multiple sources
24
+ token = os.environ.get("HF_TOKEN")
25
+ if not token or token == "$HF_TOKEN":
26
+ # Try to read from file if env var not set properly
27
+ try:
28
+ with open("/secrets/HF_TOKEN") as f:
29
+ token = f.read().strip()
30
+ except:
31
+ pass
32
+
33
+ if not token or token == "$HF_TOKEN":
34
+ print("ERROR: HF_TOKEN not set correctly")
35
+ print(f" Value: {token}")
36
+ print(" Env vars:", list(os.environ.keys()))
37
+ sys.exit(1)
38
+
39
+ print(f"Token loaded: {token[:10]}...")
40
+
41
+ # Set token for huggingface_hub
42
+ os.environ["HF_TOKEN"] = token
43
+ os.environ["HUGGINGFACE_TOKEN"] = token
44
+
45
+ # Now import and login
46
+ from huggingface_hub import login, HfApi
47
+ login(token=token, add_to_git_credential=False)
48
+ print("✅ Login successful")
49
+
50
+ from diffusers import FluxPipeline
51
+ print("✅ FluxPipeline imported")
52
+
53
+ print("\n✅ SUCCESS: All imports work!")