Spaces:
Runtime error
Runtime error
token modal
Browse files
src/lib/components/Playground/Playground.svelte
CHANGED
|
@@ -5,6 +5,7 @@
|
|
| 5 |
import PlaygroundCode from './PlaygroundCode.svelte';
|
| 6 |
import PlaygroundMessage from '$lib/components/Playground/PlaygroundMessage.svelte';
|
| 7 |
import PlaygroundOptions from '$lib/components/Playground/PlaygroundOptions.svelte';
|
|
|
|
| 8 |
|
| 9 |
type Message = {
|
| 10 |
role: 'user' | 'assistant' | 'system';
|
|
@@ -40,6 +41,7 @@
|
|
| 40 |
|
| 41 |
let hfToken: string | null = '';
|
| 42 |
let viewCode = false;
|
|
|
|
| 43 |
let loading = false;
|
| 44 |
let streamingMessage: Message | null = null;
|
| 45 |
let latency = 0;
|
|
@@ -69,11 +71,8 @@
|
|
| 69 |
|
| 70 |
async function submit() {
|
| 71 |
if (!hfToken) {
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
);
|
| 75 |
-
if (!token) return;
|
| 76 |
-
hfToken = token;
|
| 77 |
}
|
| 78 |
(document.activeElement as HTMLElement).blur();
|
| 79 |
loading = true;
|
|
@@ -145,6 +144,10 @@
|
|
| 145 |
|
| 146 |
<svelte:window on:keydown={onKeydown} />
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
<div
|
| 149 |
class="w-dvh maxdivide-gray-200 grid h-dvh overflow-hidden max-md:grid-cols-1 max-md:divide-y md:grid-cols-[260px,minmax(0,1fr),260px] md:divide-x dark:divide-gray-800 dark:bg-gray-900 dark:text-gray-300"
|
| 150 |
>
|
|
|
|
| 5 |
import PlaygroundCode from './PlaygroundCode.svelte';
|
| 6 |
import PlaygroundMessage from '$lib/components/Playground/PlaygroundMessage.svelte';
|
| 7 |
import PlaygroundOptions from '$lib/components/Playground/PlaygroundOptions.svelte';
|
| 8 |
+
import PlaygroundTokenModal from './PlaygroundTokenModal.svelte';
|
| 9 |
|
| 10 |
type Message = {
|
| 11 |
role: 'user' | 'assistant' | 'system';
|
|
|
|
| 41 |
|
| 42 |
let hfToken: string | null = '';
|
| 43 |
let viewCode = false;
|
| 44 |
+
let showTokenModal = false;
|
| 45 |
let loading = false;
|
| 46 |
let streamingMessage: Message | null = null;
|
| 47 |
let latency = 0;
|
|
|
|
| 71 |
|
| 72 |
async function submit() {
|
| 73 |
if (!hfToken) {
|
| 74 |
+
showTokenModal = true;
|
| 75 |
+
return;
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
(document.activeElement as HTMLElement).blur();
|
| 78 |
loading = true;
|
|
|
|
| 144 |
|
| 145 |
<svelte:window on:keydown={onKeydown} />
|
| 146 |
|
| 147 |
+
{#if showTokenModal}
|
| 148 |
+
<PlaygroundTokenModal on:close={() => (showTokenModal = false)} />
|
| 149 |
+
{/if}
|
| 150 |
+
|
| 151 |
<div
|
| 152 |
class="w-dvh maxdivide-gray-200 grid h-dvh overflow-hidden max-md:grid-cols-1 max-md:divide-y md:grid-cols-[260px,minmax(0,1fr),260px] md:divide-x dark:divide-gray-800 dark:bg-gray-900 dark:text-gray-300"
|
| 153 |
>
|
src/lib/components/Playground/PlaygroundOptions.svelte
CHANGED
|
@@ -8,9 +8,11 @@
|
|
| 8 |
|
| 9 |
<div>
|
| 10 |
<div>
|
| 11 |
-
<label
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
<select
|
| 15 |
bind:value={currentModel}
|
| 16 |
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
|
|
|
| 8 |
|
| 9 |
<div>
|
| 10 |
<div>
|
| 11 |
+
<label
|
| 12 |
+
for="countries"
|
| 13 |
+
class="mb-2 flex items-baseline text-sm font-medium text-gray-900 dark:text-white"
|
| 14 |
+
>models<span class="ml-4 font-normal text-gray-400">{compatibleModels.length}</span>
|
| 15 |
+
</label>
|
| 16 |
<select
|
| 17 |
bind:value={currentModel}
|
| 18 |
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
src/lib/components/Playground/PlaygroundTokenModal.svelte
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- Main modal -->
|
| 2 |
+
<script lang="ts">
|
| 3 |
+
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
| 4 |
+
import { browser } from '$app/environment';
|
| 5 |
+
|
| 6 |
+
let backdropEl: HTMLDivElement;
|
| 7 |
+
let modalEl: HTMLDivElement;
|
| 8 |
+
|
| 9 |
+
const dispatch = createEventDispatcher<{ close: void }>();
|
| 10 |
+
|
| 11 |
+
function handleKeydown(event: KeyboardEvent) {
|
| 12 |
+
// close on ESC
|
| 13 |
+
if (event.key === 'Escape') {
|
| 14 |
+
event.preventDefault();
|
| 15 |
+
dispatch('close');
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
function handleBackdropClick(event: MouseEvent) {
|
| 20 |
+
if (window?.getSelection()?.toString()) {
|
| 21 |
+
return;
|
| 22 |
+
}
|
| 23 |
+
if (event.target === backdropEl) {
|
| 24 |
+
dispatch('close');
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
onMount(() => {
|
| 29 |
+
document.getElementById('app')?.setAttribute('inert', 'true');
|
| 30 |
+
modalEl.focus();
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
onDestroy(() => {
|
| 34 |
+
if (!browser) return;
|
| 35 |
+
// remove inert attribute if this is the last modal
|
| 36 |
+
if (document.querySelectorAll('[role="dialog"]:not(#app *)').length === 1) {
|
| 37 |
+
document.getElementById('app')?.removeAttribute('inert');
|
| 38 |
+
}
|
| 39 |
+
});
|
| 40 |
+
</script>
|
| 41 |
+
|
| 42 |
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
| 43 |
+
<div
|
| 44 |
+
id="default-modal"
|
| 45 |
+
tabindex="-1"
|
| 46 |
+
aria-hidden="true"
|
| 47 |
+
class="fixed inset-0 z-50 flex items-center justify-center overflow-hidden bg-black/85"
|
| 48 |
+
bind:this={backdropEl}
|
| 49 |
+
on:click|stopPropagation={handleBackdropClick}
|
| 50 |
+
>
|
| 51 |
+
<div
|
| 52 |
+
role="dialog"
|
| 53 |
+
tabindex="-1"
|
| 54 |
+
class="relative max-h-full w-full max-w-xl p-4"
|
| 55 |
+
bind:this={modalEl}
|
| 56 |
+
on:keydown={handleKeydown}
|
| 57 |
+
>
|
| 58 |
+
<div class="relative rounded-lg bg-white shadow dark:bg-gray-700">
|
| 59 |
+
<div
|
| 60 |
+
class="flex items-center justify-between rounded-t border-b p-4 md:p-5 dark:border-gray-600"
|
| 61 |
+
>
|
| 62 |
+
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">
|
| 63 |
+
Add a Hugging Face Token
|
| 64 |
+
</h3>
|
| 65 |
+
<button
|
| 66 |
+
type="button"
|
| 67 |
+
on:click={() => dispatch('close')}
|
| 68 |
+
class="ms-auto inline-flex h-8 w-8 items-center justify-center rounded-lg bg-transparent text-sm text-gray-400 hover:bg-gray-200 hover:text-gray-900 dark:hover:bg-gray-600 dark:hover:text-white"
|
| 69 |
+
>
|
| 70 |
+
<svg
|
| 71 |
+
class="h-3 w-3"
|
| 72 |
+
aria-hidden="true"
|
| 73 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 74 |
+
fill="none"
|
| 75 |
+
viewBox="0 0 14 14"
|
| 76 |
+
>
|
| 77 |
+
<path
|
| 78 |
+
stroke="currentColor"
|
| 79 |
+
stroke-linecap="round"
|
| 80 |
+
stroke-linejoin="round"
|
| 81 |
+
stroke-width="2"
|
| 82 |
+
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"
|
| 83 |
+
/>
|
| 84 |
+
</svg>
|
| 85 |
+
<span class="sr-only">Close modal</span>
|
| 86 |
+
</button>
|
| 87 |
+
</div>
|
| 88 |
+
<!-- Modal body -->
|
| 89 |
+
<div class="space-y-6 p-4 md:p-5">
|
| 90 |
+
<p class="text-base leading-relaxed text-gray-700 2xl:text-balance dark:text-gray-400">
|
| 91 |
+
You need a free Hugging Face token to use this application. <strong class="font-semibold"
|
| 92 |
+
>Make sure you create a token with Inference API permission.</strong
|
| 93 |
+
><br /> Your token is kept safe by only being used from your browser.
|
| 94 |
+
</p>
|
| 95 |
+
<div class="mb-6">
|
| 96 |
+
<label
|
| 97 |
+
for="default-input"
|
| 98 |
+
class="mb-2 block text-sm font-medium text-gray-900 dark:text-white"
|
| 99 |
+
>Hugging Face Token</label
|
| 100 |
+
>
|
| 101 |
+
<input
|
| 102 |
+
type="text"
|
| 103 |
+
id="default-input"
|
| 104 |
+
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
|
| 105 |
+
/>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<!-- Modal footer -->
|
| 110 |
+
<div
|
| 111 |
+
class="flex items-center justify-between rounded-b border-t border-gray-200 p-4 md:p-5 dark:border-gray-600"
|
| 112 |
+
>
|
| 113 |
+
<a
|
| 114 |
+
href="https://huggingface.co/settings/tokens?new_token=true"
|
| 115 |
+
tabindex="-1"
|
| 116 |
+
target="_blank"
|
| 117 |
+
class="rounded-lg border border-gray-200 bg-white px-5 py-2.5 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
|
| 118 |
+
>Create new token</a
|
| 119 |
+
>
|
| 120 |
+
|
| 121 |
+
<button
|
| 122 |
+
type="button"
|
| 123 |
+
class="mb-2 me-2 rounded-lg bg-black px-5 py-2.5 text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700"
|
| 124 |
+
>Submit</button
|
| 125 |
+
>
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|