ArturoNereu commited on
Commit
bbb0b64
·
1 Parent(s): cc6d03f

Fix static file serving for Gradio

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. backend/storage.py +0 -1
app.py CHANGED
@@ -13,9 +13,9 @@ from pathlib import Path
13
  from backend.main import app as fastapi_app
14
 
15
  # Set up static paths for Gradio to serve model files
16
- # This makes files accessible at /gradio_api/file=<path>
17
  MODELS_DIR = Path(__file__).parent / "models"
18
- gr.set_static_paths(paths=[str(MODELS_DIR)])
19
 
20
  # Get base URLs from environment
21
  # Auto-detect HF Spaces environment
@@ -119,9 +119,9 @@ def get_viewer_html(scene_id="welcome"):
119
 
120
  # Add the static assets base URL for model loading
121
  # On local dev: FastAPI serves at /static/models/
122
- # On HF Spaces: Gradio serves via set_static_paths at /file/models/
123
  if IS_HF_SPACES:
124
- scene_data["static_base_url"] = f"/file={MODELS_DIR}/"
125
  else:
126
  scene_data["static_base_url"] = f"{FASTAPI_INTERNAL}/static/models/"
127
 
 
13
  from backend.main import app as fastapi_app
14
 
15
  # Set up static paths for Gradio to serve model files
16
+ # Files are accessible at /gradio_api/file=models/<filename>
17
  MODELS_DIR = Path(__file__).parent / "models"
18
+ gr.set_static_paths(paths=["models"]) # Relative path from app.py
19
 
20
  # Get base URLs from environment
21
  # Auto-detect HF Spaces environment
 
119
 
120
  # Add the static assets base URL for model loading
121
  # On local dev: FastAPI serves at /static/models/
122
+ # On HF Spaces: Gradio serves via set_static_paths at /gradio_api/file=models/
123
  if IS_HF_SPACES:
124
+ scene_data["static_base_url"] = "/gradio_api/file=models/"
125
  else:
126
  scene_data["static_base_url"] = f"{FASTAPI_INTERNAL}/static/models/"
127
 
backend/storage.py CHANGED
@@ -81,7 +81,6 @@ def initialize_default_scene():
81
  )
82
 
83
  # Hugging Face emoji model at center (animated)
84
- # model_path is relative - will be resolved by viewer based on environment
85
  objects = [
86
  create_game_object(
87
  object_type="model",
 
81
  )
82
 
83
  # Hugging Face emoji model at center (animated)
 
84
  objects = [
85
  create_game_object(
86
  object_type="model",