Spaces:
Paused
Paused
File size: 1,428 Bytes
8ded9cf 56593a0 8ded9cf 56593a0 8ded9cf 56593a0 8ded9cf 56593a0 8ded9cf 56593a0 8ded9cf 56593a0 8ded9cf 56593a0 8ded9cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 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() |