akhaliq HF Staff commited on
Commit
6885314
·
1 Parent(s): 1b8ccaf

Skip the LLM compose step for logged-out visitors

Browse files

compose_song falls back to the built-in demo lyrics + structured caption
when no OAuth token and no HF_TOKEN secret are available, so anonymous
users can still run the generation pipeline.

Files changed (2) hide show
  1. README.md +3 -1
  2. app.py +5 -4
README.md CHANGED
@@ -25,7 +25,9 @@ wav) → Output Song / Seed Used / Stats → `make_video` (CPU ffmpeg visualizer
25
  Seed, randomize-seed, flow-matching steps, guidance scale, duration, and video title are editable reference
26
  nodes. `hf_oauth: true` lets the owner edit the canvas; visitors sign in to run the pipeline, and the
27
  `compose_song` LLM step uses the visitor's own OAuth token (`inference-api` scope), so inference bills the
28
- visitor directly. Set an `HF_TOKEN` secret if you want anonymous/local runs to fall back to the owner's token. The original Blocks app
 
 
29
  (with the live-streaming PCM player) is preserved as `app_blocks.py` — workflow fn nodes are plain callables,
30
  so chunk-by-chunk streaming is replaced by a final audio subject.
31
 
 
25
  Seed, randomize-seed, flow-matching steps, guidance scale, duration, and video title are editable reference
26
  nodes. `hf_oauth: true` lets the owner edit the canvas; visitors sign in to run the pipeline, and the
27
  `compose_song` LLM step uses the visitor's own OAuth token (`inference-api` scope), so inference bills the
28
+ visitor directly. For logged-out visitors the LLM step is skipped (it's an add-on) and the pipeline
29
+ generates from the built-in demo lyrics + structured caption; set an `HF_TOKEN` secret to let anonymous
30
+ runs use the owner's token instead. The original Blocks app
31
  (with the live-streaming PCM player) is preserved as `app_blocks.py` — workflow fn nodes are plain callables,
32
  so chunk-by-chunk streaming is replaced by a final audio subject.
33
 
app.py CHANGED
@@ -505,10 +505,7 @@ def _llm_json(system, user, token=None):
505
  # directly); fall back to the Space owner's HF_TOKEN secret for local/anonymous runs.
506
  api_key = getattr(token, "token", None) or os.environ.get("HF_TOKEN")
507
  if not api_key:
508
- raise gr.Error(
509
- "Sign in with Hugging Face to compose (the LLM step bills your own account), "
510
- "or ask the Space owner to add an HF_TOKEN secret."
511
- )
512
  client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=api_key)
513
  completion = client.chat.completions.create(
514
  model="MiniMaxAI/MiniMax-M3:fastest",
@@ -526,6 +523,10 @@ def compose_song(description, duration, token: gr.OAuthToken = None):
526
  if not description.strip():
527
  raise gr.Error("Describe the song you want first.")
528
  data = _llm_json(_COMPOSER_SYSTEM, f"Song description: {description}\nTarget duration: {int(duration)} seconds.", token)
 
 
 
 
529
  return data["lyrics"], data["global_metadata"], data["vocal_details"], data["arrangement"]
530
 
531
 
 
505
  # directly); fall back to the Space owner's HF_TOKEN secret for local/anonymous runs.
506
  api_key = getattr(token, "token", None) or os.environ.get("HF_TOKEN")
507
  if not api_key:
508
+ return None # logged-out visitor, no owner secret: caller skips the LLM step
 
 
 
509
  client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=api_key)
510
  completion = client.chat.completions.create(
511
  model="MiniMaxAI/MiniMax-M3:fastest",
 
523
  if not description.strip():
524
  raise gr.Error("Describe the song you want first.")
525
  data = _llm_json(_COMPOSER_SYSTEM, f"Song description: {description}\nTarget duration: {int(duration)} seconds.", token)
526
+ if data is None:
527
+ # No OAuth token (logged out) and no HF_TOKEN secret: the LLM compose step is an
528
+ # add-on — skip it and generate from the built-in demo lyrics + structured caption.
529
+ return DEFAULT_LYRICS, DEFAULT_GLOBAL, DEFAULT_VOCALS, DEFAULT_ARRANGEMENT
530
  return data["lyrics"], data["global_metadata"], data["vocal_details"], data["arrangement"]
531
 
532