arthpandeyofficial commited on
Commit
2b4b8b9
·
verified ·
1 Parent(s): 61fabb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -48,7 +48,7 @@ logger = logging.getLogger("fireai")
48
  logging.getLogger("httpx").setLevel(logging.WARNING)
49
  logging.getLogger("httpcore").setLevel(logging.WARNING)
50
 
51
- # Space owner token strictly used for high-speed container asset downloads
52
  HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
53
  os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
54
 
@@ -87,6 +87,7 @@ _plan_lock = threading.Lock()
87
 
88
 
89
  def hub_kwargs() -> dict[str, Any]:
 
90
  return {"token": HF_TOKEN} if HF_TOKEN else {}
91
 
92
 
@@ -181,12 +182,12 @@ def load_model(mode: str) -> dict[str, Any]:
181
  clear_loaded_model()
182
 
183
  repo = MODELS[mode]
184
- logger.info("Loading tokenizer: %s", repo)
185
  tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True, **hub_kwargs())
186
  if tokenizer.pad_token is None:
187
  tokenizer.pad_token = tokenizer.eos_token
188
 
189
- logger.info("Loading %s as NF4 on large slice: %s", mode, repo)
190
  started = time.monotonic()
191
 
192
  model = AutoModelForCausalLM.from_pretrained(
@@ -233,7 +234,7 @@ def history_to_prompt(history: list, mode: str, tokenizer) -> str:
233
  for item in history or []:
234
  if not isinstance(item, dict):
235
  continue
236
- if (item.get("metadata") or {}).get("title") == "Raw thinking":
237
  continue
238
  role = item.get("role")
239
  content = item.get("content")
@@ -323,7 +324,6 @@ def generate_response(
323
  enabled = gr.update(interactive=True)
324
  info = get_account(profile, token)
325
 
326
- # Strictly block unauthenticated calls from using ZeroGPU
327
  if not info["logged_in"]:
328
  history.append(
329
  {
@@ -347,7 +347,7 @@ def generate_response(
347
  history.append({
348
  "role": "assistant",
349
  "content": "Thinking...",
350
- "metadata": {"title": "Raw thinking"},
351
  })
352
  thought_index = len(history) - 1
353
  history.append({
 
48
  logging.getLogger("httpx").setLevel(logging.WARNING)
49
  logging.getLogger("httpcore").setLevel(logging.WARNING)
50
 
51
+ # Enforce Space environment token & hf_transfer for accelerated model downloads
52
  HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
53
  os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
54
 
 
87
 
88
 
89
  def hub_kwargs() -> dict[str, Any]:
90
+ # Always passes HF_TOKEN to authenticate and enable multi-threaded high-speed transfers
91
  return {"token": HF_TOKEN} if HF_TOKEN else {}
92
 
93
 
 
182
  clear_loaded_model()
183
 
184
  repo = MODELS[mode]
185
+ logger.info("Loading tokenizer with HF_TOKEN: %s", repo)
186
  tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True, **hub_kwargs())
187
  if tokenizer.pad_token is None:
188
  tokenizer.pad_token = tokenizer.eos_token
189
 
190
+ logger.info("Loading %s as NF4 on large slice with HF_TOKEN: %s", mode, repo)
191
  started = time.monotonic()
192
 
193
  model = AutoModelForCausalLM.from_pretrained(
 
234
  for item in history or []:
235
  if not isinstance(item, dict):
236
  continue
237
+ if (item.get("metadata") or {}).get("title") in ("Thinking", "Raw thinking"):
238
  continue
239
  role = item.get("role")
240
  content = item.get("content")
 
324
  enabled = gr.update(interactive=True)
325
  info = get_account(profile, token)
326
 
 
327
  if not info["logged_in"]:
328
  history.append(
329
  {
 
347
  history.append({
348
  "role": "assistant",
349
  "content": "Thinking...",
350
+ "metadata": {"title": "Thinking"},
351
  })
352
  thought_index = len(history) - 1
353
  history.append({