Spaces:
Running
Running
Commit
•
7a08a75
1
Parent(s):
0378a63
update ux, links, and example prompts
Browse files- src/routes/+page.svelte +39 -10
src/routes/+page.svelte
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
import Textarea from "@/lib/components/ui/textarea/textarea.svelte";
|
3 |
import Badge from "@/lib/components/ui/badge/badge.svelte";
|
4 |
import * as webllm from "@mlc-ai/web-llm";
|
5 |
-
import { onMount } from 'svelte';
|
6 |
|
7 |
let selectedModel = "smollm-360M-instruct-add-basics-q0f32-MLC";
|
8 |
|
@@ -17,6 +17,17 @@
|
|
17 |
let isGenerating = false;
|
18 |
let pendingRequest: string | null = null;
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
async function loadWebLLM() {
|
21 |
isLoading = true;
|
22 |
error = '';
|
@@ -26,9 +37,9 @@
|
|
26 |
|
27 |
const appConfig: webllm.AppConfig = {
|
28 |
model_list: [{
|
29 |
-
model: `https://huggingface.co/reach-vb/smollm-360M-instruct-add-basics-
|
30 |
model_id: 'smollm-360M-instruct-add-basics-q0f32-MLC',
|
31 |
-
model_lib: `${webllm.modelLibURLPrefix}${webllm.modelVersion}/SmolLM-360M-Instruct-
|
32 |
overrides: { context_window_size: 2048 },
|
33 |
},
|
34 |
{
|
@@ -108,16 +119,18 @@
|
|
108 |
onMount(loadWebLLM);
|
109 |
</script>
|
110 |
|
111 |
-
<div class="flex my-20 flex-col items-center gap-4 max-w-
|
112 |
<h1 class="text-center font-mono font-bold text-4xl">SmolLM 🤗</h1>
|
113 |
-
<p class="text-center font-mono text-sm mb-4">Powered by
|
|
|
114 |
<Textarea
|
115 |
-
bind:value={inputText}
|
116 |
-
on:input={() => generateCompletion(inputText)}
|
117 |
disabled={isLoading}
|
118 |
-
class="w-full"
|
119 |
placeholder="Say something..."
|
120 |
/>
|
|
|
121 |
{#if isLoading}
|
122 |
<p class="text-sm text-slate-600 text-center">{loadingStatus}</p>
|
123 |
{:else if error}
|
@@ -130,9 +143,25 @@
|
|
130 |
{#if tokensPerSecond !== null}
|
131 |
<Badge>{tokensPerSecond} tok/s</Badge>
|
132 |
{/if}
|
133 |
-
<Badge>{selectedModel}</Badge>
|
134 |
</div>
|
135 |
{/if}
|
136 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
</div>
|
|
|
2 |
import Textarea from "@/lib/components/ui/textarea/textarea.svelte";
|
3 |
import Badge from "@/lib/components/ui/badge/badge.svelte";
|
4 |
import * as webllm from "@mlc-ai/web-llm";
|
5 |
+
import { onMount, tick } from 'svelte';
|
6 |
|
7 |
let selectedModel = "smollm-360M-instruct-add-basics-q0f32-MLC";
|
8 |
|
|
|
17 |
let isGenerating = false;
|
18 |
let pendingRequest: string | null = null;
|
19 |
|
20 |
+
const promptExamples = [
|
21 |
+
"What is the capital of France?",
|
22 |
+
"Tell me a story about a cat.",
|
23 |
+
"Write a poem about the ocean.",
|
24 |
+
]
|
25 |
+
|
26 |
+
async function setPrompt(prompt: string) {
|
27 |
+
inputText = prompt;
|
28 |
+
generateCompletion(prompt);
|
29 |
+
}
|
30 |
+
|
31 |
async function loadWebLLM() {
|
32 |
isLoading = true;
|
33 |
error = '';
|
|
|
37 |
|
38 |
const appConfig: webllm.AppConfig = {
|
39 |
model_list: [{
|
40 |
+
model: `https://huggingface.co/reach-vb/smollm-360M-instruct-add-basics-q0f16-MLC`,
|
41 |
model_id: 'smollm-360M-instruct-add-basics-q0f32-MLC',
|
42 |
+
model_lib: `${webllm.modelLibURLPrefix}${webllm.modelVersion}/SmolLM-360M-Instruct-q0f16-ctx2k_cs1k-webgpu.wasm`,
|
43 |
overrides: { context_window_size: 2048 },
|
44 |
},
|
45 |
{
|
|
|
119 |
onMount(loadWebLLM);
|
120 |
</script>
|
121 |
|
122 |
+
<div class="flex my-20 flex-col items-center gap-4 max-w-xl mx-auto">
|
123 |
<h1 class="text-center font-mono font-bold text-4xl">SmolLM 🤗</h1>
|
124 |
+
<p class="text-center font-mono text-sm mb-4">Powered by <a href="https://huggingface.co/mlc-ai" target="_blank" class="underline text-blue-500">MLC</a> WebLLM <a class="underline text-blue-500" href="https://huggingface.co/HuggingFaceTB/smollm-360M-instruct-add-basics" target="_blank">SmolLM-360M-Instruct-Add-Basics</a> <span class="text-xs italic">(15 Max Tokens)</span></p>
|
125 |
+
|
126 |
<Textarea
|
127 |
+
bind:value={inputText}
|
128 |
+
on:input={() => generateCompletion(inputText)}
|
129 |
disabled={isLoading}
|
130 |
+
class="w-full text-lg"
|
131 |
placeholder="Say something..."
|
132 |
/>
|
133 |
+
<p class="text-center text-xs italic">This model doesn't work well with extremely creative prompts.</p>
|
134 |
{#if isLoading}
|
135 |
<p class="text-sm text-slate-600 text-center">{loadingStatus}</p>
|
136 |
{:else if error}
|
|
|
143 |
{#if tokensPerSecond !== null}
|
144 |
<Badge>{tokensPerSecond} tok/s</Badge>
|
145 |
{/if}
|
|
|
146 |
</div>
|
147 |
{/if}
|
148 |
+
<div class="flex flex-col items-center mb-4">
|
149 |
+
{#if inputText === ''}
|
150 |
+
<p class="text-sm mb-2">Try these examples:</p>
|
151 |
+
<div class="flex flex-wrap justify-center gap-2">
|
152 |
+
{#each promptExamples as prompt}
|
153 |
+
<button on:click={() => setPrompt(prompt)}>
|
154 |
+
<Badge
|
155 |
+
variant="outline"
|
156 |
+
class="cursor-pointer bg-orange-100 hover:bg-orange-200"
|
157 |
+
>
|
158 |
+
{prompt}
|
159 |
+
</Badge>
|
160 |
+
</button>
|
161 |
+
{/each}
|
162 |
+
</div>
|
163 |
+
{/if}
|
164 |
+
</div>
|
165 |
+
<pre class="text-xl font-bold whitespace-pre-wrap">{outputText}</pre>
|
166 |
|
167 |
</div>
|