jbilcke-hf HF staff commited on
Commit
d32c6ac
1 Parent(s): 9e78595

improve prompt to make it generate less lorem ipsums

Browse files
Files changed (3) hide show
  1. public/index.html +8 -7
  2. src/daisy.mts +8 -5
  3. src/index.mts +22 -15
public/index.html CHANGED
@@ -35,8 +35,8 @@
35
  name="promptDraft"
36
  x-model="promptDraft"
37
  rows="10"
38
- placeholder="A simple page to compute the BMI (use SI units)"
39
- class="input input-bordered w-full rounded text-stone-500 bg-stone-300 font-mono text-md md:text-lg h-24 md:h-48"
40
  ></textarea>
41
  <button
42
  class="btn disabled:text-stone-400"
@@ -107,11 +107,12 @@
107
  return {
108
  open: false,
109
  examples: {
110
- 'page about dolphins': 'a page about dolphins, with text and a few pictures'
111
- },
 
 
112
  promptDraft:
113
- new URLSearchParams(window.location.search).get("prompt") ||
114
- "A simple page to compute the BMI (use SI units)",
115
  prompt: "",
116
  size: 0,
117
  minPromptSize: 16, // if you change this, you will need to also change in src/index.mts
@@ -138,7 +139,7 @@
138
  const elapsed = (lastTokenAt - this.lastTokenAt) / 1000;
139
  this.lastTokenAt = lastTokenAt;
140
  if (elapsed > this.timeoutInSec) {
141
- console.log(`Something went wrong, it too more than ${this.timeoutInSec} seconds to generate a token.`);
142
  this.state = "stopped";
143
  return;
144
  }
 
35
  name="promptDraft"
36
  x-model="promptDraft"
37
  rows="10"
38
+ placeholder="Describe your web app"
39
+ class="input input-bordered w-full rounded text-stone-600 bg-stone-100 font-mono text-md md:text-lg h-24 md:h-48"
40
  ></textarea>
41
  <button
42
  class="btn disabled:text-stone-400"
 
107
  return {
108
  open: false,
109
  examples: {
110
+ "compute the BMI": "a simple page to compute the BMI (use SI units)",
111
+ "animals": "app listing various animals",
112
+ // "page about dolphins": "a page about dolphins, with text and a few pictures"
113
+ },
114
  promptDraft:
115
+ new URLSearchParams(window.location.search).get("prompt"),
 
116
  prompt: "",
117
  size: 0,
118
  minPromptSize: 16, // if you change this, you will need to also change in src/index.mts
 
139
  const elapsed = (lastTokenAt - this.lastTokenAt) / 1000;
140
  this.lastTokenAt = lastTokenAt;
141
  if (elapsed > this.timeoutInSec) {
142
+ console.log(`Something went wrong, it took more than ${this.timeoutInSec} seconds to generate a token.`);
143
  this.state = "stopped";
144
  return;
145
  }
src/daisy.mts CHANGED
@@ -1,5 +1,8 @@
1
- export const daisy = `# DaisyUI docs
2
- ## To create a nice layout, wrap each article in:
3
- \`<article class="prose"></article>\`
4
- ## Buttons
5
- \`<button class="btn"></button>\``
 
 
 
 
1
+ export const daisy = `## DaisyUI docs
2
+ ### To create a nice layout, wrap each article in:
3
+ <article class="prose"></article>
4
+ ### Use appropriate CSS classes
5
+ <button class="btn ..">
6
+ <table class="table ..">
7
+ <footer class="footer ..">
8
+ `
src/index.mts CHANGED
@@ -54,7 +54,7 @@ app.get('/app', async (req, res) => {
54
 
55
  pending.queue.push(id)
56
 
57
- const prefix = `<html><head><link href='https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css' rel='stylesheet' type='text/css' /><script defer src='https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js'></script><script src='https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp'></script><title>Generated content</title><body`
58
  res.write(prefix)
59
 
60
  req.on('close', function() {
@@ -68,27 +68,34 @@ app.get('/app', async (req, res) => {
68
 
69
  const finalPrompt = `# Task
70
  Generate the following: ${req.query.prompt}
71
- # API Documentation
72
  ${daisy}
73
  # Guidelines
74
- - Never repeat the instruction, instead directly write the final code
75
- - Use a color scheme consistent with the brief and theme
76
- - To generate all your images, import from from this route: "/image?prompt=<description or caption of an image, photo or illustration>"
77
- - please be descriptive for the prompt, eg describe the scene in a few words (textures, characters, materials, camera type etc)
78
- - do not add more than 3 or 4 images
79
- - You must use Tailwind CSS and Daisy UI for the CSS classes, vanilla JS and Alpine.js for the JS.
80
- - All the JS code will be written directly inside the page, using <script type='text/javascript'>...</script>
81
- - You MUST use English, not Latin! (I repeat: do NOT write lorem ipsum!)
82
- - No need to write code comments, so please make the code compact (short function names etc)
83
- - Use a central layout by wrapping everything in a \`<div class='flex flex-col items-center'>\`
84
- # HTML output
85
- <html><head></head><body`
 
 
 
86
 
87
  try {
88
  let result = ''
89
  for await (const output of hf.textGenerationStream({
90
  inputs: finalPrompt,
91
- parameters: { max_new_tokens: 1024 }
 
 
 
 
92
  })) {
93
  if (!pending.queue.includes(id)) {
94
  break
 
54
 
55
  pending.queue.push(id)
56
 
57
+ const prefix = `<html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script><title>Generated content</title><body>`
58
  res.write(prefix)
59
 
60
  req.on('close', function() {
 
68
 
69
  const finalPrompt = `# Task
70
  Generate the following: ${req.query.prompt}
71
+ # API Doc
72
  ${daisy}
73
  # Guidelines
74
+ - Never repeat the instructions, instead write the final code
75
+ - To generate images use the /image endpoint: <img src="/image?prompt=caption of the photo" />
76
+ - Be descriptive for photo caption, use at last 10 words.
77
+ - **NEVER** add more than 3 or 4 images
78
+ - Never write lists that are too long
79
+ - You must use TailwindCSS utility classes (Tailwind is already injected in the page).
80
+ - If needed, embed new custom JS code using <script>...</script>
81
+ - You MUST use English, not Latin! Write in English! Never write "lorem ipsum.."
82
+ - Use a central layout to wrap everything in a <div class='flex flex-col items-center'>
83
+ # Output
84
+ <html>
85
+ <head>
86
+ <title>Site</title>
87
+ </head>
88
+ <body>`
89
 
90
  try {
91
  let result = ''
92
  for await (const output of hf.textGenerationStream({
93
  inputs: finalPrompt,
94
+ parameters: {
95
+ do_sample: true,
96
+ max_new_tokens: 1200,
97
+ return_full_text: false,
98
+ }
99
  })) {
100
  if (!pending.queue.includes(id)) {
101
  break