|
25 | 25 | from trackio.sqlite_storage import SQLiteStorage |
26 | 26 | from trackio.table import Table |
27 | 27 | from trackio.typehints import UploadEntry |
28 | | -from trackio.ui.main import CSS, HEAD, demo |
29 | 28 | from trackio.utils import TRACKIO_DIR, TRACKIO_LOGO_DIR |
30 | 29 |
|
31 | 30 | logging.getLogger("httpx").setLevel(logging.WARNING) |
|
69 | 68 | config = {} |
70 | 69 |
|
71 | 70 |
|
| 71 | +def _get_demo(): |
| 72 | + # Lazy import to avoid initializing Gradio Blocks (and FastAPI) at import time, |
| 73 | + # which causes import lock errors for libraries that just `import trackio`. |
| 74 | + from trackio.ui.main import CSS, HEAD, demo |
| 75 | + |
| 76 | + return demo, CSS, HEAD |
| 77 | + |
| 78 | + |
72 | 79 | def init( |
73 | 80 | project: str, |
74 | 81 | name: str | None = None, |
@@ -159,6 +166,7 @@ def init( |
159 | 166 | raise LocalTokenNotFoundError( |
160 | 167 | f"You must be logged in to Hugging Face locally when `space_id` is provided to deploy to a Space. {e}" |
161 | 168 | ) from e |
| 169 | + demo, CSS, HEAD = _get_demo() |
162 | 170 | url = context_vars.current_server.get() |
163 | 171 | share_url = context_vars.current_share_server.get() |
164 | 172 |
|
@@ -518,6 +526,8 @@ def show( |
518 | 526 | `share_url`: The public share URL of the dashboard. |
519 | 527 | `full_url`: The full URL of the dashboard including the write token (will use the public share URL if launched publicly, otherwise the local URL). |
520 | 528 | """ |
| 529 | + demo, CSS, HEAD = _get_demo() |
| 530 | + |
521 | 531 | if color_palette is not None: |
522 | 532 | os.environ["TRACKIO_COLOR_PALETTE"] = ",".join(color_palette) |
523 | 533 |
|
|
0 commit comments