Jerry
feat: add /slides route to FastAPI so slide deck is viewable on HF Space
69d7ed0
Raw
History Blame Contribute Delete
1.82 kB
"""FastAPI server for the Logistics Shipment RL Environment."""
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
import os
try:
from openenv.core.env_server.http_server import create_app
from .environment import LogisticsShipmentEnvironment, LogisticsAction, LogisticsObservation
except ImportError:
from openenv.core.env_server.http_server import create_app
from server.environment import LogisticsShipmentEnvironment, LogisticsAction, LogisticsObservation
# Create the base application
app = create_app(
LogisticsShipmentEnvironment,
LogisticsAction,
LogisticsObservation,
env_name="logistics_shipment_env",
)
# Add CORS middleware to allow dashboard.html to talk to the server
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allow all origins for the hackathon
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Serve the beautiful dashboard at the root
@app.get("/")
async def serve_dashboard():
dashboard_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "dashboard.html")
if os.path.exists(dashboard_path):
return FileResponse(dashboard_path)
return {"error": "Dashboard not found", "path": dashboard_path}
@app.get("/health")
async def health():
return {"status": "ok", "env": "logistics_shipment_env"}
# Serve the slide deck presentation
@app.get("/slides")
async def serve_slides():
slides_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "slides.html")
if os.path.exists(slides_path):
return FileResponse(slides_path, media_type="text/html")
return {"error": "Slides not found"}
def main():
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
if __name__ == "__main__":
main()