Spaces:
Paused
Paused
| import gradio as gr | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi import Request | |
| import os | |
| # Create Gradio UI | |
| with gr.Blocks(title="SkyData Game Server") as demo: | |
| gr.Markdown("# π SkyData 3D Earth Game Server") | |
| gr.Markdown("Server Status: **Online & Logging Active π’**") | |
| app = demo.app | |
| # Enable CORS for external requests | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Custom Logging Middleware to force print requests in Hugging Face Terminal | |
| async def log_requests(request: Request, call_next): | |
| path = request.url.path | |
| if path.startswith("/country_flags") or path.startswith("/textures"): | |
| print(f"π₯ [HF SERVER LOG] Request: {path} | Client IP: {request.client.host}") | |
| response = await call_next(request) | |
| return response | |
| # Mount country_flags directory | |
| if os.path.exists("country_flags"): | |
| app.mount("/country_flags", StaticFiles(directory="country_flags"), name="country_flags") | |
| print("β [INIT] Mounted /country_flags folder successfully") | |
| # Mount textures directory | |
| if os.path.exists("textures"): | |
| app.mount("/textures", StaticFiles(directory="textures"), name="textures") | |
| print("β [INIT] Mounted /textures folder successfully") | |
| if __name__ == "__main__": | |
| demo.launch() |