Spaces:
Runtime error
Runtime error
Avoid startup session download
Browse files
app.py
CHANGED
|
@@ -38,12 +38,12 @@ TIMESTAMP_KEYS = (
|
|
| 38 |
)
|
| 39 |
|
| 40 |
|
| 41 |
-
def _hub_token() -> str |
|
| 42 |
return (
|
| 43 |
os.environ.get("HF_TOKEN")
|
| 44 |
or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 45 |
or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
| 46 |
-
or
|
| 47 |
)
|
| 48 |
|
| 49 |
|
|
@@ -543,6 +543,32 @@ def _render_error(title: str, details: str) -> tuple[str, str, str, int]:
|
|
| 543 |
)
|
| 544 |
|
| 545 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
def render_session(session_name: str | None, query: str | None = "", page: int | float | None = 1) -> tuple[str, str, str, int]:
|
| 547 |
choices, list_error = _list_sessions_cached()
|
| 548 |
if not choices:
|
|
@@ -601,8 +627,8 @@ def previous_page(session_name: str | None, query: str | None, page: int | float
|
|
| 601 |
def refresh_sessions() -> tuple[Any, str, str, str, int, str]:
|
| 602 |
_list_sessions_cached.cache_clear()
|
| 603 |
choices = _session_choices()
|
| 604 |
-
value =
|
| 605 |
-
summary, transcript, page_info, page =
|
| 606 |
return gr.update(choices=choices, value=value), summary, transcript, page_info, page, ""
|
| 607 |
|
| 608 |
|
|
@@ -1103,8 +1129,8 @@ html, body, .gradio-container {
|
|
| 1103 |
|
| 1104 |
def build_app() -> gr.Blocks:
|
| 1105 |
choices = _session_choices()
|
| 1106 |
-
default =
|
| 1107 |
-
initial_summary, initial_transcript, initial_page_info, initial_page =
|
| 1108 |
|
| 1109 |
with gr.Blocks(title=APP_TITLE, fill_width=True) as demo:
|
| 1110 |
with gr.Row(elem_id="ct-app", elem_classes=["ct-shell"]):
|
|
@@ -1129,6 +1155,7 @@ def build_app() -> gr.Blocks:
|
|
| 1129 |
max_lines=1,
|
| 1130 |
)
|
| 1131 |
filter_button = gr.Button("Filter", variant="primary")
|
|
|
|
| 1132 |
refresh_button = gr.Button("Refresh file list")
|
| 1133 |
page_state = gr.State(initial_page)
|
| 1134 |
page_info = gr.Markdown(initial_page_info, elem_classes=["ct-page-info"])
|
|
@@ -1147,6 +1174,13 @@ def build_app() -> gr.Blocks:
|
|
| 1147 |
api_name="load_session",
|
| 1148 |
show_progress="minimal",
|
| 1149 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1150 |
filter_button.click(
|
| 1151 |
fn=filter_session,
|
| 1152 |
inputs=[session, search],
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
|
| 41 |
+
def _hub_token() -> str | None:
|
| 42 |
return (
|
| 43 |
os.environ.get("HF_TOKEN")
|
| 44 |
or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 45 |
or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
| 46 |
+
or None
|
| 47 |
)
|
| 48 |
|
| 49 |
|
|
|
|
| 543 |
)
|
| 544 |
|
| 545 |
|
| 546 |
+
def _initial_view(choices: list[str]) -> tuple[str, str, str, int]:
|
| 547 |
+
choices_label = f"{len(choices):,} session files available" if choices else "No session files available"
|
| 548 |
+
summary = (
|
| 549 |
+
'<section class="summary-panel">'
|
| 550 |
+
'<div class="summary-topline">'
|
| 551 |
+
"<div><h1>Select a session</h1>"
|
| 552 |
+
f"<p>{_escape(choices_label)} from {DATASET_REPO}</p></div>"
|
| 553 |
+
'<div class="repo-pill">private dataset</div>'
|
| 554 |
+
"</div>"
|
| 555 |
+
'<div class="metrics-grid">'
|
| 556 |
+
f'{_metric("Startup mode", "metadata only")}'
|
| 557 |
+
f'{_metric("Files listed", _fmt_number(len(choices)))}'
|
| 558 |
+
f'{_metric("Downloads", "on demand")}'
|
| 559 |
+
f'{_metric("Page size", _fmt_number(PAGE_SIZE))}'
|
| 560 |
+
"</div>"
|
| 561 |
+
"</section>"
|
| 562 |
+
)
|
| 563 |
+
transcript = (
|
| 564 |
+
'<section class="empty-state">'
|
| 565 |
+
"<h2>No session loaded yet</h2>"
|
| 566 |
+
"<p>Choose a session in the sidebar and select Load session. Files are downloaded lazily.</p>"
|
| 567 |
+
"</section>"
|
| 568 |
+
)
|
| 569 |
+
return summary, transcript, "No session file downloaded yet.", 1
|
| 570 |
+
|
| 571 |
+
|
| 572 |
def render_session(session_name: str | None, query: str | None = "", page: int | float | None = 1) -> tuple[str, str, str, int]:
|
| 573 |
choices, list_error = _list_sessions_cached()
|
| 574 |
if not choices:
|
|
|
|
| 627 |
def refresh_sessions() -> tuple[Any, str, str, str, int, str]:
|
| 628 |
_list_sessions_cached.cache_clear()
|
| 629 |
choices = _session_choices()
|
| 630 |
+
value = None
|
| 631 |
+
summary, transcript, page_info, page = _initial_view(choices)
|
| 632 |
return gr.update(choices=choices, value=value), summary, transcript, page_info, page, ""
|
| 633 |
|
| 634 |
|
|
|
|
| 1129 |
|
| 1130 |
def build_app() -> gr.Blocks:
|
| 1131 |
choices = _session_choices()
|
| 1132 |
+
default = None
|
| 1133 |
+
initial_summary, initial_transcript, initial_page_info, initial_page = _initial_view(choices)
|
| 1134 |
|
| 1135 |
with gr.Blocks(title=APP_TITLE, fill_width=True) as demo:
|
| 1136 |
with gr.Row(elem_id="ct-app", elem_classes=["ct-shell"]):
|
|
|
|
| 1155 |
max_lines=1,
|
| 1156 |
)
|
| 1157 |
filter_button = gr.Button("Filter", variant="primary")
|
| 1158 |
+
load_button = gr.Button("Load session")
|
| 1159 |
refresh_button = gr.Button("Refresh file list")
|
| 1160 |
page_state = gr.State(initial_page)
|
| 1161 |
page_info = gr.Markdown(initial_page_info, elem_classes=["ct-page-info"])
|
|
|
|
| 1174 |
api_name="load_session",
|
| 1175 |
show_progress="minimal",
|
| 1176 |
)
|
| 1177 |
+
load_button.click(
|
| 1178 |
+
fn=load_session,
|
| 1179 |
+
inputs=session,
|
| 1180 |
+
outputs=[summary, transcript, page_info, page_state, search],
|
| 1181 |
+
api_name=False,
|
| 1182 |
+
show_progress="minimal",
|
| 1183 |
+
)
|
| 1184 |
filter_button.click(
|
| 1185 |
fn=filter_session,
|
| 1186 |
inputs=[session, search],
|