Spaces:
Running

tinyllama / index.html
afeening's picture
TinyLLaMA chat: the model runs in your browser
3c5aec5 verified
Raw History Blame Contribute Delete
9.2 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TinyLLaMA</title>
<meta name="description" content="A small LLaMA-style language model, trained from scratch.">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%236d5dfc'/%3E%3Ctext x='16' y='22' font-size='16' text-anchor='middle' fill='white' font-family='sans-serif' font-weight='700'%3ETL%3C/text%3E%3C/svg%3E">
<!-- relative paths: the same files work under the FastAPI server and on a static host -->
<link rel="stylesheet" href="static/style.css">
</head>
<body>
<div class="app" id="app">
<!-- ===== sidebar: new chat, search, history, settings ===== -->
<aside class="sidebar" id="sidebar" aria-label="Chats">
<div class="sidebar-top">
<div class="brand">
<span class="logo">TL</span>
<div>
<div class="brand-name">TinyLLaMA</div>
<div class="brand-sub">trained from scratch</div>
</div>
</div>
<button class="btn btn-new" id="newChat" title="New chat (Ctrl+Shift+O)">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>
New chat
</button>
<label class="search">
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
<input id="search" type="search" placeholder="Search chats" autocomplete="off">
</label>
</div>
<nav class="chat-list" id="chatList"></nav>
<div class="sidebar-bottom">
<button class="side-link" id="openApi">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m8 9-4 3 4 3M16 9l4 3-4 3M14 5l-4 14"/></svg>
API &amp; keys
</button>
<button class="side-link" id="openSettings">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h10M18 7h2M4 17h4M12 17h8"/><circle cx="16" cy="7" r="2"/><circle cx="10" cy="17" r="2"/></svg>
Settings
</button>
<button class="side-link" id="toggleTheme">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg>
<span id="themeLabel">Dark mode</span>
</button>
<a class="side-link" href="https://github.com/arshiafreen090/llm-from-scratch" target="_blank" rel="noopener">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 19c-4 1.5-4-2-6-2.5m12 5v-3.5c0-1 .1-1.4-.5-2 2.8-.3 5.5-1.4 5.5-6a4.6 4.6 0 0 0-1.3-3.2 4.2 4.2 0 0 0-.1-3.2s-1-.3-3.4 1.3a11.6 11.6 0 0 0-6 0C6.8 3.3 5.8 3.6 5.8 3.6a4.2 4.2 0 0 0-.1 3.2A4.6 4.6 0 0 0 4.4 10c0 4.6 2.7 5.7 5.5 6-.6.6-.6 1.2-.5 2V22"/></svg>
Code &amp; results
</a>
</div>
</aside>
<div class="scrim" id="scrim" hidden></div>
<!-- ===== main: header, conversation, composer ===== -->
<main class="main">
<header class="topbar">
<button class="icon-btn only-mobile" id="openSidebar" aria-label="Open chats">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 6h16M4 12h16M4 18h16"/></svg>
</button>
<div class="model-pill" id="modelPill" title="Model">
<span class="status-dot" id="statusDot"></span>
<span id="modelName">connecting…</span>
<span class="pill-meta" id="modelMeta"></span>
</div>
<button class="icon-btn" id="openApiTop" title="Use this model from your own code">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m8 9-4 3 4 3M16 9l4 3-4 3M14 5l-4 14"/></svg>
<span class="hide-mobile">API</span>
</button>
</header>
<section class="conversation" id="conversation" aria-live="polite">
<div class="empty" id="empty">
<div class="empty-logo">TL</div>
<h1>What story should I write?</h1>
<p>An 11M-parameter LLaMA-style model, pretrained and instruction-tuned from scratch on
children's stories. Ask for a story and name a few words it should use.</p>
<div class="examples" id="examples"></div>
</div>
<div class="messages" id="messages"></div>
</section>
<footer class="composer-wrap">
<form class="composer" id="composer">
<textarea id="prompt" rows="1" placeholder="Ask for a story…"
aria-label="Message" maxlength="4000"></textarea>
<button class="send" id="send" type="submit" aria-label="Send">
<svg class="i-send" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>
<svg class="i-stop" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>
</button>
</form>
<div class="composer-note" id="composerNote">Each message is answered on its own · Enter to send, Shift+Enter for a new line</div>
</footer>
</main>
</div>
<!-- ===== settings dialog ===== -->
<dialog class="modal" id="settingsModal">
<form method="dialog" class="modal-body" id="settingsForm">
<header class="modal-head">
<h2>Settings</h2>
<button class="icon-btn" value="close" aria-label="Close">✕</button>
</header>
<label class="field">
<span>Temperature <output id="tempOut"></output></span>
<input type="range" id="temperature" min="0" max="1.5" step="0.05">
<small>0 = always the most likely word. Higher = more varied, and eventually incoherent.</small>
</label>
<label class="field">
<span>Top-p <output id="topPOut"></output></span>
<input type="range" id="topP" min="0.1" max="1" step="0.05">
<small>Only sample from the most likely words covering this much probability.</small>
</label>
<label class="field">
<span>Max length <output id="maxOut"></output></span>
<input type="range" id="maxTokens" min="32" max="480" step="16">
</label>
<label class="field">
<span>Seed</span>
<input type="number" id="seed" placeholder="random" min="0">
<small>Leave empty for a random seed. Every reply shows its seed, so you can reproduce it.</small>
</label>
<label class="field server-only" id="keyField">
<span>API key</span>
<input type="password" id="apiKey" placeholder="sk-tl-…" autocomplete="off">
<small id="keyHint">Stored only in this browser.</small>
</label>
<footer class="modal-foot">
<button class="btn btn-ghost" type="button" id="resetSettings">Reset to defaults</button>
<button class="btn btn-primary" value="close">Done</button>
</footer>
</form>
</dialog>
<!-- ===== API dialog ===== -->
<dialog class="modal modal-wide" id="apiModal">
<form method="dialog" class="modal-body">
<header class="modal-head">
<h2>Use this model from your own code</h2>
<button class="icon-btn" value="close" aria-label="Close">✕</button>
</header>
<div class="browser-only">
<p class="muted">On this page the model runs <strong>inside your browser</strong> (ONNX Runtime Web), so
there is no server to call. To get the HTTP API, run the model's own server, on your computer or any
machine with Docker. It speaks the <strong>OpenAI chat API</strong>, with optional API keys and rate limits:</p>
<div class="snippet"><button type="button" class="copy" data-copy="selfHost">Copy</button><pre><code id="selfHost">git clone https://github.com/arshiafreen090/llm-from-scratch.git && cd llm-from-scratch
docker build -t tinyllama . && docker run -p 8000:7860 tinyllama
# then: OpenAI(base_url="http://localhost:8000/v1", api_key="any-text")</code></pre></div>
<p class="muted small">Full instructions: <a href="https://github.com/arshiafreen090/llm-from-scratch#web-ui-and-openai-compatible-api" target="_blank" rel="noopener">README → Web UI and OpenAI-compatible API</a></p>
</div>
<p class="muted server-only">The server speaks the <strong>OpenAI chat API</strong>, so the official OpenAI libraries and
tools work: point them at this base URL.</p>
<div class="kv server-only">
<div><span>Base URL</span><code id="baseUrl"></code><button type="button" class="copy" data-copy="baseUrl">Copy</button></div>
<div><span>Model</span><code id="apiModel"></code><button type="button" class="copy" data-copy="apiModel">Copy</button></div>
<div><span>API key</span><code id="apiKeyInfo"></code></div>
</div>
<h3 class="server-only">curl (streaming)</h3>
<div class="snippet server-only"><button type="button" class="copy" data-copy="curlSnippet">Copy</button><pre><code id="curlSnippet"></code></pre></div>
<h3 class="server-only">Python (<code>pip install openai</code>)</h3>
<div class="snippet server-only"><button type="button" class="copy" data-copy="pySnippet">Copy</button><pre><code id="pySnippet"></code></pre></div>
<p class="muted small server-only">Interactive docs for every endpoint: <a id="docsLink" href="/docs" target="_blank" rel="noopener">/docs</a></p>
</form>
</dialog>
<div class="toast" id="toast" role="status" hidden></div>
<script src="static/config.js"></script>
<script src="static/app.js"></script>
</body>
</html>