jbilcke-hf HF staff commited on
Commit
6b981ec
1 Parent(s): 64dea8b
Files changed (3) hide show
  1. README.md +1 -1
  2. public/index.html +7 -0
  3. src/index.mts +11 -6
README.md CHANGED
@@ -31,7 +31,7 @@ http://localhost:7860/?prompt=a simple html canvas game where we need to feed ta
31
  ```bash
32
  nvm use
33
  npm i
34
- npm run start
35
  ```
36
 
37
  ## Building and running with Docker
 
31
  ```bash
32
  nvm use
33
  npm i
34
+ HF_API_TOKEN=******* HF_END_POINT_URL=https://*******.endpoints.huggingface.cloud npm run start
35
  ```
36
 
37
  ## Building and running with Docker
public/index.html CHANGED
@@ -22,6 +22,13 @@
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'"
 
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
+ <textarea
26
+ name="promptDraft"
27
+ x-model="promptDraft"
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 = promptDraft, state = state === 'stopped' ? 'loading' : 'stopped'"
src/index.mts CHANGED
@@ -4,7 +4,8 @@ import { HfInference } from '@huggingface/inference'
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
@@ -23,9 +24,9 @@ const app = express()
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
 
@@ -92,12 +93,12 @@ app.get("/app", async (req, res) => {
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)
@@ -109,7 +110,7 @@ ${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
@@ -120,6 +121,10 @@ ${prefix}`
120
  if (result.includes('</html>')) {
121
  break
122
  }
 
 
 
 
123
  }
124
 
125
  endRequest(id, `normal end of the LLM stream for request ${id}`)
 
4
  import { daisy } from "./daisy.mts"
5
 
6
  const hfi = new HfInference(process.env.HF_API_TOKEN)
7
+
8
+ console.log('HF_ENDPOINT_URL:', process.env.HF_ENDPOINT_URL)
9
  const hf = hfi.endpoint(process.env.HF_ENDPOINT_URL)
10
 
11
  // define the CSS and JS dependencies
 
24
  const port = 7860
25
 
26
  const minPromptSize = 16 // if you change this, you will need to also change in public/index.html
27
+ const timeoutInSec = 30 * 60
28
 
29
+ console.log("timeout set to 30 minutes")
30
 
31
  app.use(express.static("public"))
32
 
 
93
 
94
  const finalPrompt = `# Task
95
  Generate the following: ${req.query.prompt}
96
+ # API Documentation
97
  ${daisy}
98
  # Guidelines
99
  - Never repeat the instruction, instead directly write the final code
100
  - Use a color scheme consistent with the brief and theme
101
+ - You must use Tailwind CSS and Daisy UI for the CSS classes, vanilla JS and Alpine.js for the JS.
102
  - All the JS code will be written directly inside the page, using <script type="text/javascript">...</script>
103
  - You MUST use English, not Latin! (I repeat: do NOT write lorem ipsum!)
104
  - No need to write code comments, so please make the code compact (short function names etc)
 
110
  let result = ''
111
  for await (const output of hf.textGenerationStream({
112
  inputs: finalPrompt,
113
+ parameters: { max_new_tokens: 1024 }
114
  })) {
115
  if (!pending.queue.includes(id)) {
116
  break
 
121
  if (result.includes('</html>')) {
122
  break
123
  }
124
+ if (result.includes('</enbd>') || result.includes('<|assistant|>')) {
125
+ // it ended, but we probably don't have a valid HTML
126
+ break
127
+ }
128
  }
129
 
130
  endRequest(id, `normal end of the LLM stream for request ${id}`)