jbilcke-hf HF staff commited on
Commit
64dea8b
1 Parent(s): f03ce40

small update

Browse files
Files changed (2) hide show
  1. public/index.html +10 -17
  2. src/index.mts +18 -12
public/index.html CHANGED
@@ -19,25 +19,18 @@
19
  <div
20
  class="py-2 space-y-4 text-stone-600 transition-all delay-150 ease-in-out"
21
  :class="open ? 'md:text-lg lg:text-xl' : 'text-2xl'">
22
- <p>A space to generate web content with WizardCoder, using an Inference Endpoint.</p>
23
- <p>Feel free to duplicate and create interesting forks 🔧</p>
24
  </div>
25
- <textarea
26
- name="draft"
27
- x-model="draft"
28
- rows="10"
29
- placeholder="A simple page to compute the bmi, using kg and meters"
30
- class="input input-bordered w-full rounded text-lg text-stone-500 bg-stone-300 font-mono h-48"
31
- ></textarea>
32
  <button
33
  class="btn disabled:text-stone-400"
34
- @click="open = true, prompt = draft, state = state === 'stopped' ? 'loading' : 'stopped'"
35
- :class="draft.length < minPromptSize ? 'btn-neutral' : state === 'stopped' ? 'btn-accent' : 'btn-warning'"
36
- :disabled="draft.length < minPromptSize"
37
  >
38
- <span x-show="draft.length < minPromptSize">Prompt too short to generate</span>
39
- <span x-show="draft.length >= minPromptSize && state !== 'stopped'">Stop now</span>
40
- <span x-show="draft.length >= minPromptSize && state === 'stopped'">Generate!</span>
41
  </button>
42
  <span class="py-3" x-show="state === 'loading'">Waiting for the stream to begin (might take a few minutes)..</span>
43
  <span class="py-3" x-show="state === 'streaming'">
@@ -53,7 +46,7 @@
53
  class="border-none w-full h-screen"
54
  :src="!open
55
  ? '/placeholder.html'
56
- : `/app?prompt=${prompt}`
57
  "></iframe>
58
  </div>
59
  </div>
