Spaces:
Sleeping
Sleeping
ARYANPATEL-BIT commited on
Commit ·
03e27fd
1
Parent(s): 2b0efd5
Feat: Better structured inference.py
Browse files- inference.py +24 -3
inference.py
CHANGED
|
@@ -43,7 +43,22 @@ except ImportError:
|
|
| 43 |
API_BASE_URL = os.environ.get("API_BASE_URL", "")
|
| 44 |
MODEL_NAME = os.environ.get("MODEL_NAME", "")
|
| 45 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
TASKS = ["easy", "medium", "hard"]
|
| 49 |
REQUEST_TIMEOUT = 30
|
|
@@ -257,7 +272,7 @@ def wait_for_env():
|
|
| 257 |
return False
|
| 258 |
for attempt in range(ENV_BOOT_RETRIES):
|
| 259 |
try:
|
| 260 |
-
resp = requests.get(f"{ENV_URL}/", timeout=10)
|
| 261 |
if resp.status_code == 200:
|
| 262 |
print(f" ENV reachable on attempt {attempt + 1}", flush=True)
|
| 263 |
return True
|
|
@@ -396,7 +411,13 @@ def main():
|
|
| 396 |
sys.stdout.write("")
|
| 397 |
sys.stdout.flush()
|
| 398 |
|
| 399 |
-
print(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
|
| 401 |
# Create LLM client (or None if not available)
|
| 402 |
client = None
|
|
|
|
| 43 |
API_BASE_URL = os.environ.get("API_BASE_URL", "")
|
| 44 |
MODEL_NAME = os.environ.get("MODEL_NAME", "")
|
| 45 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 46 |
+
|
| 47 |
+
# ENV_URL resolution order:
|
| 48 |
+
# 1. Explicit ENV_URL env var
|
| 49 |
+
# 2. Constructed from SPACE_ID (HuggingFace Spaces pattern)
|
| 50 |
+
# 3. Default to localhost:7860
|
| 51 |
+
def _resolve_env_url() -> str:
|
| 52 |
+
explicit = os.environ.get("ENV_URL", "")
|
| 53 |
+
if explicit:
|
| 54 |
+
return explicit.rstrip("/")
|
| 55 |
+
space_id = os.environ.get("SPACE_ID", "")
|
| 56 |
+
if space_id and "/" in space_id:
|
| 57 |
+
user, repo = space_id.split("/", 1)
|
| 58 |
+
return f"https://{user}-{repo}.hf.space"
|
| 59 |
+
return "http://localhost:7860"
|
| 60 |
+
|
| 61 |
+
ENV_URL = _resolve_env_url()
|
| 62 |
|
| 63 |
TASKS = ["easy", "medium", "hard"]
|
| 64 |
REQUEST_TIMEOUT = 30
|
|
|
|
| 272 |
return False
|
| 273 |
for attempt in range(ENV_BOOT_RETRIES):
|
| 274 |
try:
|
| 275 |
+
resp = requests.get(f"{ENV_URL}/health", timeout=10)
|
| 276 |
if resp.status_code == 200:
|
| 277 |
print(f" ENV reachable on attempt {attempt + 1}", flush=True)
|
| 278 |
return True
|
|
|
|
| 411 |
sys.stdout.write("")
|
| 412 |
sys.stdout.flush()
|
| 413 |
|
| 414 |
+
print("="*60, flush=True)
|
| 415 |
+
print("DevOps/FinOps OpenEnv — Baseline Inference Agent v2.0", flush=True)
|
| 416 |
+
print("="*60, flush=True)
|
| 417 |
+
print(f"[CONFIG] ENV_URL={ENV_URL}", flush=True)
|
| 418 |
+
print(f"[CONFIG] MODEL={MODEL_NAME or 'unset'}", flush=True)
|
| 419 |
+
print(f"[CONFIG] API_BASE={API_BASE_URL[:50] if API_BASE_URL else 'unset'}", flush=True)
|
| 420 |
+
print(f"[CONFIG] TASKS={TASKS}", flush=True)
|
| 421 |
|
| 422 |
# Create LLM client (or None if not available)
|
| 423 |
client = None
|