Spaces:
Sleeping
Sleeping
| import os | |
| import uvicorn | |
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import RedirectResponse, HTMLResponse, JSONResponse | |
| from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html | |
| from fastapi.openapi.utils import get_openapi | |
| from src.api.app import app as api_app | |
| app = FastAPI(title="MCP EdTech", description="Model Context Protocol for Educational Technology") | |
| app.mount("/static", StaticFiles(directory="static"), name="static") | |
| async def serve_root(): | |
| try: | |
| with open("static/index.html", "r") as f: | |
| html_content = f.read() | |
| return HTMLResponse(content=html_content) | |
| except Exception as e: | |
| return JSONResponse(content={ | |
| "name": "MCP EdTech API", | |
| "version": "1.0.0", | |
| "description": "Model Context Protocol implementation for EdTech applications", | |
| "demo_ui": "Please visit /demo for the interactive demo" | |
| }) | |
| async def serve_demo(): | |
| with open("static/index.html", "r") as f: | |
| html_content = f.read() | |
| return HTMLResponse(content=html_content) | |
| for route in api_app.routes: | |
| app.routes.append(route) | |
| def custom_openapi(): | |
| if app.openapi_schema: | |
| return app.openapi_schema | |
| openapi_schema = get_openapi( | |
| title="MCP EdTech API BY MHA", | |
| version="1.0.0", | |
| description="Model Context Protocol implementation for EdTech applications", | |
| routes=app.routes, | |
| ) | |
| app.openapi_schema = openapi_schema | |
| return app.openapi_schema | |
| app.openapi = custom_openapi | |
| if __name__ == "__main__": | |
| port = int(os.environ.get("PORT", 7860)) | |
| uvicorn.run(app, host="0.0.0.0", port=port) | |