Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse filesFiles changed (3)
- README.md+19-6
- app.pyAdded+473
- requirements.txtAdded+3
123423456788109101112131415161317181920212223242526---title: Flung 8bemoji: 📈colorFrom: yellowtitle: FLUNG 8Bemoji: 🌲colorFrom: greencolorTo: pinksdk: gradiosdk_version: 6.33.0python_version: '3.12'app_file: app.pypinned: falsepython_version: "3.12"startup_duration_timeout: 1hshort_description: Chat with a language flow model, live decoding viewmodels: - black-forest-labs/flung-8blicense: cc-by-nc-4.0---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference# FLUNG 8B: live decoding chat
This is a chat demo for [black-forest-labs/flung-8b](https://huggingface.co/black-forest-labs/flung-8b), a language flow model from Black Forest Labs. FLUNG drafts 128 tokens at once as Gaussian noise and refines all of them in parallel.
The right-hand panel streams every denoising step of the current 128-token block. It shows each token's argmax readout and confidence, the tokens that changed on that step, the noise level `t`, and how many steps each block used before early stop.
The sampler is the authors' `generation_flung.sample_block`, run step for step with the same RNG stream and default settings (64 steps, early stop 4, temperature 0.3, top-p 0.9, seed 1973). The only addition is the visualization hooks.
Paper: [Towards Training Your Language Flow Model from Scratch](https://arxiv.org/abs/2612.06003) (Abdessaied et al., 2026).The weights are a research artifact released under CC BY-NC 4.0 and are not for commercial use.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473import spaces # must come before torch / transformers
import htmlimport importlibimport mathimport randomimport time
import gradio as grimport torchfrom transformers import AutoModel, AutoTokenizer
MODEL_ID = "black-forest-labs/flung-8b"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)model = AutoModel.from_pretrained(MODEL_ID, trust_remote_code=True, dtype=torch.bfloat16).to("cuda").eval()# The authors' sampler lives next to the remote modeling code; reuse its exact primitives.S = importlib.import_module(type(model).__module__.rsplit(".", 1)[0] + ".generation_flung")
END_ID = int(tokenizer.convert_tokens_to_ids(S.END_OF_TURN))EOS_ID = S.EOS_TOKEN_IDBLOCK = S.BLOCK_SIZEFRAME_INTERVAL = 0.06 # seconds between streamed visualization frames_TOK_CACHE: dict[int, str] = {}
# ----------------------------------------------------------------------------- helpersdef _text_of(content) -> str: if isinstance(content, str): return content if isinstance(content, dict): return content.get("text") or content.get("content") or "" if isinstance(content, (list, tuple)): return "".join(_text_of(c) for c in content) return "" if content is None else str(content)
def _tok_str(i: int) -> str: s = _TOK_CACHE.get(i) if s is None: s = tokenizer.decode([i]) _TOK_CACHE[i] = s return s
def _reply(ids: list[int]) -> str: cut = ids[: ids.index(END_ID)] if END_ID in ids else ids return tokenizer.decode(cut, skip_special_tokens=True)
def _chip(i: int, conf: float, age: int, changed: bool, tail: bool) -> str: if i == END_ID: return '<span class="fv-chip fv-end">end</span>' s = _tok_str(i) if i == EOS_ID or s == "": body = "∅" else: body = html.escape(s).replace("\n", '<b class="fv-nl">↵</b><br>') cls = "fv-chip" if tail: cls += " fv-tail" elif changed: cls += " fv-chg" return f'<span class="{cls}" style="--c:{conf:.2f}">{body}</span>'
def render_viz( *, phase: str, block: int = 0, max_blocks: int = 0, step: int = 0, steps: int = 64, t: float = 1.0, ids=None, conf=None, age=None, changed=None, history_blocks=(),) -> str: """HTML for the live-decoding panel (one 128-token block).""" if phase == "idle": return ( '<div class="fv"><div class="fv-top"><span class="fv-live idle"><i></i>live decoding</span>' '<span class="fv-meta">waiting</span></div>' '<div class="fv-empty">Send a message to watch FLUNG draft a 128-token block as pure noise ' "and refine every token in parallel, step by step.</div></div>" ) ids = ids or [] n = len(ids) end_at = ids.index(END_ID) if END_ID in ids else None prog = max(0.0, min(1.0, (1.0 - t) / (1.0 - S.T_MIN))) ticks, chips = [], [] for k in range(n): tail = end_at is not None and k > end_at c = float(conf[k]) if conf is not None else 1.0 ch = bool(changed[k]) if changed is not None else False tcls = "fv-tick" + (" tail" if tail else (" chg" if ch else "")) ticks.append(f'<span class="{tcls}" style="--c:{c:.2f}"></span>') chips.append(_chip(ids[k], c, int(age[k]) if age is not None else 0, ch, tail)) live = "" if phase == "denoising" else " idle" label = {"denoising": "denoising", "done": "complete"}.get(phase, phase) pills = "".join( f'<span class="fv-pill{" cur" if j == block and phase == "denoising" else ""}">' f"B{j + 1}<em>{u} steps</em></span>" for j, u in enumerate(history_blocks) ) if phase == "denoising": pills += f'<span class="fv-pill cur">B{block + 1}<em>step {step}</em></span>' n_changed = int(sum(1 for v in (changed or []) if v)) if changed is not None else 0 return f"""<div class="fv"> <div class="fv-top"> <span class="fv-live{live}"><i></i>{label}</span> <span class="fv-meta">block {block + 1}{f"/{max_blocks}" if max_blocks else ""} · step {step}/{steps}</span> </div> <div class="fv-time"> <span class="fv-tl">noise</span> <div class="fv-track"><div class="fv-fill" style="width:{prog * 100:.1f}%"></div> <div class="fv-knob" style="left:{prog * 100:.1f}%"></div></div> <span class="fv-tl">t = {t:.2f}</span> </div> <div class="fv-ticks">{"".join(ticks)}</div> <div class="fv-block">{"".join(chips)}</div> <div class="fv-foot"> <div class="fv-legend"><span><b class="lg lg-noisy"></b>uncertain</span> <span><b class="lg lg-set"></b>settled</span><span><b class="lg lg-chg"></b>changed this step</span> <span class="fv-count">{n_changed}/{n} tokens moved</span></div> <div class="fv-pills">{pills}</div> </div></div>"""
def render_stats(n_tokens, n_blocks, forwards, secs, seed, steps) -> str: tpf = n_tokens / max(forwards, 1) return ( '<div class="fv-stats">' f"<span><b>{n_tokens}</b> tokens</span><span><b>{n_blocks}</b> block{'s' if n_blocks != 1 else ''}</span>" f"<span><b>{forwards}</b> forward passes</span><span><b>{tpf:.1f}</b> tokens / forward</span>" f"<span><b>{secs:.1f}</b> s</span><span>seed <b>{seed}</b></span><span>{steps} steps/block</span></div>" )
# ----------------------------------------------------------------------------- inferencedef _duration(message, history=None, steps=64, stable_stop=4, temperature=0.3, top_p=0.9, max_new_tokens=1024, seed=1973, randomize_seed=False, *args, **kwargs): blocks = math.ceil(int(max_new_tokens) / BLOCK) return int(min(170, 12 + blocks * int(steps) * 0.035))
@spaces.GPU(duration=_duration)def respond( message: str, history: list | None = None, steps: int = 64, stable_stop: int = 4, temperature: float = 0.3, top_p: float = 0.9, max_new_tokens: int = 1024, seed: int = 1973, randomize_seed: bool = False,): """Chat with FLUNG 8B and stream its block-wise flow denoising.
Args: message: the new user message. history: previous chat turns as a list of {"role", "content"} messages. steps: denoising steps per 128-token block (model default 64). stable_stop: early-stop a block once its argmax readout is unchanged for this many steps (0 = off). temperature: temperature of the clean-state estimate. top_p: nucleus mass of the clean-state estimate. max_new_tokens: reply token budget. seed: random seed. randomize_seed: draw a fresh random seed instead of using `seed`.
Yields: (chat history, live-decoding HTML, stats HTML) """ message = (message or "").strip() if not message: raise gr.Error("Please type a message.") steps, stable_stop = int(steps), min(int(stable_stop), int(steps)) max_new_tokens = int(max_new_tokens) seed = random.randrange(2**31) if randomize_seed else int(seed)
msgs = [] for m in history or []: role = m.get("role") if isinstance(m, dict) else None text = _text_of(m.get("content")) if isinstance(m, dict) else "" if role in ("user", "assistant") and text.strip(): msgs.append({"role": role, "content": text}) msgs.append({"role": "user", "content": message}) chat = [dict(m) for m in msgs] + [{"role": "assistant", "content": ""}]
device = torch.device("cuda") prompt = S.FlungSamplingMixin.render(tokenizer, msgs).to(device) budget = min(max_new_tokens, S.MAX_CONTEXT - prompt.numel()) if budget <= 0: raise gr.Error("This conversation is too long for the 16k-token context. Clear the chat and start again.") max_blocks = math.ceil(budget / BLOCK) gen = torch.Generator(device=device).manual_seed(seed) pad = -prompt.numel() % BLOCK out_ids: list[int] = [] used_steps: list[int] = [] forwards = 0 t0 = time.perf_counter() last_frame = 0.0
with torch.no_grad(), model._autocast(device): caches = S.prefill(model, prompt, pad) while len(out_ids) < budget: b = len(used_steps) start = pad + prompt.numel() + len(out_ids) positions = torch.arange(start, start + min(BLOCK, budget - len(out_ids)), device=device)[None] L = positions.shape[1] # ---- generation_flung.sample_block, step for step (same RNG stream), instrumented ---- x = S.noise(torch.empty(1, L, model.embed_rep_dim, device=device), gen) hint = torch.zeros_like(x) ts = S.time_grid(steps, device) prev_ids, unchanged = None, 0 age = torch.zeros(L, dtype=torch.long, device=device) ids, used = None, steps for i in range(steps): t, t_next = ts[i], ts[i + 1] if float(t) > S.EPS_MIN: x, t = S.sde_backtrack(x, t, t_next, gen) sigma = torch.full(x.shape[:2], float(t), device=device, dtype=torch.float32) logits, _, r = model( x, sigma, self_cond=hint if model.self_conditioning else None, position_ids=positions, decode_caches=caches, t_ref=torch.full_like(sigma, float(t_next)), return_flow=True, ) ids = logits.argmax(dim=-1) if prev_ids is not None: same = ids[0] == prev_ids[0] age = torch.where(same, age + 1, torch.zeros_like(age)) unchanged = unchanged + 1 if bool(same.all()) else 0 changed = (~same).tolist() else: changed = [True] * L last = i == steps - 1 stop = (not last) and stable_stop and unchanged >= stable_stop now = time.perf_counter() if now - last_frame >= FRAME_INTERVAL or last or stop: last_frame = now conf = (logits[0].float() / float(temperature)).softmax(-1).amax(-1).tolist() cur = ids[0].tolist() chat[-1]["content"] = _reply(out_ids + cur) viz = render_viz( phase="denoising", block=b, max_blocks=max_blocks, step=i + 1, steps=steps, t=float(t_next), ids=cur, conf=conf, age=age.tolist(), changed=changed, history_blocks=used_steps, ) yield chat, viz, gr.skip() if last: used = steps break prev_ids = ids x0 = hint = S.clean_estimate(model, logits, float(temperature), float(top_p)) if float(t_next) > S.EPS_MIN: x = (1.0 - t_next) * x0 + t_next * S.noise(x, gen) else: x = x + ((x - x0) / t.clamp(min=S.EPS_MIN) + S.FLOW_RESIDUAL_SCALE * r.float()) * (t_next - t) if stop: used = i + 1 break # ---- commit the block ---- block_ids = ids[0].tolist() out_ids.extend(block_ids) used_steps.append(used) forwards += used if END_ID in block_ids or len(out_ids) >= budget: break S.run_clean(model, ids, positions, caches)
secs = time.perf_counter() - t0 reply = _reply(out_ids).strip() chat[-1]["content"] = reply n_tok = len(out_ids[: out_ids.index(END_ID)] if END_ID in out_ids else out_ids) print(f"[flung] {n_tok} tok, {len(used_steps)} blocks, {forwards} fwd, {secs:.1f}s, steps={steps}", flush=True) final_block = out_ids[-len(block_ids):] viz = render_viz( phase="done", block=len(used_steps) - 1, max_blocks=len(used_steps), step=used_steps[-1], steps=steps, t=S.T_MIN, ids=final_block, conf=None, changed=None, history_blocks=used_steps, ) yield chat, viz, render_stats(n_tok, len(used_steps), forwards, secs, seed, steps)
# ----------------------------------------------------------------------------- UIdef add_user(message, history): message = (message or "").strip() history = list(history or []) if not message: return gr.update(), history, "", history return "", history + [{"role": "user", "content": message}], message, history
def clear_chat(): return [], render_viz(phase="idle"), "", "", []
EXAMPLES = [ "A train leaves at 9:40 and arrives at 13:15. How long is the trip in minutes?", "Write a Python function that checks whether a string is a palindrome, ignoring case and punctuation.", "Explain in simple terms how a flow-matching model turns noise into data.", "Write a short poem about a black forest at dawn.",]
HEADER = """<div class="bfl-head"> <div class="bfl-brand"><span class="bfl-mark">▲</span>BLACK FOREST LABS</div> <h1>FLUNG <span>8B</span></h1> <p>A language flow model. Instead of writing one token at a time, FLUNG drafts 128 tokens at once as noise and refines all of them in parallel — watch it happen live, step by step.</p> <div class="bfl-links"> <a href="https://huggingface.co/black-forest-labs/flung-8b" target="_blank">Model card</a> <a href="https://arxiv.org/abs/2612.06003" target="_blank">Paper</a> <a href="https://bfl.ai" target="_blank">bfl.ai</a> <span class="bfl-lic">Research artifact · CC BY-NC 4.0</span> </div></div>"""
CSS = """:root, .dark { --ink:#07130E; --paper:#F4F0EA; --sand:#E6E0D7; --line:#DDD6CB; --moss:#3B473E; --violet:#6F5FD0; --lav:#E0DEEA; --green:#1A7F64; }.gradio-container { max-width: 1320px !important; margin: 0 auto !important; }.dark .gradio-container { color: var(--body-text-color); }footer { display:none !important; }.bfl-head { padding: 28px 4px 10px; color: var(--ink); }.bfl-brand { font-family: var(--font-mono); font-size: 12px; letter-spacing: .22em; color: var(--moss); display:flex; align-items:center; gap:10px; }.bfl-mark { display:inline-flex; width:22px; height:22px; align-items:center; justify-content:center; background: var(--ink); color: var(--paper); border-radius: 4px; font-size: 10px; letter-spacing:0; }.bfl-head h1 { font-size: 46px; line-height: 1.05; margin: 14px 0 8px; font-weight: 600; letter-spacing: -.02em; color: var(--ink); }.bfl-head h1 span { color: var(--moss); font-weight: 400; }.bfl-head p { max-width: 720px; font-size: 16px; color: #3d453f; margin: 0 0 14px; }.bfl-links { display:flex; flex-wrap:wrap; gap:8px; align-items:center; font-family: var(--font-mono); font-size: 12px; }.bfl-links a { color: var(--ink) !important; text-decoration:none; border:1px solid var(--ink); border-radius: 999px; padding: 4px 12px; }.bfl-links a:hover { background: var(--ink); color: var(--paper) !important; }.bfl-lic { color: #6b6f69; margin-left: 6px; }.panel-title { font-family: var(--font-mono); font-size: 11px; letter-spacing:.18em; text-transform: uppercase; color: var(--moss); margin: 2px 2px 6px; }
/* chat */#chat { border: 1px solid var(--line) !important; background: var(--paper) !important; border-radius: 14px !important; }#chat .message.user, #chat .user .message { background: var(--ink) !important; border-color: var(--ink) !important; }#chat .message.user *, #chat .user .message * { color: #fff !important; }#chat .message.bot, #chat .bot .message { background: #fff !important; border: 1px solid var(--line) !important; }#composer { border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: 4px; }#composer textarea { font-size: 15px !important; }#send { min-width: 110px; }
/* live decoding panel */.fv { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px 16px 12px; color: var(--ink); min-height: 520px; display:flex; flex-direction:column; gap: 12px; }.fv-top { display:flex; justify-content:space-between; align-items:center; font-family: var(--font-mono); font-size: 12px; }.fv-live { display:flex; align-items:center; gap:8px; text-transform: uppercase; letter-spacing:.16em; color: var(--ink); }.fv-live i { width:8px; height:8px; border-radius:50%; background: var(--violet); box-shadow: 0 0 0 0 rgba(111,95,208,.6); animation: fvpulse 1.2s infinite; }.fv-live.idle i { background: var(--green); animation: none; }@keyframes fvpulse { 0%{box-shadow:0 0 0 0 rgba(111,95,208,.55)} 70%{box-shadow:0 0 0 8px rgba(111,95,208,0)} 100%{box-shadow:0 0 0 0 rgba(111,95,208,0)} }.fv-meta { color: #5b625c; }.fv-time { display:flex; align-items:center; gap:10px; font-family: var(--font-mono); font-size: 11px; color:#5b625c; }.fv-track { position:relative; flex:1; height: 6px; border-radius: 6px; background: var(--sand); border: 1px solid #cfc8bc; }.fv-fill { position:absolute; left:0; top:0; bottom:0; border-radius: 6px; background: linear-gradient(90deg, var(--lav), var(--moss)); transition: width .08s linear; }.fv-knob { position:absolute; top:50%; width:14px; height:14px; margin-left:-7px; margin-top:-7px; border-radius:50%; background: var(--ink); transition: left .08s linear; }.fv-ticks { display:grid; grid-template-columns: repeat(64, 1fr); gap: 2px; }.fv-tick { height: 12px; border-radius: 1.5px; background: var(--ink); opacity: calc(.12 + .88 * var(--c)); transition: opacity .1s, background .1s; }.fv-tick.chg { background: var(--violet); opacity: 1; }.fv-tick.tail { opacity: .07; }.fv-block { flex:1; background:#fff; border:1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-size: 15px; line-height: 1.9; white-space: pre-wrap; word-break: break-word; overflow-y:auto; max-height: 360px; }.fv-chip { border-radius: 3px; padding: 1px 0; color: rgba(7,19,14, calc(.38 + .62 * var(--c))); background: rgba(111,95,208, calc((1 - var(--c)) * .22)); transition: background .12s, color .12s; }.fv-chip.fv-chg { background: rgba(111,95,208,.16); box-shadow: inset 0 -2px 0 var(--violet); }.fv-chip.fv-tail { color: rgba(7,19,14,.18); background: transparent; }.fv-chip.fv-end { font-family: var(--font-mono); font-size: 10px; letter-spacing:.12em; text-transform:uppercase; background: var(--ink); color:#fff; padding: 2px 6px; margin: 0 3px; }.fv-nl { color: rgba(7,19,14,.25); font-weight: 400; }.fv-empty { flex:1; display:flex; align-items:center; justify-content:center; text-align:center; padding: 30px; color:#6b6f69; border: 1px dashed #cfc8bc; border-radius: 12px; font-size: 15px; line-height: 1.6; background: repeating-linear-gradient(90deg, rgba(7,19,14,.04) 0 6px, transparent 6px 9px); }.fv-foot { display:flex; flex-direction:column; gap:8px; font-family: var(--font-mono); font-size: 11px; color:#5b625c; }.fv-legend { display:flex; flex-wrap:wrap; gap: 14px; align-items:center; }.fv-legend .lg { display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:6px; vertical-align:-1px; }.lg-noisy { background: rgba(111,95,208,.28); } .lg-set { background: var(--ink); } .lg-chg { background: var(--violet); }.fv-count { margin-left:auto; color: var(--ink); }.fv-pills { display:flex; flex-wrap:wrap; gap:6px; }.fv-pill { border:1px solid #cfc8bc; border-radius: 999px; padding: 2px 9px; color: var(--ink); background:#fff; }.fv-pill em { font-style: normal; color:#7a7f79; margin-left:6px; }.fv-pill.cur { border-color: var(--violet); color: var(--violet); }.fv-stats { display:flex; flex-wrap:wrap; gap: 6px 16px; font-family: var(--font-mono); font-size: 12px; color:#5b625c; padding: 4px 4px 0; }.fv-stats b { color: var(--ink); font-weight: 600; }#settings { border-radius: 14px !important; }"""
FORCE_LIGHT = """() => { const url = new URL(window.location); if (url.searchParams.get('__theme') !== 'light') { url.searchParams.set('__theme', 'light'); window.location.href = url.href; }}"""
theme = gr.themes.Base( primary_hue=gr.themes.colors.stone, neutral_hue=gr.themes.colors.stone, font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"], font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "ui-monospace", "monospace"], radius_size=gr.themes.sizes.radius_lg,).set( body_background_fill="#F9F7F3", body_text_color="#07130E", block_background_fill="#FFFFFF", block_border_color="#DDD6CB", block_label_text_color="#3B473E", button_primary_background_fill="#07130E", button_primary_background_fill_hover="#26332C", button_primary_text_color="#FFFFFF", button_secondary_background_fill="#FFFFFF", button_secondary_border_color="#CFC8BC", button_secondary_text_color="#07130E", slider_color="#07130E", color_accent="#3B473E", color_accent_soft="#E6E0D7", input_background_fill="#FFFFFF", border_color_primary="#DDD6CB",)
with gr.Blocks(title="FLUNG 8B · Black Forest Labs") as demo: gr.HTML(HEADER) prev_history = gr.State([]) pending = gr.State("") with gr.Row(equal_height=False): with gr.Column(scale=6): gr.HTML('<div class="panel-title">Conversation</div>') chatbot = gr.Chatbot(elem_id="chat", height=520, show_label=False, buttons=["copy"], placeholder="Ask FLUNG anything — math, code, writing.") with gr.Row(elem_id="composer"): msg = gr.Textbox(show_label=False, placeholder="Message FLUNG 8B…", container=False, scale=6, lines=1, max_lines=6, autofocus=True) send = gr.Button("Send", variant="primary", scale=1, elem_id="send") with gr.Row(): clear = gr.Button("New chat", variant="secondary", size="sm") with gr.Column(scale=5): gr.HTML('<div class="panel-title">Live decoding · current 128-token block</div>') viz = gr.HTML(render_viz(phase="idle")) stats = gr.HTML("")
with gr.Accordion("Sampling settings", open=False, elem_id="settings"): with gr.Row(): steps = gr.Slider(8, 64, value=64, step=8, label="Denoising steps per block", info="64 = model default; 32 is faster with a small quality cost.") stable_stop = gr.Slider(0, 8, value=4, step=1, label="Early stop", info="Commit a block once its readout is unchanged for n steps (0 = off).") max_new_tokens = gr.Slider(128, 2048, value=1024, step=128, label="Max new tokens") with gr.Row(): temperature = gr.Slider(0.05, 1.0, value=0.3, step=0.05, label="Temperature") top_p = gr.Slider(0.5, 1.0, value=0.9, step=0.01, label="Top-p") seed = gr.Number(value=1973, precision=0, label="Seed") randomize_seed = gr.Checkbox(value=False, label="Randomize seed")
gr.Examples( examples=[[e] for e in EXAMPLES], inputs=[msg], outputs=[chatbot, viz, stats], fn=respond, cache_examples=True, cache_mode="lazy", label="Try an example", )
settings = [steps, stable_stop, temperature, top_p, max_new_tokens, seed, randomize_seed] for trigger in (msg.submit, send.click): trigger(add_user, [msg, chatbot], [msg, chatbot, pending, prev_history], queue=False).then( respond, [pending, prev_history, *settings], [chatbot, viz, stats], api_name=False, ) clear.click(clear_chat, None, [chatbot, viz, stats, msg, prev_history], queue=False)
# Programmatic endpoint (one-shot chat) for gradio_client / MCP. api_btn = gr.Button(visible=False) api_btn.click(respond, [msg, prev_history, *settings], [chatbot, viz, stats], api_name="chat")
demo.queue(default_concurrency_limit=2).launch(theme=theme, css=CSS, js=FORCE_LIGHT, mcp_server=True)123transformersacceleratesafetensorsREADME.md+19-6
app.pyAdded+473
requirements.txtAdded+3