Spaces:
Running
Running
Joseph Pollack
commited on
adds demo
Browse files
__pycache__/interface.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/interface.cpython-313.pyc and b/__pycache__/interface.cpython-313.pyc differ
|
|
|
interface.py
CHANGED
|
@@ -47,6 +47,43 @@ def get_username_from_token(token: str) -> Optional[str]:
|
|
| 47 |
return None
|
| 48 |
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def run_command_stream(args: list[str], env: Dict[str, str], cwd: Optional[Path] = None) -> Generator[str, None, int]:
|
| 51 |
import subprocess
|
| 52 |
import shlex
|
|
@@ -189,15 +226,13 @@ def _push_dataset_to_hub(jsonl_path: str, repo_name: str, username: str = "") ->
|
|
| 189 |
if not token:
|
| 190 |
return "β No HF_TOKEN found. Set HF_TOKEN environment variable to push datasets."
|
| 191 |
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
-
|
| 195 |
-
if "/" not in repo_name:
|
| 196 |
-
if not username:
|
| 197 |
-
user_info = api.whoami()
|
| 198 |
-
username = user_info.get("name") or user_info.get("username") or ""
|
| 199 |
-
if username:
|
| 200 |
-
repo_name = f"{username}/{repo_name}"
|
| 201 |
|
| 202 |
# Create dataset repository
|
| 203 |
try:
|
|
@@ -410,7 +445,17 @@ def start_voxtral_training(
|
|
| 410 |
write_token = env.get("HF_WRITE_TOKEN") or env.get("HF_TOKEN")
|
| 411 |
read_token = env.get("HF_READ_TOKEN")
|
| 412 |
username = get_username_from_token(write_token or "") or env.get("HF_USERNAME") or ""
|
| 413 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
|
| 415 |
# Collect all logs
|
| 416 |
all_logs = []
|
|
@@ -453,29 +498,28 @@ def start_voxtral_training(
|
|
| 453 |
|
| 454 |
# 2) Push to Hub
|
| 455 |
if push_to_hub:
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
]
|
| 466 |
-
all_logs.append(f"π€ Pushing model to Hugging Face Hub: {repo_name}")
|
| 467 |
-
collect_logs(run_command_stream(push_args, env))
|
| 468 |
-
all_logs.append("β
Model pushed successfully!")
|
| 469 |
|
| 470 |
# 3) Deploy demo Space
|
| 471 |
-
if deploy_demo
|
|
|
|
|
|
|
|
|
|
| 472 |
deploy_args = [
|
| 473 |
str(PROJECT_ROOT / "scripts/deploy_demo_space.py"),
|
| 474 |
"--hf-token", write_token or "",
|
| 475 |
-
"--hf-username",
|
| 476 |
-
"--model-id",
|
| 477 |
"--demo-type", "voxtral",
|
| 478 |
-
"--space-name",
|
| 479 |
]
|
| 480 |
all_logs.append("π Deploying demo Space...")
|
| 481 |
collect_logs(run_command_stream(deploy_args, env))
|
|
|
|
| 47 |
return None
|
| 48 |
|
| 49 |
|
| 50 |
+
def resolve_repo_name(repo_name: str, token: Optional[str] = None, fallback_username: Optional[str] = None) -> str:
|
| 51 |
+
"""
|
| 52 |
+
Resolve a repository name to full format (username/repo).
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
repo_name: Repository name, either short (repo) or full (username/repo)
|
| 56 |
+
token: HF token to get username from (optional)
|
| 57 |
+
fallback_username: Fallback username if token fails (optional)
|
| 58 |
+
|
| 59 |
+
Returns:
|
| 60 |
+
Full repository name in format username/repo
|
| 61 |
+
|
| 62 |
+
Raises:
|
| 63 |
+
ValueError: If username cannot be determined and repo_name is not already full
|
| 64 |
+
"""
|
| 65 |
+
# If already in full format, return as-is
|
| 66 |
+
if "/" in repo_name:
|
| 67 |
+
return repo_name
|
| 68 |
+
|
| 69 |
+
# Try to get username from token
|
| 70 |
+
username = None
|
| 71 |
+
if token:
|
| 72 |
+
username = get_username_from_token(token)
|
| 73 |
+
|
| 74 |
+
# Fallback to environment variable
|
| 75 |
+
if not username:
|
| 76 |
+
username = os.getenv("HF_USERNAME") or fallback_username
|
| 77 |
+
|
| 78 |
+
if not username:
|
| 79 |
+
raise ValueError(
|
| 80 |
+
f"Cannot resolve full repository name for '{repo_name}'. "
|
| 81 |
+
"Please provide a full repository name (username/repo) or set HF_TOKEN/HF_USERNAME."
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
return f"{username}/{repo_name}"
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def run_command_stream(args: list[str], env: Dict[str, str], cwd: Optional[Path] = None) -> Generator[str, None, int]:
|
| 88 |
import subprocess
|
| 89 |
import shlex
|
|
|
|
| 226 |
if not token:
|
| 227 |
return "β No HF_TOKEN found. Set HF_TOKEN environment variable to push datasets."
|
| 228 |
|
| 229 |
+
# Resolve the full repository name consistently
|
| 230 |
+
try:
|
| 231 |
+
repo_name = resolve_repo_name(repo_name, token, username)
|
| 232 |
+
except ValueError as e:
|
| 233 |
+
return f"β {e}"
|
| 234 |
|
| 235 |
+
api = HfApi(token=token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
# Create dataset repository
|
| 238 |
try:
|
|
|
|
| 445 |
write_token = env.get("HF_WRITE_TOKEN") or env.get("HF_TOKEN")
|
| 446 |
read_token = env.get("HF_READ_TOKEN")
|
| 447 |
username = get_username_from_token(write_token or "") or env.get("HF_USERNAME") or ""
|
| 448 |
+
|
| 449 |
+
# Resolve the full repository name for consistency
|
| 450 |
+
try:
|
| 451 |
+
full_repo_name = resolve_repo_name(repo_short, write_token, username)
|
| 452 |
+
except ValueError as e:
|
| 453 |
+
return f"β Error: {e}"
|
| 454 |
+
|
| 455 |
+
# Use the resolved repo name to create a unique output directory
|
| 456 |
+
# Replace slashes with underscores to avoid path issues
|
| 457 |
+
output_dir_name = full_repo_name.replace("/", "_")
|
| 458 |
+
output_dir = PROJECT_ROOT / "outputs" / output_dir_name
|
| 459 |
|
| 460 |
# Collect all logs
|
| 461 |
all_logs = []
|
|
|
|
| 498 |
|
| 499 |
# 2) Push to Hub
|
| 500 |
if push_to_hub:
|
| 501 |
+
push_args = [
|
| 502 |
+
str(PROJECT_ROOT / "scripts/push_to_huggingface.py"),
|
| 503 |
+
"model",
|
| 504 |
+
str(output_dir),
|
| 505 |
+
full_repo_name,
|
| 506 |
+
]
|
| 507 |
+
all_logs.append(f"π€ Pushing model to Hugging Face Hub: {full_repo_name}")
|
| 508 |
+
collect_logs(run_command_stream(push_args, env))
|
| 509 |
+
all_logs.append("β
Model pushed successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
|
| 511 |
# 3) Deploy demo Space
|
| 512 |
+
if deploy_demo:
|
| 513 |
+
# Extract username from full repo name for demo space
|
| 514 |
+
demo_username = full_repo_name.split("/")[0]
|
| 515 |
+
demo_space_name = f"{full_repo_name.split('/')[1]}-demo"
|
| 516 |
deploy_args = [
|
| 517 |
str(PROJECT_ROOT / "scripts/deploy_demo_space.py"),
|
| 518 |
"--hf-token", write_token or "",
|
| 519 |
+
"--hf-username", demo_username,
|
| 520 |
+
"--model-id", full_repo_name,
|
| 521 |
"--demo-type", "voxtral",
|
| 522 |
+
"--space-name", demo_space_name,
|
| 523 |
]
|
| 524 |
all_logs.append("π Deploying demo Space...")
|
| 525 |
collect_logs(run_command_stream(deploy_args, env))
|
templates/spaces/demo_voxtral/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
title: Voxtral ASR Demo
|
| 3 |
emoji: ποΈ
|
| 4 |
colorFrom: indigo
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.42.0
|
| 8 |
app_file: app.py
|
|
|
|
| 2 |
title: Voxtral ASR Demo
|
| 3 |
emoji: ποΈ
|
| 4 |
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.42.0
|
| 8 |
app_file: app.py
|
templates/spaces/demo_voxtral/requirements.txt
CHANGED
|
@@ -4,4 +4,4 @@ transformers
|
|
| 4 |
datasets
|
| 5 |
soundfile
|
| 6 |
librosa
|
| 7 |
-
|
|
|
|
| 4 |
datasets
|
| 5 |
soundfile
|
| 6 |
librosa
|
| 7 |
+
mistral-common
|