Spaces:
Running on Zero
Running on Zero
Composer fallbacks: three distinct verified providers, per-provider timeouts, attempt logging
#7
by multimodalart HF Staff - opened
501 unmodified lines5025035045055065075085095105115124 unmodified lines517518519520521522523524525501 unmodified linesfrom openai import OpenAI# Bounded timeout: a hung provider must fail over, not freeze the UI at the composing step.client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=os.environ["HF_TOKEN"], timeout=60, max_retries=0)last_error = Nonefor model in ("deepseek-ai/DeepSeek-V4-Flash-0731:baseten", "deepseek-ai/DeepSeek-V4-Flash-0731", "deepseek-ai/DeepSeek-V4-Flash-0731:fastest"):try:completion = client.chat.completions.create(model=model,messages=[{"role": "system", "content": system}, {"role": "user", "content": user}],)4 unmodified linesraise ValueError(f"no JSON object in composer reply (finish_reason={completion.choices[0].finish_reason})")return _json.loads(text[start : end + 1])except Exception as e:last_error = eraise gr.Error("The MiniMax-M3 composer is overloaded right now — try again in a moment, ""or write the lyrics and structured prompt directly in the Studio tab.") from last_error501 unmodified lines5025035045055065075085095105115125135145155165175184 unmodified lines523524525526527528529530531532501 unmodified linesfrom openai import OpenAI# Bounded timeout: a hung provider must fail over, not freeze the UI at the composing step.client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=os.environ["HF_TOKEN"], max_retries=0)last_error = None# Three DISTINCT providers, all verified enabled for this account (bare/":fastest" can route to# together, which 403s here and killed the fallbacks). Timeouts sized to measured composer latency.for model, timeout in (("deepseek-ai/DeepSeek-V4-Flash-0731:baseten", 45),("deepseek-ai/DeepSeek-V4-Flash-0731:deepinfra", 75),("deepseek-ai/DeepSeek-V4-Flash-0731:novita", 100),):try:completion = client.with_options(timeout=timeout).chat.completions.create(model=model,messages=[{"role": "system", "content": system}, {"role": "user", "content": user}],)4 unmodified linesraise ValueError(f"no JSON object in composer reply (finish_reason={completion.choices[0].finish_reason})")return _json.loads(text[start : end + 1])except Exception as e:print(f"composer attempt failed ({model}): {type(e).__name__}: {e}", flush=True)last_error = eraise gr.Error("The composer model is overloaded right now — try again in a moment, ""or write the lyrics and structured prompt directly in the Studio tab.") from last_error
app.py+11-4