Skydata001 commited on
Commit
56593a0
·
verified ·
1 Parent(s): 3f9a1fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -1,16 +1,17 @@
1
  import gradio as gr
2
  from fastapi.staticfiles import StaticFiles
3
  from fastapi.middleware.cors import CORSMiddleware
 
4
  import os
5
 
6
- # Create Gradio interface
7
  with gr.Blocks(title="SkyData Game Server") as demo:
8
- gr.Markdown("# 🌍 SkyData Game Server is Running")
9
- gr.Markdown("Status: **Active & Serving Assets**")
10
 
11
  app = demo.app
12
 
13
- # Enable CORS for cross-origin requests from game.html
14
  app.add_middleware(
15
  CORSMiddleware,
16
  allow_origins=["*"],
@@ -19,13 +20,24 @@ app.add_middleware(
19
  allow_headers=["*"],
20
  )
21
 
 
 
 
 
 
 
 
 
 
22
  # Mount country_flags directory
23
  if os.path.exists("country_flags"):
24
  app.mount("/country_flags", StaticFiles(directory="country_flags"), name="country_flags")
 
25
 
26
  # Mount textures directory
27
  if os.path.exists("textures"):
28
  app.mount("/textures", StaticFiles(directory="textures"), name="textures")
 
29
 
30
  if __name__ == "__main__":
31
  demo.launch()
 
1
  import gradio as gr
2
  from fastapi.staticfiles import StaticFiles
3
  from fastapi.middleware.cors import CORSMiddleware
4
+ from fastapi import Request
5
  import os
6
 
7
+ # Create Gradio UI
8
  with gr.Blocks(title="SkyData Game Server") as demo:
9
+ gr.Markdown("# 🌍 SkyData 3D Earth Game Server")
10
+ gr.Markdown("Server Status: **Online & Logging Active 🟢**")
11
 
12
  app = demo.app
13
 
14
+ # Enable CORS for external requests
15
  app.add_middleware(
16
  CORSMiddleware,
17
  allow_origins=["*"],
 
20
  allow_headers=["*"],
21
  )
22
 
23
+ # Custom Logging Middleware to force print requests in Hugging Face Terminal
24
+ @app.middleware("http")
25
+ async def log_requests(request: Request, call_next):
26
+ path = request.url.path
27
+ if path.startswith("/country_flags") or path.startswith("/textures"):
28
+ print(f"📥 [HF SERVER LOG] Request: {path} | Client IP: {request.client.host}")
29
+ response = await call_next(request)
30
+ return response
31
+
32
  # Mount country_flags directory
33
  if os.path.exists("country_flags"):
34
  app.mount("/country_flags", StaticFiles(directory="country_flags"), name="country_flags")
35
+ print("✅ [INIT] Mounted /country_flags folder successfully")
36
 
37
  # Mount textures directory
38
  if os.path.exists("textures"):
39
  app.mount("/textures", StaticFiles(directory="textures"), name="textures")
40
+ print("✅ [INIT] Mounted /textures folder successfully")
41
 
42
  if __name__ == "__main__":
43
  demo.launch()