Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
envs/wildfire_env/server/app.py
CHANGED
|
@@ -16,6 +16,11 @@ def create_wildfire_environment():
|
|
| 16 |
"""Factory function that creates WildfireEnvironment with config."""
|
| 17 |
return WildfireEnvironment(width=W, height=H)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Create the app with web interface support
|
| 20 |
# create_app handles ENABLE_WEB_INTERFACE automatically
|
| 21 |
app = create_app(
|
|
@@ -25,16 +30,28 @@ app = create_app(
|
|
| 25 |
env_name="wildfire_env",
|
| 26 |
)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
os.getenv("ENABLE_WEB_INTERFACE", "false").lower() in ("true", "1", "yes")
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
if enable_web:
|
| 34 |
# Load metadata for custom wildfire interface
|
| 35 |
env_instance = create_wildfire_environment()
|
| 36 |
metadata = load_environment_metadata(env_instance, "wildfire_env")
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Add our custom wildfire interface route (overrides default /web)
|
| 39 |
@app.get("/web", response_class=HTMLResponse)
|
| 40 |
async def wildfire_web_interface():
|
|
|
|
| 16 |
"""Factory function that creates WildfireEnvironment with config."""
|
| 17 |
return WildfireEnvironment(width=W, height=H)
|
| 18 |
|
| 19 |
+
# Check if web interface should be enabled for custom routes
|
| 20 |
+
enable_web = (
|
| 21 |
+
os.getenv("ENABLE_WEB_INTERFACE", "false").lower() in ("true", "1", "yes")
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
# Create the app with web interface support
|
| 25 |
# create_app handles ENABLE_WEB_INTERFACE automatically
|
| 26 |
app = create_app(
|
|
|
|
| 30 |
env_name="wildfire_env",
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Override the default /web route with our custom wildfire interface
|
| 34 |
+
# This must be done AFTER create_app to ensure it overrides the default route
|
|
|
|
|
|
|
|
|
|
| 35 |
if enable_web:
|
| 36 |
# Load metadata for custom wildfire interface
|
| 37 |
env_instance = create_wildfire_environment()
|
| 38 |
metadata = load_environment_metadata(env_instance, "wildfire_env")
|
| 39 |
|
| 40 |
+
# Remove any existing /web GET route and add our custom one
|
| 41 |
+
# FastAPI uses the first matching route, so we need to remove the default one first
|
| 42 |
+
routes_to_remove = []
|
| 43 |
+
for route in app.routes:
|
| 44 |
+
# Check if this is a GET route for /web
|
| 45 |
+
if hasattr(route, 'path') and route.path == '/web':
|
| 46 |
+
if hasattr(route, 'methods') and 'GET' in route.methods:
|
| 47 |
+
routes_to_remove.append(route)
|
| 48 |
+
elif hasattr(route, 'methods') and not route.methods: # Some route types don't have methods
|
| 49 |
+
# Check if it's a GET route by inspecting the endpoint
|
| 50 |
+
routes_to_remove.append(route)
|
| 51 |
+
|
| 52 |
+
for route in routes_to_remove:
|
| 53 |
+
app.routes.remove(route)
|
| 54 |
+
|
| 55 |
# Add our custom wildfire interface route (overrides default /web)
|
| 56 |
@app.get("/web", response_class=HTMLResponse)
|
| 57 |
async def wildfire_web_interface():
|