Commit
·
801d57b
1
Parent(s):
64716d4
load token
Browse files- wai_service.py +15 -1
wai_service.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# --- wai_service.py (final handler) ---------------------------------
|
| 2 |
-
import base64, sys, os, torch
|
| 3 |
sys.path.append(os.path.join(os.path.dirname(__file__), "code"))
|
| 4 |
|
| 5 |
from code.config import set_config
|
|
@@ -34,6 +34,17 @@ def _sanitize(cfg):
|
|
| 34 |
|
| 35 |
|
| 36 |
def handler(payload: dict) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# 1️⃣ Build fake argv *only* from recognised keys
|
| 38 |
cli_argv = [sys.argv[0]]
|
| 39 |
for k in KNOWN_CLI_KEYS & payload.keys():
|
|
@@ -45,6 +56,9 @@ def handler(payload: dict) -> str:
|
|
| 45 |
cfg = set_config() # EasyDict with YAML + CLI-compatible fields
|
| 46 |
finally:
|
| 47 |
sys.argv = orig_argv
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
_sanitize(cfg)
|
| 50 |
|
|
|
|
| 1 |
# --- wai_service.py (final handler) ---------------------------------
|
| 2 |
+
import base64, sys, os, torch, tempfile
|
| 3 |
sys.path.append(os.path.join(os.path.dirname(__file__), "code"))
|
| 4 |
|
| 5 |
from code.config import set_config
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
def handler(payload: dict) -> str:
|
| 37 |
+
|
| 38 |
+
tmp_token_path = None # ➋
|
| 39 |
+
if "token" in payload:
|
| 40 |
+
tmp_token_path = tempfile.NamedTemporaryFile(delete=False, dir=".", prefix="TOKEN_", mode="w")
|
| 41 |
+
tmp_token_path.write(payload["token"])
|
| 42 |
+
tmp_token_path.close()
|
| 43 |
+
os.environ["TOKEN_FILE"] = tmp_token_path.name # optional: let you debug
|
| 44 |
+
|
| 45 |
+
# make config.py look for our temp file
|
| 46 |
+
os.symlink(tmp_token_path.name, "TOKEN")
|
| 47 |
+
|
| 48 |
# 1️⃣ Build fake argv *only* from recognised keys
|
| 49 |
cli_argv = [sys.argv[0]]
|
| 50 |
for k in KNOWN_CLI_KEYS & payload.keys():
|
|
|
|
| 56 |
cfg = set_config() # EasyDict with YAML + CLI-compatible fields
|
| 57 |
finally:
|
| 58 |
sys.argv = orig_argv
|
| 59 |
+
if tmp_token_path: # ➌ clean-up
|
| 60 |
+
os.remove("TOKEN") # remove symlink
|
| 61 |
+
os.unlink(tmp_token_path.name) # remove temp file
|
| 62 |
|
| 63 |
_sanitize(cfg)
|
| 64 |
|