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 @app.middleware("http") 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()