Update app.py
Browse files
app.py
CHANGED
|
@@ -281,6 +281,42 @@ hive_base.__dict__["__name__"] = "hive_base"
|
|
| 281 |
exec(compile(_HIVE_BASE_SOURCE, "hive_tinyllama_hf.py", "exec"), hive_base.__dict__)
|
| 282 |
sys.modules["hive_base"] = hive_base
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
# ---------- Tutor+ Layer & Curves builder (no UI) ----------
|
| 285 |
try:
|
| 286 |
import numpy as np
|
|
@@ -648,7 +684,7 @@ if __name__ == "__main__":
|
|
| 648 |
|
| 649 |
# Respect platform port if provided
|
| 650 |
port = int(os.getenv("PORT", "7860"))
|
| 651 |
-
ui.queue().launch(server_name="0.0.0.0", server_port=port)
|
| 652 |
else:
|
| 653 |
# CLI mode when a TTY exists
|
| 654 |
print("Hive (Original-first, Tutor+ • SAFE v5 BACKGROUND) ready. Type to chat.")
|
|
@@ -661,3 +697,4 @@ if __name__ == "__main__":
|
|
| 661 |
# If the CLI loop ended because stdin vanished, keep app alive
|
| 662 |
if HEADLESS:
|
| 663 |
run_headless_wait()
|
|
|
|
|
|
| 281 |
exec(compile(_HIVE_BASE_SOURCE, "hive_tinyllama_hf.py", "exec"), hive_base.__dict__)
|
| 282 |
sys.modules["hive_base"] = hive_base
|
| 283 |
|
| 284 |
+
# ---------- Compatibility Monkey Patch for Hive.chat ----------
|
| 285 |
+
# Some UI callbacks may call Hive.chat(...) without the required keyword-only
|
| 286 |
+
# args added in newer versions. Patch it so defaults are injected, preventing
|
| 287 |
+
# errors like: Hive.chat() missing 'effective_role' and 'caller_id'.
|
| 288 |
+
try:
|
| 289 |
+
DEFAULT_EFFECTIVE_ROLE = os.getenv("EFFECTIVE_ROLE", "user")
|
| 290 |
+
DEFAULT_CALLER_ID_CLI = os.getenv("CALLER_ID_CLI", "cli")
|
| 291 |
+
DEFAULT_CALLER_ID_UI = os.getenv("CALLER_ID_UI", "ui")
|
| 292 |
+
|
| 293 |
+
if hasattr(hive_base, "Hive"):
|
| 294 |
+
_Hive = hive_base.Hive
|
| 295 |
+
if hasattr(_Hive, "chat"):
|
| 296 |
+
_orig_chat = _Hive.chat
|
| 297 |
+
|
| 298 |
+
def _chat_compat(self, *args, **kwargs):
|
| 299 |
+
# Inject defaults only if missing
|
| 300 |
+
if "effective_role" not in kwargs or kwargs.get("effective_role") is None:
|
| 301 |
+
kwargs["effective_role"] = DEFAULT_EFFECTIVE_ROLE
|
| 302 |
+
if "caller_id" not in kwargs or kwargs.get("caller_id") is None:
|
| 303 |
+
# Prefer UI caller id if we are in the web app
|
| 304 |
+
if os.getenv("RUNNING_IN_UI", "0") == "1":
|
| 305 |
+
kwargs["caller_id"] = DEFAULT_CALLER_ID_UI
|
| 306 |
+
else:
|
| 307 |
+
kwargs["caller_id"] = DEFAULT_CALLER_ID_CLI
|
| 308 |
+
return _orig_chat(self, *args, **kwargs)
|
| 309 |
+
|
| 310 |
+
# Tag to avoid double-patching
|
| 311 |
+
if getattr(_Hive.chat, "_compat_patched", False) is False:
|
| 312 |
+
_chat_compat._compat_patched = True
|
| 313 |
+
_Hive.chat = _chat_compat
|
| 314 |
+
except Exception as _e:
|
| 315 |
+
# Do not fail the app if patching isn't possible
|
| 316 |
+
pass
|
| 317 |
+
# -------------------------------------------------------------
|
| 318 |
+
|
| 319 |
+
|
| 320 |
# ---------- Tutor+ Layer & Curves builder (no UI) ----------
|
| 321 |
try:
|
| 322 |
import numpy as np
|
|
|
|
| 684 |
|
| 685 |
# Respect platform port if provided
|
| 686 |
port = int(os.getenv("PORT", "7860"))
|
| 687 |
+
os.environ.setdefault("RUNNING_IN_UI","1"); ui.queue().launch(server_name="0.0.0.0", server_port=port)
|
| 688 |
else:
|
| 689 |
# CLI mode when a TTY exists
|
| 690 |
print("Hive (Original-first, Tutor+ • SAFE v5 BACKGROUND) ready. Type to chat.")
|
|
|
|
| 697 |
# If the CLI loop ended because stdin vanished, keep app alive
|
| 698 |
if HEADLESS:
|
| 699 |
run_headless_wait()
|
| 700 |
+
|