Skip to content

Commit d8891b8

Browse files
committed
Fix imports to support both local dev and HF Spaces deployment
1 parent 1786d53 commit d8891b8

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

apps/analytics/app.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
import sys
66
from pathlib import Path
77

8-
# Add project root to path for imports
8+
# Add project root to path for local development
99
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
1010

1111
import gradio as gr
12-
from apps.shared.custom_components import AppBase
13-
from config.settings import LOCAL_PORTS
12+
13+
# Support both local (apps.shared) and HF Spaces (shared) imports
14+
try:
15+
from apps.shared.custom_components import AppBase
16+
from config.settings import LOCAL_PORTS
17+
except ImportError:
18+
from shared.custom_components import AppBase
19+
from config.settings import LOCAL_PORTS
1420

1521

1622
class AnalyticsApp(AppBase):

apps/dashboard/app.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
import sys
66
from pathlib import Path
77

8-
# Add project root to path for imports
8+
# Add project root to path for local development
99
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
1010

1111
import gradio as gr
12-
from apps.shared.custom_components import AppBase
13-
from config.settings import LOCAL_PORTS
12+
13+
# Support both local (apps.shared) and HF Spaces (shared) imports
14+
try:
15+
from apps.shared.custom_components import AppBase
16+
from config.settings import LOCAL_PORTS
17+
except ImportError:
18+
from shared.custom_components import AppBase
19+
from config.settings import LOCAL_PORTS
1420

1521

1622
class DashboardApp(AppBase):

apps/shared/custom_components.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99

1010
from abc import ABC, abstractmethod
1111
import gradio as gr
12-
from config.app_registry import get_app_info
13-
from apps.shared.ui_components import header, footer, navigation
12+
13+
# Support both local and HF Spaces imports
14+
try:
15+
from config.app_registry import get_app_info
16+
from apps.shared.ui_components import header, footer, navigation
17+
except ImportError:
18+
from config.app_registry import get_app_info
19+
from shared.ui_components import header, footer, navigation
1420

1521

1622
class AppBase(ABC):

apps/shared/ui_components.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
"""
66

77
import gradio as gr
8-
from config.app_registry import APPS_REGISTRY, get_app_info, get_all_apps
9-
from config.settings import get_app_url
8+
9+
# Support both local and HF Spaces imports
10+
try:
11+
from config.app_registry import APPS_REGISTRY, get_app_info, get_all_apps
12+
from config.settings import get_app_url
13+
except ImportError:
14+
# When running on HF Spaces, config is at root level
15+
import sys
16+
sys.path.insert(0, "/app")
17+
from config.app_registry import APPS_REGISTRY, get_app_info, get_all_apps
18+
from config.settings import get_app_url
1019

1120

1221
def header(title: str, subtitle: str | None = None) -> gr.Markdown:

0 commit comments

Comments
 (0)