Commit ·
2ff4c13
1
Parent(s): 86c5bd7
Update app.py
Browse files
app.py
CHANGED
|
@@ -250,10 +250,7 @@ APP_CSS = """
|
|
| 250 |
"""
|
| 251 |
|
| 252 |
# Build immersive chat interface with overlay
|
| 253 |
-
with gr.Blocks(
|
| 254 |
-
title="GCP - Game Context Protocol",
|
| 255 |
-
css=APP_CSS,
|
| 256 |
-
) as demo:
|
| 257 |
# Initialize JavaScript functionality (minimal essentials only)
|
| 258 |
gr.HTML("""
|
| 259 |
<script>
|
|
@@ -508,20 +505,41 @@ with gr.Blocks(
|
|
| 508 |
|
| 509 |
|
| 510 |
if __name__ == "__main__":
|
| 511 |
-
# Enable queue for handling multiple concurrent users (important for HF Spaces)
|
| 512 |
demo.queue()
|
| 513 |
|
| 514 |
if IS_HF_SPACES:
|
| 515 |
-
# On HF Spaces:
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
else:
|
| 526 |
# Local dev: FastAPI already running on 8000 (started above), just launch Gradio on 7860
|
| 527 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 250 |
"""
|
| 251 |
|
| 252 |
# Build immersive chat interface with overlay
|
| 253 |
+
with gr.Blocks(title="GCP - Game Context Protocol") as demo:
|
|
|
|
|
|
|
|
|
|
| 254 |
# Initialize JavaScript functionality (minimal essentials only)
|
| 255 |
gr.HTML("""
|
| 256 |
<script>
|
|
|
|
| 505 |
|
| 506 |
|
| 507 |
if __name__ == "__main__":
|
|
|
|
| 508 |
demo.queue()
|
| 509 |
|
| 510 |
if IS_HF_SPACES:
|
| 511 |
+
# On HF Spaces: Create a FastAPI app with our routes, then mount Gradio on it
|
| 512 |
+
from fastapi import FastAPI, HTTPException
|
| 513 |
+
from fastapi.responses import HTMLResponse
|
| 514 |
+
from backend.storage import storage
|
| 515 |
+
|
| 516 |
+
app = FastAPI()
|
| 517 |
+
|
| 518 |
+
@app.get("/api/scenes/{scene_id}")
|
| 519 |
+
async def get_scene_api(scene_id: str):
|
| 520 |
+
scene = storage.get(scene_id)
|
| 521 |
+
if not scene:
|
| 522 |
+
raise HTTPException(status_code=404, detail=f"Scene '{scene_id}' not found")
|
| 523 |
+
return scene
|
| 524 |
+
|
| 525 |
+
@app.get("/view/scene/{scene_id}")
|
| 526 |
+
async def view_scene(scene_id: str):
|
| 527 |
+
scene = storage.get(scene_id)
|
| 528 |
+
if not scene:
|
| 529 |
+
raise HTTPException(status_code=404, detail=f"Scene '{scene_id}' not found")
|
| 530 |
+
viewer_path = os.path.join(os.path.dirname(__file__), "frontend", "game_viewer.html")
|
| 531 |
+
with open(viewer_path, 'r') as f:
|
| 532 |
+
return HTMLResponse(content=f.read())
|
| 533 |
+
|
| 534 |
+
@app.get("/health")
|
| 535 |
+
async def health_check():
|
| 536 |
+
return {"status": "healthy", "service": "GCP", "version": "2.0.0"}
|
| 537 |
+
|
| 538 |
+
# Mount Gradio onto our FastAPI app
|
| 539 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 540 |
+
|
| 541 |
+
print("🚀 Starting on HF Spaces - FastAPI + Gradio on port 7860")
|
| 542 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 543 |
else:
|
| 544 |
# Local dev: FastAPI already running on 8000 (started above), just launch Gradio on 7860
|
| 545 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|