Reza2kn commited on
Commit
26e0f70
·
verified ·
1 Parent(s): c4db08d

Redirect hf.space to huggingface.co for ZeroGPU auth

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -8,6 +8,7 @@ import sys
8
  import tempfile
9
  import time
10
  import urllib.request
 
11
  from datetime import datetime
12
  from pathlib import Path
13
  from typing import List, Optional, Tuple
@@ -58,6 +59,15 @@ DEFAULT_ZERO_GPU_SHARD_SIZE = int(
58
  DEFAULT_ZERO_GPU_MAX_SHARDS = int(
59
  os.getenv("CHIZZLER_ZERO_GPU_MAX_SHARDS", "1")
60
  )
 
 
 
 
 
 
 
 
 
61
 
62
 
63
  def log_progress(message: str, level: int = 1, enabled: bool = True) -> None:
@@ -1152,6 +1162,17 @@ def process_dataset_and_push(
1152
  request: gr.Request | None = None,
1153
  progress=gr.Progress(),
1154
  ) -> str:
 
 
 
 
 
 
 
 
 
 
 
1155
  attempts = 0
1156
  while True:
1157
  try:
@@ -1391,6 +1412,20 @@ def gradio_single_file(
1391
 
1392
 
1393
  with gr.Blocks(title="Representation Chizzler") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1394
  gr.Markdown(
1395
  "# Representation Chizzler\n"
1396
  "Two-stage audio processing: VAD-based speech extraction followed by MP-SENet "
 
8
  import tempfile
9
  import time
10
  import urllib.request
11
+ import warnings
12
  from datetime import datetime
13
  from pathlib import Path
14
  from typing import List, Optional, Tuple
 
59
  DEFAULT_ZERO_GPU_MAX_SHARDS = int(
60
  os.getenv("CHIZZLER_ZERO_GPU_MAX_SHARDS", "1")
61
  )
62
+ SPACE_ID = os.getenv("SPACE_ID")
63
+ if SPACE_ID:
64
+ warnings.filterwarnings(
65
+ "ignore",
66
+ message=(
67
+ "LoginButton created outside of a Blocks context\\. "
68
+ "May not work unless you call its `activate\\(\\)` method manually\\."
69
+ ),
70
+ )
71
 
72
 
73
  def log_progress(message: str, level: int = 1, enabled: bool = True) -> None:
 
1162
  request: gr.Request | None = None,
1163
  progress=gr.Progress(),
1164
  ) -> str:
1165
+ if SPACE_ID and request is not None:
1166
+ headers = getattr(request, "headers", None)
1167
+ token_header = None
1168
+ if headers and hasattr(headers, "get"):
1169
+ token_header = headers.get("x-ip-token")
1170
+ if not token_header:
1171
+ log_progress(
1172
+ "ZeroGPU auth header missing. Use the Space on huggingface.co "
1173
+ "to attach your login to ZeroGPU quota.",
1174
+ 2,
1175
+ )
1176
  attempts = 0
1177
  while True:
1178
  try:
 
1412
 
1413
 
1414
  with gr.Blocks(title="Representation Chizzler") as demo:
1415
+ if SPACE_ID:
1416
+ gr.HTML(
1417
+ f"""
1418
+ <script>
1419
+ (() => {{
1420
+ const host = window.location.hostname;
1421
+ if (host.endsWith(".hf.space")) {{
1422
+ const target = "https://huggingface.co/spaces/{SPACE_ID}";
1423
+ window.location.replace(target + window.location.search + window.location.hash);
1424
+ }}
1425
+ }})();
1426
+ </script>
1427
+ """
1428
+ )
1429
  gr.Markdown(
1430
  "# Representation Chizzler\n"
1431
  "Two-stage audio processing: VAD-based speech extraction followed by MP-SENet "