@@ -92,7 +85,7 @@ function humanFileSize(bytes, si=false, dp=1) {
92
  function app() {
93
  return {
94
  open: false,
95
- draft: new URLSearchParams(window.location.search).get('prompt') || 'A simple page to compute the bmi, using kg and meters',
96
  prompt: '',
97
  size: 0,
98
  minPromptSize: 16, // if you change this, you will need to also change in src/index.mts
 
19
  <div
20
  class="py-2 space-y-4 text-stone-600 transition-all delay-150 ease-in-out"
21
  :class="open ? 'md:text-lg lg:text-xl' : 'text-2xl'">
22
+ <p>A space to generate web content using WizardCoder.</p>
23
+ <p>It uses the Hugging Face Endpoints API for inference.</p>
24
  </div>
 
 
 
 
 
 
 
25
  <button
26
  class="btn disabled:text-stone-400"
27
+ @click="open = true, prompt = promptDraft, state = state === 'stopped' ? 'loading' : 'stopped'"
28
+ :class="promptDraft.length < minPromptSize ? 'btn-neutral' : state === 'stopped' ? 'btn-accent' : 'btn-warning'"
29
+ :disabled="promptDraft.length < minPromptSize"
30
  >
31
+ <span x-show="promptDraft.length < minPromptSize">Prompt too short to generate</span>
32
+ <span x-show="promptDraft.length >= minPromptSize && state !== 'stopped'">Stop now</span>
33
+ <span x-show="promptDraft.length >= minPromptSize && state === 'stopped'">Generate!</span>
34
  </button>
35
  <span class="py-3" x-show="state === 'loading'">Waiting for the stream to begin (might take a few minutes)..</span>
36
  <span class="py-3" x-show="state === 'streaming'">
 
46
  class="border-none w-full h-screen"
47
  :src="!open
48
  ? '/placeholder.html'
49
+ : `/app?prompt=${encodeURIComponent(prompt)}`
50
  "></iframe>
51
  </div>
52
  </div>
 
85
  function app() {
86
  return {
87
  open: false,
88
+ promptDraft: new URLSearchParams(window.location.search).get('prompt') || 'A simple page to compute the bmi, using kg and meters',
89
  prompt: '',
90
  size: 0,
91
  minPromptSize: 16, // if you change this, you will need to also change in src/index.mts
src/index.mts CHANGED
@@ -2,12 +2,10 @@ import express from "express"
2
  import { HfInference } from '@huggingface/inference'
3
 
4
  import { daisy } from "./daisy.mts"
5
- import { alpine } from "./alpine.mts"
6
 
7
- const hf = new HfInference(process.env.HF_API_TOKEN)
8
 
9
- // TODO put here the Inference Endpoint url for WizardCoder
10
- const model = hf.endpoint('https://xyz.eu-west-1.aws.endpoints.huggingface.cloud/gpt2');
11
 
12
  // define the CSS and JS dependencies
13
  const css = [
@@ -25,12 +23,12 @@ const app = express()
25
  const port = 7860
26
 
27
  const minPromptSize = 16 // if you change this, you will need to also change in public/index.html
28
- const timeoutInSec = 3 * 60
29
 
30
- console.log("timeout set to 3 minutes")
31
 
32
  app.use(express.static("public"))
33
-
34
  const pending: {
35
  total: number;
36
  queue: string[];
@@ -59,6 +57,14 @@ app.get("/debug", (req, res) => {
59
 
60
  app.get("/app", async (req, res) => {
61
 
 
 
 
 
 
 
 
 
62
  if (`${req.query.prompt}`.length < minPromptSize) {
63
  res.write(`prompt too short, please enter at least ${minPromptSize} characters`)
64
  res.end()
@@ -86,15 +92,15 @@ app.get("/app", async (req, res) => {
86
 
87
  const finalPrompt = `# Task
88
  Generate the following: ${req.query.prompt}
89
- # Documentation
90
  ${daisy}
91
  # Guidelines
92
- - Never repeat the instruction, instead directly write the final code within a script tag
93
  - Use a color scheme consistent with the brief and theme
94
- - You need to use Tailwind CSS and DaisyUI for the UI, pure vanilla JS and AlpineJS for the JS.
95
  - All the JS code will be written directly inside the page, using <script type="text/javascript">...</script>
96
  - You MUST use English, not Latin! (I repeat: do NOT write lorem ipsum!)
97
- - No need to write code comments, and try to make the code compact (short function names etc)
98
  - Use a central layout by wrapping everything in a \`<div class="flex flex-col justify-center">\`
99
  # HTML output
100
  ${prefix}`
@@ -103,7 +109,7 @@ ${prefix}`
103
  let result = ''
104
  for await (const output of hf.textGenerationStream({
105
  inputs: finalPrompt,
106
- parameters: { max_new_tokens: 1024 }
107
  })) {
108
  if (!pending.queue.includes(id)) {
109
  break
 
2
  import { HfInference } from '@huggingface/inference'
3
 
4
  import { daisy } from "./daisy.mts"
 
5
 
6
+ const hfi = new HfInference(process.env.HF_API_TOKEN)
7
 
8
+ const hf = hfi.endpoint(process.env.HF_ENDPOINT_URL)
 
9
 
10
  // define the CSS and JS dependencies
11
  const css = [
 
23
  const port = 7860
24
 
25
  const minPromptSize = 16 // if you change this, you will need to also change in public/index.html
26
+ const timeoutInSec = 5 * 60
27
 
28
+ console.log("timeout set to 5 minutes")
29
 
30
  app.use(express.static("public"))
31
+
32
  const pending: {
33
  total: number;
34
  queue: string[];
 
57
 
58
  app.get("/app", async (req, res) => {
59
 
60
+ const model = `${req.query.model || 'OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5'}`
61
+
62
+ console.log('model:', model)
63
+
64
+ const endpoint = `${req.query.endpoint || ''}`
65
+
66
+ console.log('endpoint:', endpoint)
67
+
68
  if (`${req.query.prompt}`.length < minPromptSize) {
69
  res.write(`prompt too short, please enter at least ${minPromptSize} characters`)
70
  res.end()
 
92
 
93
  const finalPrompt = `# Task
94
  Generate the following: ${req.query.prompt}
95
+ # API Documentation for Daisy UI
96
  ${daisy}
97
  # Guidelines
98
+ - Never repeat the instruction, instead directly write the final code
99
  - Use a color scheme consistent with the brief and theme
100
+ - You need to use Tailwind CSS
101
  - All the JS code will be written directly inside the page, using <script type="text/javascript">...</script>
102
  - You MUST use English, not Latin! (I repeat: do NOT write lorem ipsum!)
103
+ - No need to write code comments, so please make the code compact (short function names etc)
104
  - Use a central layout by wrapping everything in a \`<div class="flex flex-col justify-center">\`
105
  # HTML output
106
  ${prefix}`
 
109
  let result = ''
110
  for await (const output of hf.textGenerationStream({
111
  inputs: finalPrompt,
112
+ parameters: { max_new_tokens: 2048 }
113
  })) {
114
  if (!pending.queue.includes(id)) {
115
  break