Arsala Grey
commited on
Commit
·
0d92137
1
Parent(s):
d59fcb5
scaffolded vue app
Browse files- index.html +99 -16
- style.css +38 -15
index.html
CHANGED
|
@@ -1,19 +1,102 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width" />
|
| 6 |
+
<title>My static Space</title>
|
| 7 |
+
<link rel="stylesheet" href="./style.css" />
|
| 8 |
+
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
| 9 |
+
<script type="module">
|
| 10 |
+
const { createApp, ref, onMounted } = Vue;
|
| 11 |
+
import { HfInference } from "https://cdn.skypack.dev/@huggingface/[email protected]";
|
| 12 |
+
|
| 13 |
+
const app = createApp({
|
| 14 |
+
setup() {
|
| 15 |
+
const title = ref("Mistral-7B-Instruct-v0.1");
|
| 16 |
+
const subtitle = ref("huggingface.js");
|
| 17 |
+
const token = ref(localStorage.getItem("token") || "");
|
| 18 |
+
const inputText = ref("Write an essay about Star Wars");
|
| 19 |
+
const generatedText = ref("");
|
| 20 |
+
let controller;
|
| 21 |
+
|
| 22 |
+
const textStreamRes = async function* (hf, controller, input) {
|
| 23 |
+
let tokens = [];
|
| 24 |
+
for await (const output of hf.textGenerationStream(
|
| 25 |
+
{
|
| 26 |
+
model: "mistralai/Mistral-7B-Instruct-v0.1",
|
| 27 |
+
inputs: `[INST]${input}[/INST]`,
|
| 28 |
+
parameters: { max_new_tokens: 450 },
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
use_cache: false,
|
| 32 |
+
signal: controller.signal,
|
| 33 |
+
}
|
| 34 |
+
)) {
|
| 35 |
+
tokens.push(output.token.text);
|
| 36 |
+
generatedText.value += output.token.text;
|
| 37 |
+
yield;
|
| 38 |
+
}
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
const run = async () => {
|
| 42 |
+
controller = new AbortController();
|
| 43 |
+
localStorage.setItem("token", token.value);
|
| 44 |
+
const hf = new HfInference(token.value);
|
| 45 |
+
|
| 46 |
+
try {
|
| 47 |
+
for await (const text of textStreamRes(
|
| 48 |
+
hf,
|
| 49 |
+
controller,
|
| 50 |
+
inputText.value
|
| 51 |
+
)) {
|
| 52 |
+
console.log(text);
|
| 53 |
+
}
|
| 54 |
+
} catch (e) {
|
| 55 |
+
console.log(e);
|
| 56 |
+
}
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
const abort = () => {
|
| 60 |
+
if (controller) {
|
| 61 |
+
controller.abort();
|
| 62 |
+
}
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
onMounted(() => {
|
| 66 |
+
if (localStorage.getItem("token")) {
|
| 67 |
+
token.value = localStorage.getItem("token");
|
| 68 |
+
}
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
return {
|
| 72 |
+
title,
|
| 73 |
+
subtitle,
|
| 74 |
+
token,
|
| 75 |
+
inputText,
|
| 76 |
+
generatedText,
|
| 77 |
+
run,
|
| 78 |
+
abort,
|
| 79 |
+
};
|
| 80 |
+
},
|
| 81 |
+
}).mount("#app");
|
| 82 |
+
</script>
|
| 83 |
+
</head>
|
| 84 |
+
<body>
|
| 85 |
+
<div id="app">
|
| 86 |
+
<header>
|
| 87 |
+
<h1>{{title}}</h1>
|
| 88 |
+
<h2>{{subtitle}}</h2>
|
| 89 |
+
</header>
|
| 90 |
+
<input v-model="token" placeholder="HF-TOKEN" type="password" />
|
| 91 |
+
<textarea
|
| 92 |
+
v-model="inputText"
|
| 93 |
+
style="width: 100%; height: 100px"
|
| 94 |
+
></textarea>
|
| 95 |
+
<div>
|
| 96 |
+
<button @click="run">GENERATE</button>
|
| 97 |
+
<button @click="abort">ABORT</button>
|
| 98 |
+
</div>
|
| 99 |
+
<div>{{generatedText}}</div>
|
| 100 |
+
</div>
|
| 101 |
+
</body>
|
| 102 |
</html>
|
style.css
CHANGED
|
@@ -2,27 +2,50 @@ body {
|
|
| 2 |
padding: 2rem;
|
| 3 |
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
| 4 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
h1 {
|
| 7 |
-
|
| 8 |
-
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
padding: 2rem;
|
| 3 |
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
| 4 |
}
|
| 5 |
+
#app {
|
| 6 |
+
max-width: 800px;
|
| 7 |
+
margin: 2rem auto;
|
| 8 |
+
padding: 1.5rem;
|
| 9 |
+
background: white;
|
| 10 |
+
box-shadow: 0px 3px 10px rgba(0, 0, 0, 0.2);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
header {
|
| 14 |
+
margin-bottom: 1.5rem;
|
| 15 |
+
}
|
| 16 |
|
| 17 |
h1 {
|
| 18 |
+
font-size: 2rem;
|
| 19 |
+
margin-bottom: 0.5rem;
|
| 20 |
}
|
| 21 |
|
| 22 |
+
h2 {
|
| 23 |
+
font-size: 1.5rem;
|
| 24 |
+
margin-bottom: 1rem;
|
| 25 |
+
color: #666;
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
+
input[type="password"],
|
| 29 |
+
textarea,
|
| 30 |
+
button {
|
| 31 |
+
width: 100%;
|
| 32 |
+
padding: 0.6rem;
|
| 33 |
+
margin-bottom: 1rem;
|
| 34 |
+
border: 1px solid #ccc;
|
| 35 |
+
border-radius: 4px;
|
| 36 |
}
|
| 37 |
|
| 38 |
+
button {
|
| 39 |
+
cursor: pointer;
|
| 40 |
+
background-color: #007bff;
|
| 41 |
+
color: white;
|
| 42 |
}
|
| 43 |
+
|
| 44 |
+
button:hover {
|
| 45 |
+
background-color: #0056b3;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
div > span {
|
| 49 |
+
display: inline-block;
|
| 50 |
+
margin-right: 0.2rem;
|
| 51 |
+
}
|