Skip to content

Commit 2dc7e90

Browse files
committed
Fixed import issues
1 parent 239e8b8 commit 2dc7e90

File tree

2 files changed

+38
-54
lines changed

2 files changed

+38
-54
lines changed

locallab/config.py

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ def estimate_model_requirements(model_id: str) -> Dict[str, float]:
208208
"ram_gb": requirements["min_ram"] * 1.2, # 20% buffer
209209
"vram_gb": requirements["min_vram"] * 1.2 if "min_vram" in requirements else 0
210210
}
211-
211+
import torch
212+
import psutil
212213

213214
# Model Configuration
214215
CUSTOM_MODEL = get_env_var("LOCALLAB_CUSTOM_MODEL", default="")
@@ -600,7 +601,7 @@ def set_env_var(name: str, value: str):
600601
def get_hf_token(interactive: bool = False) -> Optional[str]:
601602
"""Get HuggingFace token from environment or config"""
602603
# First check environment
603-
token = get_env_var(HF_TOKEN_ENV)
604+
token = os.environ.get("HUGGINGFACE_TOKEN", "").strip()
604605

605606
# Then check config
606607
if not token:
@@ -609,16 +610,45 @@ def get_hf_token(interactive: bool = False) -> Optional[str]:
609610
token = str(get_config_value("huggingface_token", "")).strip()
610611
if token:
611612
# Update environment variable
612-
set_env_var(HF_TOKEN_ENV, token)
613+
os.environ["HUGGINGFACE_TOKEN"] = token
613614
except:
614615
pass
615616

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("\nSkipping token...")
643+
except:
644+
pass
645+
616646
return token
617647

618648
def get_ngrok_token() -> Optional[str]:
619649
"""Get ngrok token from environment or config"""
620650
# First check environment
621-
token = get_env_var(NGROK_TOKEN_ENV)
651+
token = os.environ.get("NGROK_AUTHTOKEN", "").strip()
622652

623653
# Then check config
624654
if not token:
@@ -627,14 +657,16 @@ def get_ngrok_token() -> Optional[str]:
627657
token = str(get_config_value("ngrok_auth_token", "")).strip()
628658
if token:
629659
# Update environment variable
630-
set_env_var(NGROK_TOKEN_ENV, token)
660+
os.environ["NGROK_AUTHTOKEN"] = token
631661
except:
632662
pass
633663

634664
return token
635665

636666
def save_config(config: Dict[str, Any]):
637667
"""Save configuration to file"""
668+
from .cli.config import ensure_config_dir, CONFIG_FILE
669+
638670
ensure_config_dir()
639671

640672
# Ensure tokens are stored as proper strings
@@ -653,51 +685,3 @@ def save_config(config: Dict[str, Any]):
653685
json.dump(config, f, indent=2)
654686
except Exception as e:
655687
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("\nSkipping token...")
700-
except:
701-
pass
702-
703-
return token

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="locallab",
8-
version="0.4.32",
8+
version="0.4.33",
99
packages=find_packages(include=["locallab", "locallab.*"]),
1010
install_requires=[
1111
"fastapi>=0.95.0,<1.0.0",

0 commit comments

Comments
 (0)