forked from lightningpixel/modly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
53 lines (41 loc) · 1.45 KB
/
Copy pathsettings.py
File metadata and controls
53 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from fastapi import APIRouter
from pydantic import BaseModel
from pathlib import Path
from typing import Optional
import services.generator_registry as reg_module
router = APIRouter(prefix="/settings", tags=["settings"])
class PathsUpdate(BaseModel):
models_dir: Optional[str] = None
workspace_dir: Optional[str] = None
class TokenUpdate(BaseModel):
token: str
@router.get("/paths")
async def get_paths():
return {
"models_dir": str(reg_module.MODELS_DIR),
"workspace_dir": str(reg_module.WORKSPACE_DIR),
}
@router.post("/paths")
async def update_paths(body: PathsUpdate):
reg_module.generator_registry.update_paths(
models_dir = Path(body.models_dir) if body.models_dir else None,
workspace_dir = Path(body.workspace_dir) if body.workspace_dir else None,
)
return {
"models_dir": str(reg_module.MODELS_DIR),
"workspace_dir": str(reg_module.WORKSPACE_DIR),
}
@router.post("/hf-token")
async def update_hf_token(body: TokenUpdate):
"""
Update the HuggingFace token in this process's environment so that
extension subprocesses spawned after this call inherit the new token.
"""
if body.token:
os.environ["HUGGING_FACE_HUB_TOKEN"] = body.token
os.environ["HF_TOKEN"] = body.token
else:
os.environ.pop("HUGGING_FACE_HUB_TOKEN", None)
os.environ.pop("HF_TOKEN", None)
return {"ok": True}