Add files via upload

This commit is contained in:
pliny
2026-03-08 13:02:53 -07:00
committed by GitHub
parent 346db3d59d
commit 526cfb8943
4 changed files with 17 additions and 13 deletions
+9 -8
View File
@@ -346,7 +346,7 @@ METHODS = {
# ── Community Hub push ────────────────────────────────────────────────
# Shared org + token so users can auto-push without their own HF_TOKEN.
# Set OBLITERATUS_HUB_TOKEN as a Space secret with write access to the org.
_HUB_COMMUNITY_ORG = os.environ.get("OBLITERATUS_HUB_ORG", "OBLITERATUS-community")
_HUB_COMMUNITY_ORG = os.environ.get("OBLITERATUS_HUB_ORG", "OBLITERATUS")
_HUB_COMMUNITY_TOKEN = os.environ.get("OBLITERATUS_HUB_TOKEN")
# Import preset configs for Advanced Settings defaults
@@ -477,10 +477,10 @@ def _validate_hub_repo(hub_repo: str) -> str:
"Invalid repo format — use `username/model-name` "
"(letters, numbers, hyphens, dots only)"
)
if not os.environ.get("HF_TOKEN") and not _HUB_COMMUNITY_TOKEN:
if not os.environ.get("HF_TOKEN") and not os.environ.get("HF_PUSH_TOKEN") and not _HUB_COMMUNITY_TOKEN:
warnings.append(
"No Hub token available — push will fail. "
"Set HF_TOKEN or OBLITERATUS_HUB_TOKEN."
"Set HF_PUSH_TOKEN, HF_TOKEN, or OBLITERATUS_HUB_TOKEN."
)
if warnings:
return "**Warning:** " + " | ".join(warnings)
@@ -622,11 +622,11 @@ def push_session_to_hub(
# Resolve token
token = hub_token_input.strip() if hub_token_input else None
if not token:
token = os.environ.get("HF_TOKEN") or _HUB_COMMUNITY_TOKEN
token = os.environ.get("HF_PUSH_TOKEN") or os.environ.get("HF_TOKEN") or _HUB_COMMUNITY_TOKEN
if not token:
yield (
"**Error:** No Hub token available. Enter a token above, "
"or set `HF_TOKEN` / `OBLITERATUS_HUB_TOKEN` as an environment variable.",
"or set `HF_PUSH_TOKEN`, `HF_TOKEN`, or `OBLITERATUS_HUB_TOKEN` as an environment variable.",
"",
)
return
@@ -1875,12 +1875,12 @@ def obliterate(model_choice: str, method_choice: str,
# Early validation: gated model access
from obliteratus.presets import is_gated
if is_gated(model_id) and not os.environ.get("HF_TOKEN"):
if is_gated(model_id) and not (os.environ.get("HF_TOKEN") or os.environ.get("HF_PUSH_TOKEN")):
yield (
f"**Error: Gated model requires authentication.**\n\n"
f"`{model_id}` is a gated HuggingFace repo. To use it:\n\n"
f"1. **Accept the license** at [huggingface.co/{model_id}](https://huggingface.co/{model_id})\n"
f"2. **Set HF_TOKEN** in your Space secrets (Settings → Variables and secrets)\n"
f"2. **Set HF_TOKEN** (or `HF_PUSH_TOKEN`) in your Space secrets (Settings → Variables and secrets)\n"
f" or locally: `export HF_TOKEN=hf_...`\n\n"
f"Get your token at [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)\n\n"
f"Alternatively, choose a non-gated model (those without the \U0001f512 icon).",
@@ -4840,7 +4840,7 @@ with the **-OBLITERATED** tag.
label="HF Token (optional)",
placeholder="hf_...",
type="password",
info="Leave blank to use HF_TOKEN env var or community token",
info="Leave blank to use HF_PUSH_TOKEN / HF_TOKEN env var or community token",
)
push_repo_warning = gr.Markdown("")
@@ -4994,6 +4994,7 @@ To opt out, set the environment variable `OBLITERATUS_TELEMETRY=0` before launch
diag.append(f"- On HF Spaces: `{_ON_HF_SPACES}`")
diag.append(f"- Repo: `{_TELEMETRY_REPO or '(not set)'}`")
diag.append(f"- HF_TOKEN set: `{bool(os.environ.get('HF_TOKEN'))}`")
diag.append(f"- HF_PUSH_TOKEN set: `{bool(os.environ.get('HF_PUSH_TOKEN'))}`")
diag.append(f"- Local file: `{TELEMETRY_FILE}`")
diag.append(f"- Local file exists: `{TELEMETRY_FILE.exists()}`")
n_records = len(read_telemetry()) if TELEMETRY_FILE.exists() else 0
+2 -1
View File
@@ -6069,7 +6069,8 @@ class AbliterationPipeline:
if self.push_to_hub:
from huggingface_hub import HfApi
api = HfApi(token=self.hub_token) if self.hub_token else HfApi()
_fallback_token = os.environ.get("HF_PUSH_TOKEN") or os.environ.get("HF_TOKEN") or None
api = HfApi(token=self.hub_token) if self.hub_token else (HfApi(token=_fallback_token) if _fallback_token else HfApi())
# Resolve "auto" → {namespace}/{short_model}-OBLITERATED
if self.push_to_hub == "auto":
+3 -3
View File
@@ -325,7 +325,7 @@ def _ensure_hub_repo(repo_id: str) -> bool:
return True
try:
from huggingface_hub import HfApi
api = HfApi(token=os.environ.get("HF_TOKEN"))
api = HfApi(token=os.environ.get("HF_PUSH_TOKEN") or os.environ.get("HF_TOKEN"))
# First try create_repo (works if we own the namespace)
try:
api.create_repo(
@@ -380,7 +380,7 @@ def _sync_to_hub_bg() -> None:
from huggingface_hub import HfApi
if not _ensure_hub_repo(repo):
return
api = HfApi(token=os.environ.get("HF_TOKEN"))
api = HfApi(token=os.environ.get("HF_PUSH_TOKEN") or os.environ.get("HF_TOKEN"))
slug = _instance_slug()
api.upload_file(
path_or_fileobj=str(TELEMETRY_FILE),
@@ -869,7 +869,7 @@ def push_to_hub(repo_id: str | None = None) -> bool:
if not _ensure_hub_repo(repo):
return False
api = HfApi(token=os.environ.get("HF_TOKEN"))
api = HfApi(token=os.environ.get("HF_PUSH_TOKEN") or os.environ.get("HF_TOKEN"))
slug = _instance_slug()
api.upload_file(
path_or_fileobj=str(TELEMETRY_FILE),
+3 -1
View File
@@ -17,6 +17,7 @@ from __future__ import annotations
import gc
import json
import math
import os
import shutil
import time
from dataclasses import dataclass, field
@@ -1460,7 +1461,8 @@ class TourneyRunner:
self.log(f"\nPushing winner to Hub: {repo_id}")
api = HfApi()
_token = os.environ.get("HF_PUSH_TOKEN") or os.environ.get("HF_TOKEN") or None
api = HfApi(token=_token) if _token else HfApi()
api.create_repo(repo_id, exist_ok=True)
# Write model card