hy-nomas / app.py
akhaliq's picture
akhaliq HF Staff
Remove LLM prompt enhancer: route turns through the module's deterministic structured-prompt builders so no HF token is needed
6d6540c verified
Raw History Blame Contribute Delete
3.44 kB
"""Hy-Nomas Live — Tencent-styled studio.
Thin launcher around the upstream demo backend. The full Hy-Nomas Live server
(gr.Server + the hymm/ pipeline code) is vendored in hugging-apps/tencent-hy-nomas;
this Space downloads it at startup, overlays this repo's Tencent-styled index.html,
then execs the upstream app unchanged. All session logic, ZeroGPU handling and the
prompt enhancer behave exactly as in the original Space.
"""
import os
import sys
from pathlib import Path
from huggingface_hub import snapshot_download
UPSTREAM_REPO = "hugging-apps/tencent-hy-nomas"
HERE = Path(__file__).resolve().parent
WORK = Path(os.environ.get("NOMAS_UPSTREAM_DIR", "/tmp/hy_nomas_upstream"))
def main() -> None:
if not (WORK / "app.py").exists():
print(f"[launcher] fetching upstream demo from {UPSTREAM_REPO} …", flush=True)
snapshot_download(
UPSTREAM_REPO,
repo_type="space",
local_dir=str(WORK),
ignore_patterns=["__pycache__/*", "*.pyc"],
)
# Overlay the Tencent-styled front-end (the upstream app serves ROOT/index.html).
(WORK / "index.html").write_text((HERE / "index.html").read_text(encoding="utf-8"), encoding="utf-8")
print("[launcher] Tencent front-end installed; starting Hy-Nomas Live …", flush=True)
# Remove the LLM prompt enhancer (it calls Inference Providers and needs an
# HF token). The enhancer module ships deterministic builders for the same
# EnhancedPrompt dataclass; route every turn through them instead.
upstream_app = WORK / "app.py"
src = upstream_app.read_text(encoding="utf-8")
patches = (
(
"from apps.kimi_k3_prompt_enhancer import ( # noqa: E402\n"
" KimiK3Client,\n"
" OnlinePromptEnhancer,\n"
" PromptEnhancementError,\n"
")",
"from apps.kimi_k3_prompt_enhancer import ( # noqa: E402\n"
" KimiK3Client,\n"
" OnlinePromptEnhancer,\n"
" PromptEnhancementError,\n"
" build_local_fallback_prompt,\n"
" build_minimal_camera_prompt,\n"
")",
),
(
" enhancer = OPENING_ENHANCER if sess.pe_session is None else TURN_ENHANCER\n"
' enhanced = enhancer.enhance(pe_input, sess.pe_session, reasoning_effort="none", seed=req["seed"])',
" if pe_input.get(\"camera_controlled\"):\n"
" enhanced = build_minimal_camera_prompt(pe_input, sess.pe_session, fps=FPS, duration_seconds=float(turn[\"seconds\"]))\n"
" else:\n"
" enhanced = build_local_fallback_prompt(pe_input, sess.pe_session, fps=FPS, duration_seconds=float(turn[\"seconds\"]))",
),
)
applied = 0
for old, new in patches:
if src.count(old) == 1:
src = src.replace(old, new)
applied += 1
if applied == len(patches):
upstream_app.write_text(src, encoding="utf-8")
print("[launcher] prompt enhancer removed: direct structured prompts (no HF token needed)", flush=True)
else:
print(f"[launcher] WARNING: upstream app.py changed ({applied}/{len(patches)} patches applied); prompt enhancer left as-is", flush=True)
os.chdir(WORK)
os.execv(sys.executable, [sys.executable, str(WORK / "app.py")])
if __name__ == "__main__":
main()