Spaces:
Sleeping
Sleeping
Update main.py
Browse files
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=
|
| 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
|