@@ -208,7 +208,8 @@ def estimate_model_requirements(model_id: str) -> Dict[str, float]:
208
208
"ram_gb" : requirements ["min_ram" ] * 1.2 , # 20% buffer
209
209
"vram_gb" : requirements ["min_vram" ] * 1.2 if "min_vram" in requirements else 0
210
210
}
211
-
211
+ import torch
212
+ import psutil
212
213
213
214
# Model Configuration
214
215
CUSTOM_MODEL = get_env_var ("LOCALLAB_CUSTOM_MODEL" , default = "" )
@@ -600,7 +601,7 @@ def set_env_var(name: str, value: str):
600
601
def get_hf_token (interactive : bool = False ) -> Optional [str ]:
601
602
"""Get HuggingFace token from environment or config"""
602
603
# First check environment
603
- token = get_env_var ( HF_TOKEN_ENV )
604
+ token = os . environ . get ( "HUGGINGFACE_TOKEN" , "" ). strip ( )
604
605
605
606
# Then check config
606
607
if not token :
@@ -609,16 +610,45 @@ def get_hf_token(interactive: bool = False) -> Optional[str]:
609
610
token = str (get_config_value ("huggingface_token" , "" )).strip ()
610
611
if token :
611
612
# Update environment variable
612
- set_env_var ( HF_TOKEN_ENV , token )
613
+ os . environ [ "HUGGINGFACE_TOKEN" ] = token
613
614
except :
614
615
pass
615
616
617
+ # If interactive and still no token, prompt user
618
+ if not token and interactive :
619
+ try :
620
+ click .echo ("\n 🔑 HuggingFace token is required for accessing this model." )
621
+ click .echo ("Get your token from: https://huggingface.co/settings/tokens" )
622
+
623
+ token = click .prompt (
624
+ "Enter your HuggingFace token" ,
625
+ type = str ,
626
+ default = "" ,
627
+ show_default = False
628
+ ).strip ()
629
+
630
+ if token :
631
+ if len (token ) < 20 :
632
+ click .echo ("\n ❌ Invalid token format. Please check your token." )
633
+ return None
634
+
635
+ click .echo (f"\n ✅ Token saved: { token } " )
636
+ os .environ ["HUGGINGFACE_TOKEN" ] = token
637
+
638
+ # Save to config
639
+ from .cli .config import set_config_value
640
+ set_config_value ("huggingface_token" , token )
641
+ else :
642
+ click .echo ("\n Skipping token..." )
643
+ except :
644
+ pass
645
+
616
646
return token
617
647
618
648
def get_ngrok_token () -> Optional [str ]:
619
649
"""Get ngrok token from environment or config"""
620
650
# First check environment
621
- token = get_env_var ( NGROK_TOKEN_ENV )
651
+ token = os . environ . get ( "NGROK_AUTHTOKEN" , "" ). strip ( )
622
652
623
653
# Then check config
624
654
if not token :
@@ -627,14 +657,16 @@ def get_ngrok_token() -> Optional[str]:
627
657
token = str (get_config_value ("ngrok_auth_token" , "" )).strip ()
628
658
if token :
629
659
# Update environment variable
630
- set_env_var ( NGROK_TOKEN_ENV , token )
660
+ os . environ [ "NGROK_AUTHTOKEN" ] = token
631
661
except :
632
662
pass
633
663
634
664
return token
635
665
636
666
def save_config (config : Dict [str , Any ]):
637
667
"""Save configuration to file"""
668
+ from .cli .config import ensure_config_dir , CONFIG_FILE
669
+
638
670
ensure_config_dir ()
639
671
640
672
# Ensure tokens are stored as proper strings
@@ -653,51 +685,3 @@ def save_config(config: Dict[str, Any]):
653
685
json .dump (config , f , indent = 2 )
654
686
except Exception as e :
655
687
logger .error (f"Error saving config: { e } " )
656
-
657
-
658
- def get_hf_token (interactive : bool = False ) -> Optional [str ]:
659
- """Get HuggingFace token from environment or config"""
660
- # First check environment
661
- token = os .environ .get ("HUGGINGFACE_TOKEN" , "" ).strip ()
662
-
663
- # Then check config
664
- if not token :
665
- try :
666
- from .cli .config import get_config_value
667
- token = str (get_config_value ("huggingface_token" , "" )).strip ()
668
- if token :
669
- # Update environment variable
670
- os .environ ["HUGGINGFACE_TOKEN" ] = token
671
- except :
672
- pass
673
-
674
- # If interactive and still no token, prompt user
675
- if not token and interactive :
676
- try :
677
- click .echo ("\n 🔑 HuggingFace token is required for accessing this model." )
678
- click .echo ("Get your token from: https://huggingface.co/settings/tokens" )
679
-
680
- token = click .prompt (
681
- "Enter your HuggingFace token" ,
682
- type = str ,
683
- default = "" ,
684
- show_default = False
685
- ).strip ()
686
-
687
- if token :
688
- if len (token ) < 20 :
689
- click .echo ("\n ❌ Invalid token format. Please check your token." )
690
- return None
691
-
692
- click .echo (f"\n ✅ Token saved: { token } " )
693
- os .environ ["HUGGINGFACE_TOKEN" ] = token
694
-
695
- # Save to config
696
- from .cli .config import set_config_value
697
- set_config_value ("huggingface_token" , token )
698
- else :
699
- click .echo ("\n Skipping token..." )
700
- except :
701
- pass
702
-
703
- return token
0 commit comments