Rajan Sharma commited on
Commit
047cd92
·
verified ·
1 Parent(s): f5e795d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -50,7 +50,6 @@ HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN") or os.getenv("HF_TOKEN")
50
 
51
  COHERE_API_KEY = os.getenv("COHERE_API_KEY")
52
  USE_HOSTED_COHERE = bool(COHERE_API_KEY and _HAS_COHERE)
53
- COHERE_TIMEOUT_SEC = float(os.getenv("COHERE_TIMEOUT_SEC", "30"))
54
 
55
  MAX_NEW_TOKENS = int(os.getenv("MAX_NEW_TOKENS", "512"))
56
 
@@ -104,7 +103,8 @@ def _history_to_prompt(message, history):
104
  # ---------- Cohere path (default first; fallback to local on failure) ----------
105
  _co_client = None
106
  if USE_HOSTED_COHERE:
107
- _co_client = cohere.Client(api_key=COHERE_API_KEY, timeout=COHERE_TIMEOUT_SEC)
 
108
 
109
  def cohere_chat(message, history):
110
  """
@@ -305,7 +305,6 @@ def clarityops_reply(user_msg, history, tz, uploaded_files_paths):
305
  # Surface the error in-chat so the websocket doesn’t die silently
306
  err = f"Error: {e}"
307
  try:
308
- # Optionally log stack for ops
309
  traceback.print_exc()
310
  except Exception:
311
  pass
@@ -349,15 +348,14 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
349
 
350
  # --- Background warmup so first message doesn't time out ---
351
  def _warmup():
 
352
  def _bg():
353
  try:
354
- # Preload local fallback model quietly (download may be large)
355
- load_local_model()
356
  except Exception:
357
  pass
358
  threading.Thread(target=_bg, daemon=True).start()
359
- return ""
360
- demo.load(_warmup, None, None) # fire-and-forget
361
 
362
  gr.Markdown("# ClarityOps Augmented Decision AI")
363
 
@@ -402,7 +400,6 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
402
  new_history = clarityops_reply(user_msg.strip(), history or [], tz, up_paths or [])
403
  return new_history, "", new_history
404
  except Exception as e:
405
- # Return the error in the chat so UI doesn't show a websocket failure
406
  err = f"Error: {e}"
407
  try:
408
  traceback.print_exc()
@@ -430,8 +427,8 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
430
 
431
  if __name__ == "__main__":
432
  port = int(os.environ.get("PORT", "7860"))
433
- # max_threads gives the worker pool; leave as-is unless you need more parallelism
434
  demo.launch(server_name="0.0.0.0", server_port=port, show_api=False, max_threads=8)
435
 
436
 
437
 
 
 
50
 
51
  COHERE_API_KEY = os.getenv("COHERE_API_KEY")
52
  USE_HOSTED_COHERE = bool(COHERE_API_KEY and _HAS_COHERE)
 
53
 
54
  MAX_NEW_TOKENS = int(os.getenv("MAX_NEW_TOKENS", "512"))
55
 
 
103
  # ---------- Cohere path (default first; fallback to local on failure) ----------
104
  _co_client = None
105
  if USE_HOSTED_COHERE:
106
+ # Avoid passing unsupported args; some SDK builds don't accept timeout=
107
+ _co_client = cohere.Client(api_key=COHERE_API_KEY)
108
 
109
  def cohere_chat(message, history):
110
  """
 
305
  # Surface the error in-chat so the websocket doesn’t die silently
306
  err = f"Error: {e}"
307
  try:
 
308
  traceback.print_exc()
309
  except Exception:
310
  pass
 
348
 
349
  # --- Background warmup so first message doesn't time out ---
350
  def _warmup():
351
+ # IMPORTANT: no return value, because we register with outputs=None
352
  def _bg():
353
  try:
354
+ load_local_model() # Preload local fallback quietly
 
355
  except Exception:
356
  pass
357
  threading.Thread(target=_bg, daemon=True).start()
358
+ demo.load(_warmup) # no inputs, no outputs
 
359
 
360
  gr.Markdown("# ClarityOps Augmented Decision AI")
361
 
 
400
  new_history = clarityops_reply(user_msg.strip(), history or [], tz, up_paths or [])
401
  return new_history, "", new_history
402
  except Exception as e:
 
403
  err = f"Error: {e}"
404
  try:
405
  traceback.print_exc()
 
427
 
428
  if __name__ == "__main__":
429
  port = int(os.environ.get("PORT", "7860"))
 
430
  demo.launch(server_name="0.0.0.0", server_port=port, show_api=False, max_threads=8)
431
 
432
 
433
 
434
+