Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 65 additions & 109 deletions gsma_dataset_creation/argilla_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import typer
from loguru import logger
from gsma_dataset_creation.clients.argilla_client import get_argilla_client

app = typer.Typer(help="Argilla dataset annotation commands")

Expand Down Expand Up @@ -53,6 +54,9 @@ def upload(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -91,6 +95,7 @@ def upload(
labels=labels,
api_url=api_url,
api_key=api_key,
hf_token=hf_token
)
logger.info(f"✅ Successfully uploaded dataset: {dataset_name}")
except Exception as e:
Expand All @@ -113,6 +118,9 @@ def delete(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -166,6 +174,7 @@ def delete(
workspace=workspace,
api_url=api_url,
api_key=api_key,
hf_token=hf_token
)
logger.info("✅ Successfully deleted dataset")
except Exception as e:
Expand All @@ -188,6 +197,9 @@ def download(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -227,6 +239,7 @@ def download(
workspace=workspace,
api_url=api_url,
api_key=api_key,
hf_token=hf_token,
)
logger.info(f"✅ Successfully downloaded dataset: {dataset_name}")
except Exception as e:
Expand Down Expand Up @@ -277,6 +290,9 @@ def upload_by_subgroup(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
dataset_name_prefix: str = typer.Option(
"gsma_subgroup",
"--dataset-name-prefix",
Expand Down Expand Up @@ -330,7 +346,7 @@ def upload_by_subgroup(
if dataset_path is not None and dataset_repo is not None:
logger.error("❌ Error: Cannot specify both --dataset-path and --dataset-repo")
raise typer.Exit(code=2)

if dataset_path and not dataset_path.exists():
logger.error(f"❌ Dataset path not found: {dataset_path}")
raise typer.Exit(code=2)
Expand Down Expand Up @@ -362,6 +378,7 @@ def upload_by_subgroup(
workspace_name=effective_workspace,
api_url=api_url,
api_key=api_key,
hf_token=hf_token,
)

if dataset_name is None:
Expand All @@ -374,6 +391,8 @@ def upload_by_subgroup(
logger.info(f"🔒 Password: {effective_working_group.lower()}-gsma")
except Exception as e:
logger.error(f"❌ Upload failed: {e}")
import traceback
logger.error(traceback.format_exc())
raise typer.Exit(code=1) from e


Expand All @@ -392,6 +411,9 @@ def delete_workspace(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand All @@ -414,16 +436,6 @@ def delete_workspace(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

# Confirmation prompt
if not force:
confirm = typer.confirm(
Expand All @@ -434,8 +446,8 @@ def delete_workspace(
raise typer.Exit(code=0)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Get workspace
workspace = client.workspaces(name=workspace_name)
Expand Down Expand Up @@ -512,6 +524,9 @@ def add_user(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -567,19 +582,9 @@ def add_user(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Validate all workspaces exist
workspace_objs = []
Expand Down Expand Up @@ -676,6 +681,9 @@ def add_to_workspace(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -706,19 +714,9 @@ def add_to_workspace(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Check if user exists
user = client.users(username=username)
Expand Down Expand Up @@ -778,6 +776,9 @@ def add_users(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -815,19 +816,9 @@ def add_users(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Validate workspace exists
workspace_obj = client.workspaces(name=workspace)
Expand Down Expand Up @@ -917,6 +908,9 @@ def list_users(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -955,19 +949,9 @@ def list_users(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

if workspace:
# Get workspace-specific users
Expand Down Expand Up @@ -1094,6 +1078,9 @@ def track_progress(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -1126,19 +1113,9 @@ def track_progress(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Get workspace
workspace_obj = client.workspaces(name=workspace)
Expand Down Expand Up @@ -1307,6 +1284,9 @@ def list_workspaces(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand All @@ -1332,19 +1312,9 @@ def list_workspaces(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Get all workspaces
workspaces = sorted([ws.name for ws in client.workspaces])
Expand Down Expand Up @@ -1390,6 +1360,9 @@ def list_datasets(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -1419,19 +1392,9 @@ def list_datasets(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Get workspace
workspace_obj = client.workspaces(name=workspace)
Expand Down Expand Up @@ -1489,6 +1452,9 @@ def delete_user(
api_key: str | None = typer.Option(
None, "--api-key", help="Argilla API key (defaults to ARGILLA_API_KEY env var)"
),
hf_token: str | None = typer.Option(
None, "--hf-token", help="HuggingFace API token for private HF spaces (defaults to HF_TOKEN env var)"
),
logger_level: str = typer.Option("INFO", "--logger-level", help="Logging level"),
) -> None:
"""
Expand Down Expand Up @@ -1518,16 +1484,6 @@ def delete_user(
logger.error("Install with: pip install argilla")
raise typer.Exit(code=1) from e

# Get API credentials
api_url = api_url or os.getenv("ARGILLA_API_URL")
api_key = api_key or os.getenv("ARGILLA_API_KEY")

if not api_url or not api_key:
logger.error(
"❌ Argilla credentials not found. Set ARGILLA_API_URL and ARGILLA_API_KEY environment variables or use --api-url and --api-key options."
)
raise typer.Exit(code=1)

# Confirmation prompt
if not force:
confirm = typer.confirm(
Expand All @@ -1538,8 +1494,8 @@ def delete_user(
raise typer.Exit(code=0)

try:
# Create client
client = rg.Argilla(api_url=api_url, api_key=api_key)
# Initialising an Argilla client
client = get_argilla_client(api_url, api_key, hf_token)

# Find user
user = client.users(username=username)
Expand Down
Loading
Loading