Spaces:
Running
Running
Update UI to include user orgs
Browse files
app.py
CHANGED
|
@@ -7,11 +7,36 @@ from huggingface_hub import HfApi
|
|
| 7 |
from get_dataset_stats import get_dataset_stats
|
| 8 |
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
"""
|
| 12 |
api = HfApi()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
repo_ids = [getattr(d, "id", None) or getattr(d, "repo_id", None) for d in items]
|
| 16 |
repo_ids = [r for r in repo_ids if r]
|
| 17 |
# Remove duplicates while preserving order
|
|
@@ -62,23 +87,29 @@ def fetch_stats_for_selected(selected_datasets: List[str], progress=gr.Progress(
|
|
| 62 |
with gr.Blocks(title="LeRobot Dataset Stats Viewer") as demo:
|
| 63 |
gr.Markdown("**View statistics for Hugging Face datasets (LeRobot format).**")
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
with gr.Row():
|
| 69 |
-
|
| 70 |
-
label="Organization",
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 73 |
)
|
| 74 |
-
load_btn = gr.Button("Load Datasets")
|
| 75 |
|
| 76 |
dataset_checkboxes = gr.CheckboxGroup(
|
| 77 |
label="Select datasets",
|
| 78 |
-
choices=
|
| 79 |
interactive=True,
|
| 80 |
)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
fetch_btn = gr.Button("Fetch Statistics", variant="primary")
|
| 83 |
|
| 84 |
stats_output = gr.Markdown(
|
|
@@ -91,9 +122,35 @@ with gr.Blocks(title="LeRobot Dataset Stats Viewer") as demo:
|
|
| 91 |
results = search_datasets_fn(org_name)
|
| 92 |
return gr.update(choices=results, value=[])
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
load_btn.click(
|
| 95 |
load_datasets_from_org,
|
| 96 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
outputs=dataset_checkboxes,
|
| 98 |
)
|
| 99 |
|
|
|
|
| 7 |
from get_dataset_stats import get_dataset_stats
|
| 8 |
|
| 9 |
|
| 10 |
+
def get_user_organizations() -> List[str]:
|
| 11 |
+
"""Get organizations the user is part of"""
|
| 12 |
api = HfApi()
|
| 13 |
+
token = os.environ.get("HF_TOKEN")
|
| 14 |
+
try:
|
| 15 |
+
# Get the user's info
|
| 16 |
+
user_info = api.whoami(token=token)
|
| 17 |
+
username = user_info["name"]
|
| 18 |
+
|
| 19 |
+
# Get organizations the user is part of
|
| 20 |
+
orgs = [username] # Include user's own namespace
|
| 21 |
+
if "orgs" in user_info:
|
| 22 |
+
orgs.extend([org["name"] for org in user_info["orgs"]])
|
| 23 |
+
|
| 24 |
+
return orgs
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f"Error getting user organizations: {e}")
|
| 27 |
+
return []
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def search_datasets_fn(org_name: str) -> List[str]:
|
| 31 |
+
"""Search for datasets from a specific organization"""
|
| 32 |
+
api = HfApi()
|
| 33 |
+
token = os.environ.get("HF_TOKEN")
|
| 34 |
try:
|
| 35 |
+
if not org_name:
|
| 36 |
+
return []
|
| 37 |
+
|
| 38 |
+
# List datasets for the specific organization/user
|
| 39 |
+
items = api.list_datasets(author=org_name, token=token)
|
| 40 |
repo_ids = [getattr(d, "id", None) or getattr(d, "repo_id", None) for d in items]
|
| 41 |
repo_ids = [r for r in repo_ids if r]
|
| 42 |
# Remove duplicates while preserving order
|
|
|
|
| 87 |
with gr.Blocks(title="LeRobot Dataset Stats Viewer") as demo:
|
| 88 |
gr.Markdown("**View statistics for Hugging Face datasets (LeRobot format).**")
|
| 89 |
|
| 90 |
+
# Get user's organizations
|
| 91 |
+
_user_orgs = get_user_organizations()
|
| 92 |
+
_initial_datasets = search_datasets_fn(_user_orgs[0]) if _user_orgs else []
|
| 93 |
|
| 94 |
with gr.Row():
|
| 95 |
+
org_dropdown = gr.Dropdown(
|
| 96 |
+
label="Select Organization",
|
| 97 |
+
choices=_user_orgs,
|
| 98 |
+
value=_user_orgs[0] if _user_orgs else None,
|
| 99 |
+
interactive=True,
|
| 100 |
)
|
| 101 |
+
load_btn = gr.Button("Load Datasets", variant="secondary")
|
| 102 |
|
| 103 |
dataset_checkboxes = gr.CheckboxGroup(
|
| 104 |
label="Select datasets",
|
| 105 |
+
choices=_initial_datasets,
|
| 106 |
interactive=True,
|
| 107 |
)
|
| 108 |
|
| 109 |
+
with gr.Row():
|
| 110 |
+
select_all_btn = gr.Button("Select All", size="sm")
|
| 111 |
+
deselect_all_btn = gr.Button("Deselect All", size="sm")
|
| 112 |
+
|
| 113 |
fetch_btn = gr.Button("Fetch Statistics", variant="primary")
|
| 114 |
|
| 115 |
stats_output = gr.Markdown(
|
|
|
|
| 122 |
results = search_datasets_fn(org_name)
|
| 123 |
return gr.update(choices=results, value=[])
|
| 124 |
|
| 125 |
+
def select_all_datasets(current_choices):
|
| 126 |
+
# Get all available choices from the checkbox group
|
| 127 |
+
return current_choices
|
| 128 |
+
|
| 129 |
+
def deselect_all_datasets():
|
| 130 |
+
return []
|
| 131 |
+
|
| 132 |
+
# Load datasets on button click or dropdown change
|
| 133 |
load_btn.click(
|
| 134 |
load_datasets_from_org,
|
| 135 |
+
inputs=org_dropdown,
|
| 136 |
+
outputs=dataset_checkboxes,
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
org_dropdown.change(
|
| 140 |
+
load_datasets_from_org,
|
| 141 |
+
inputs=org_dropdown,
|
| 142 |
+
outputs=dataset_checkboxes,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
# Select/Deselect all buttons
|
| 146 |
+
select_all_btn.click(
|
| 147 |
+
lambda choices: gr.update(value=choices),
|
| 148 |
+
inputs=dataset_checkboxes,
|
| 149 |
+
outputs=dataset_checkboxes,
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
deselect_all_btn.click(
|
| 153 |
+
lambda: gr.update(value=[]),
|
| 154 |
outputs=dataset_checkboxes,
|
| 155 |
)
|
| 156 |
|