cloud450 commited on
Commit
550d1a6
·
verified ·
1 Parent(s): 0275f08

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -1
main.py CHANGED
@@ -8,11 +8,25 @@ import os
8
  load_dotenv()
9
  # Trigger reload
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  app = FastAPI(
12
  title="Network IDS API",
13
  description="Backend API for Intrusion Detection System",
14
  version="1.0.0",
15
- root_path=os.getenv("ROOT_PATH", "")
16
  )
17
 
18
  # Configure CORS
 
8
  load_dotenv()
9
  # Trigger reload
10
 
11
+ # Configure root_path
12
+ # 1. Try explicit ROOT_PATH env var (User preference)
13
+ root_path = os.getenv("ROOT_PATH")
14
+
15
+ # 2. If not set, try auto-detecting Hugging Face Spaces (Fallback)
16
+ if not root_path:
17
+ space_id = os.getenv("SPACE_ID")
18
+ if space_id:
19
+ # SPACE_ID is usually "username/spacename"
20
+ root_path = f"/spaces/{space_id}"
21
+ print(f"Auto-detected HF Space. Setting root_path to: {root_path}")
22
+ else:
23
+ root_path = ""
24
+
25
  app = FastAPI(
26
  title="Network IDS API",
27
  description="Backend API for Intrusion Detection System",
28
  version="1.0.0",
29
+ root_path=root_path
30
  )
31
 
32
  # Configure CORS