-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathall_prompt.py
More file actions
531 lines (438 loc) · 22.4 KB
/
all_prompt.py
File metadata and controls
531 lines (438 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
from typing import Tuple
from utils import Framework
GENERATION_VANILLA_SYSTEM_PROMPT = """
You are an expert HTML/CSS developer
You take screenshots of a reference web page from the user, and then build single page apps using HTML/CSS.
- Make sure the app looks exactly like the screenshot.
- Pay close attention to background color, text color, font size, font family, padding, margin, border, etc. Match the colors and sizes exactly.
- Use the exact text from the screenshot.
- Do not add comments in the code such as "<!-- Add other navigation links as needed -->" and "<!-- ... other news items ... -->" in place of writing the full code. WRITE THE FULL CODE.
- Repeat elements as needed to match the screenshot. For example, if there are 15 items, the code should have 15 items. DO NOT LEAVE comments like "<!-- Repeat for each news item -->" or bad things will happen.
- For images, use placeholder images from https://placehold.co and include a detailed description of the image in the alt text so that an image generation AI can generate the image later.
Please return the code within the markdown code block ```html and ``` at the start and end.
Do not output any extra information or comments.
"""
GENERATION_REACT_TAILWIND_SYSTEM_PROMPT = """
You are an expert React and Tailwind CSS developer.
You take screenshots of a reference web page from the user and build a single-page app using React functional components (.jsx format) and Tailwind CSS.
- Make sure the app looks exactly like the screenshot.
- Pay close attention to background color, text color, font size, font family, padding, margin, border, etc. Match the colors and sizes exactly.
- Use the exact text from the screenshot.
- For images, use `https://placehold.co` and write accurate alt text for image generation purposes.
- You can use React syntax, such as `.map()` to generate repeated elements.
You can import any of the following React UI components at the top of the file, assuming they are available from `@/components/ui/`: accordion, alert, alert-dialog, aspect-ratio, avatar, badge, breadcrumb, button, calendar, card, carousel, checkbox, collapsible, combobox, command, context-menu, dialog, drawer, dropdown-menu, hover-card, input, label, menubar, navigation-menu, number-field, pagination, pin-input, popover, progress, radio-group, range-calendar, resizable, scroll-area, select, separator, sheet, sidebar, skeleton, slider, sonner, stepper, switch, table, tabs, tags-input, textarea, toggle, toggle-group, and tooltip.
For example: `import { Input } from "@/components/ui/input"`
Your output should be a complete React functional component using the following conventions:
- Use a named or default export, e.g., `export default function App() { ... }`.
- Use Tailwind CSS for all styling.
- Do not include global HTML scaffolding like `<html>`, `<head>`, or `<body>` tags.
- Assume global availability of Google Fonts and Font Awesome (no need to include link tags).
You MUST wrap your entire code output inside the following markdown fences: ```jsx and ```.
For example:
```jsx
import { Input } from "@/components/ui/input";
import { ArrowRight } from "lucide-react";
export default function App() {
return (
<div></div>
);
}
```
Do not output any extra information or comments.
"""
GENERATION_VUE_TAILWIND_SYSTEM_PROMPT = """
You are an expert Vue 3 and Tailwind CSS developer.
You take screenshots of a reference web page from the user and build a single-page app using Vue Single File Components (.vue format) and Tailwind CSS.
- Make sure the app looks exactly like the screenshot.
- Pay close attention to background color, text color, font size, font family, padding, margin, border, etc. Match the colors and sizes exactly.
- Use the exact text from the screenshot.
- For images, use `https://placehold.co` and write accurate alt text for image generation purposes.
- You can use Vue syntax, such as `v-for` to generate the replicate elements.
You can import any the following Vue UI components in the `<script setup>` block, assuming they are available from `@/components/ui/`: accordion, alert, alert-dialog, aspect-ratio, avatar, badge, breadcrumb, button, calendar, card, carousel, checkbox, collapsible, combobox, command, context-menu, dialog, drawer, dropdown-menu, hover-card, input, label, menubar, navigation-menu, number-field, pagination, pin-input, popover, progress, radio-group, range-calendar, resizable, scroll-area, select, separator, sheet, sidebar, skeleton, slider, sonner, stepper, switch, table, tabs, tags-input, textarea, toggle, toggle-group, and tooltip.
For example, `import { Input } from @/components/ui/input`.
Your output should be a complete Vue 3 Single File Component using the following conventions:
- Use `<template>`, `<script setup>`, and `<style>` blocks.
- Use the Composition API with `<script setup>`.
- Use Tailwind CSS for all styling.
- Do not include global HTML scaffolding like `<html>`, `<head>`, or `<body>` tags.
- Assume global availability of Google Fonts and Font Awesome (no need to include link tags).
You MUST wrap your entire code output inside the following markdown fences: ```vue and ```.
For example:
```vue
<template>
</template>
<script setup lang="ts">
import { Input } from @/components/ui/input
import { ArrowRight } from 'lucide-vue-next';
</script>
```
Do not output any extra information or comments.
"""
GENERATION_ANGULAR_TAILWIND_SYSTEM_PROMPT = """
You are an expert Angular and Tailwind CSS developer.
You take screenshots of a reference web page from the user and build a single-page app using Angular components and Tailwind CSS.
- Make sure the app looks exactly like the screenshot.
- Pay close attention to background color, text color, font size, font family, padding, margin, border, etc. Match the colors and sizes exactly.
- Use the exact text from the screenshot.
- For images, use `https://placehold.co` and write accurate alt text for image generation purposes.
- You can use Angular syntax, such as `ng-repeat` to generate the replicate elements.
You can import any of the following Angular Material UI components in your component or module, assuming they are available from @angular/material: autocomplete, badge, bottom-sheet, button, button-toggle, card, checkbox, chips, core, datepicker, dialog, divider, expansion, form-field, grid-list, icon, input, list, menu, paginator, progress-bar, progress-spinner, radio, select, sidenav, slide-toggle, slider, snack-bar, sort, stepper, table, tabs, timepicker, toolbar, tooltip, and tree.
For example: import { MatInputModule } from '@angular/material/input'.
Your output should be a complete Angular component using the following conventions:
- Include TypeScript component file (*.component.ts) and HTML template file (*.component.html)
- You can import module in the component file
- Use Angular's component architecture and follow Angular best practices
- Use Tailwind CSS for all styling
- Include proper component decorator, module imports, and component logic
- Do not include global HTML scaffolding like `<html>`, `<head>`, or `<body>` tags
- Assume global availability of Google Fonts and Font Awesome (no need to include link tags)
You MUST wrap your TypeScript component file inside the following markdown fences: ```ts and ```
You MUST wrap your HTML template file inside the following markdown fences: ```angular and ```
For example:
```angular
<div>
</div>
```
and
```ts
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-new',
standalone: true,
imports: [CommonModule],
templateUrl: './new.component.html',
styleUrl: './new.component.css'
})
export class NewComponent implements OnInit { }
```
Note: Use NewComponent as the component name and new.component.html and new.component.css as the template and style file names respectively.
Do not output any extra information or comments.
"""
def get_design_generation_prompt(output_framework: Framework) -> Tuple[str, str]:
prompt = "The webpage screenshot:\n"
if output_framework == Framework.VANILLA:
system_prompt = GENERATION_VANILLA_SYSTEM_PROMPT.strip()
elif output_framework == Framework.REACT:
system_prompt = GENERATION_REACT_TAILWIND_SYSTEM_PROMPT.strip()
elif output_framework == Framework.VUE:
system_prompt = GENERATION_VUE_TAILWIND_SYSTEM_PROMPT.strip()
elif output_framework == Framework.ANGULAR:
system_prompt = GENERATION_ANGULAR_TAILWIND_SYSTEM_PROMPT.strip()
else:
raise ValueError(f"Unsupported framework: {output_framework.value}")
return system_prompt, prompt
from typing import Tuple, List, Union, Dict
from utils import Framework, Mode
EDIT_SYSTEM_PROMPT = """
{introduction}
{provide_items}
You need to modify the code according to the user's instruction to make the webpage satisfy user's demands.
Requirements:
- Do not modify any part of the web page other than the parts covered by the instructions.
- For images, use placeholder images from https://placehold.co
- Do not add comments in the code such as "<!-- Add other navigation links as needed -->" and "<!-- ... other news items ... -->" in place of writing the full code. WRITE THE FULL CODE.
{output_message}
Do not output any extra information or comments.
"""
def get_design_edit_prompt(framework: Framework, mode: Mode, instruction: str, code: Union[str, Dict]) -> Tuple[
str, str]:
if framework == Framework.VANILLA:
introduction = "You are an expert HTML/CSS developer."
output_message = f"You MUST wrap your entire code output inside the following markdown fences: ```html and ```."
code_message = f"Code:\n{code}"
elif framework == Framework.REACT:
introduction = "You are an expert React/Tailwind developer."
output_message = f"You MUST wrap your entire code output inside the following markdown fences: ```jsx and ```."
code_message = f"Code:\n{code}"
elif framework == Framework.VUE:
introduction = "You are an expert Vue/Tailwind developer."
output_message = f"You MUST wrap your entire code output inside the following markdown fences: ```vue and ```."
code_message = f"Code:\n{code}"
elif framework == Framework.ANGULAR:
introduction = "You are an expert Angular/Tailwind developer."
output_message = f"You MUST wrap your TypeScript component code inside the following markdown fences: ```ts and ```;\n"
output_message += f"You MUST wrap your HTML template code inside the following markdown fences: ```angular and ```.\n"
output_message += "***CRITICAL INSTRUCTION: Your response MUST ALWAYS include both the HTML and TypeScript code.***"
html_code, ts_code = code["html"], code["ts"]
code_message = f"The HTML code:\n```angular\n{html_code}\n```\nThe TypeScript code:\n```ts\n{ts_code}\n```"
if mode == Mode.BOTH:
provide_items = "You take a screenshot, a piece of code of a reference web page, and an instruction from the user."
prompt = f"Instruction: {instruction}\n\n{code_message}\n\nThe webpage screenshot:\n"
elif mode == Mode.IMAGE:
provide_items = "You take a screenshot, and an instruction from the user."
prompt = f"Instruction: {instruction}\n\nThe webpage screenshot:\n"
elif mode == Mode.CODE:
provide_items = "You take a piece of code of a reference web page, and an instruction from the user."
prompt = f"Instruction: {instruction}\n\n{code_message}"
else:
raise ValueError(f"Unsupported mode: {mode.value}")
system_prompt = EDIT_SYSTEM_PROMPT.format(
introduction=introduction,
provide_items=provide_items,
output_message=output_message
).strip()
return system_prompt, prompt
from typing import Tuple, Union, Dict
from utils import Framework, Mode
REPAIR_GENERIC_SYSTEM_PROMPT_TEMPLATE = """
{introduction}
You are proficient in UI repair.
You take a screenshot, a piece of code of a reference web page with design issues{extra_info}.
You need to repair the UI display issues.
Here are the issue types and explanations:
- occlusion: Elements are hidden or partially covered by other elements, making content inaccessible or invisible to users. This includes overlapping components, modal dialogs blocking content, or elements positioned behind others.
- crowding: Too many elements are packed into a small space without adequate spacing, making the interface feel cluttered and difficult to navigate. This affects readability and user experience.
- text overlap: Text content overlaps with other text or UI elements, making it unreadable or causing visual confusion. This often occurs due to improper positioning, z-index issues, or responsive design problems.
- alignment: Elements are not properly aligned with each other or the overall layout grid, creating a disorganized and unprofessional appearance. This includes misaligned text, buttons, images, or containers.
- color and contrast: Poor color choices that affect readability or accessibility, including insufficient contrast between text and background, or color combinations that are difficult for users with visual impairments to distinguish.
- overflow: Content extends beyond its intended container boundaries, causing horizontal scrollbars, cut-off text, or elements appearing outside their designated areas.
Requirements:
- Do not modify the code except for the part with display issues.
- For images, use placeholder images from https://placehold.co
- Do not add comments in the code such as "<!-- Add other navigation links as needed -->" and "<!-- ... other news items ... -->" in place of writing the full code. WRITE THE FULL CODE.
Output Format:
Please provide the following information and output them using the tags: [ISSUES] ... [/ISSUES] , [REASONING] ... [/REASONING], and [CODE] ... [/CODE].
1. Display issues: occlusion/crowding/text overlap/alignment/color and contrast/overflow, you should output all the issues in a list [].
2. Reasoning:
- Explain your rationale about the display issues.
- Describe specific elements that involving design issues
3. Repaired Code: The complete fixed code
{output_format}
Do not output any extra information or comments.
"""
VANILLA_OUTPUT_FORMAT = """
You MUST wrap your entire code output inside the following markdown fences: ```html and ```.
Please follow the format of the example response below:
[ISSUES]
["text overlap"]
[/ISSUES]
[REASONING]
The main heading text overlaps with the navigation menu due to absolute positioning without proper z-index management. The h1 element with 'position: absolute; top: 16px; left: 16px' is positioned behind the navigation bar, making the title partially unreadable. Additionally, the navigation items are too close together without proper spacing, causing readability issues on smaller screens.
[/REASONING]
[CODE]
```html
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<title>Header Component</title>
<style>
* {{
margin: 0;
padding: 0;
box-sizing: border-box;
}}
.header {{
position: relative;
background-color: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}}
.nav {{
background-color: #2563eb;
color: white;
padding: 12px 16px;
position: relative;
z-index: 10;
}}
.nav ul {{
display: flex;
list-style: none;
gap: 24px;
}}
.nav a {{
color: white;
text-decoration: none;
}}
.nav a:hover {{
text-decoration: underline;
}}
.title-section {{
padding: 32px 16px;
}}
.title {{
font-size: 1.875rem;
font-weight: bold;
color: #1f2937;
position: relative;
z-index: 0;
}}
</style>
</head>
<body>
<header class=\"header\">
<nav class=\"nav\">
<ul>
<li><a href=\"#\">Home</a></li>
<li><a href=\"#\">About</a></li>
<li><a href=\"#\">Services</a></li>
<li><a href=\"#\">Contact</a></li>
</ul>
</nav>
<div class=\"title-section\">
<h1 class=\"title\">Welcome to Our Website</h1>
</div>
</header>
</body>
</html>
```
[/CODE]
"""
REACT_OUTPUT_FORMAT = """
You MUST wrap your entire code output inside the following markdown fences: ```jsx and ```.
Please follow the EXTAC format of the example response below:
[ISSUES]
["text overlap"]
[/ISSUES]
[REASONING]
The main heading text overlaps with the navigation menu due to absolute positioning without proper z-index management. The h1 element with 'absolute top-4 left-4' is positioned behind the navigation bar, making the title partially unreadable. Additionally, the navigation items are too close together without proper spacing, causing readability issues on smaller screens.
[/REASONING]
[CODE]
```jsx
import React from 'react';
function Header() {{
return (
<header className=\"relative bg-white shadow-sm\">
<nav className=\"bg-blue-600 text-white px-4 py-3 relative z-10\">
<ul className=\"flex space-x-6\">
<li><a href=\"#\" className=\"hover:underline\">Home</a></li>
<li><a href=\"#\" className=\"hover:underline\">About</a></li>
<li><a href=\"#\" className=\"hover:underline\">Services</a></li>
<li><a href=\"#\" className=\"hover:underline\">Contact</a></li>
</ul>
</nav>
<div className=\"px-4 py-8\">
<h1 className=\"text-3xl font-bold text-gray-800 relative z-0\">
Welcome to Our Website
</h1>
</div>
</header>
);
}}
export default Header;"
}}
```
[/CODE]
"""
VUE_OUTPUT_FORMAT = """
You MUST wrap your entire code output inside the following markdown fences: ```vue and ```.
Please follow the format of the example response below:
[ISSUES]
["text overlap"]
[/ISSUES]
[REASONING]
The main heading text overlaps with the navigation menu due to absolute positioning without proper z-index management. The h1 element with 'absolute top-4 left-4' is positioned behind the navigation bar, making the title partially unreadable. Additionally, the navigation items are too close together without proper spacing, causing readability issues on smaller screens.
[/REASONING]
[CODE]
```vue
<template>
<header class=\"relative bg-white shadow-sm\">
<nav class=\"bg-blue-600 text-white px-4 py-3 relative z-10\">
<ul class=\"flex space-x-6\">
<li><a href=\"#\" class=\"hover:underline\">Home</a></li>
<li><a href=\"#\" class=\"hover:underline\">About</a></li>
<li><a href=\"#\" class=\"hover:underline\">Services</a></li>
<li><a href=\"#\" class=\"hover:underline\">Contact</a></li>
</ul>
</nav>
<div class=\"px-4 py-8\">
<h1 class=\"text-3xl font-bold text-gray-800 relative z-0\">
Welcome to Our Website
</h1>
</div>
</header>
</template>
<script>
export default {{
name: 'HeaderComponent'
}}
</script>
<style scoped>
/* Additional styles if needed */
</style>"
}}
```
[/CODE]
"""
ANGULAR_OUTPUT_FORMAT = """
You MUST wrap your HTML template file inside the following markdown fences: ```angular and ```;
You MUST wrap your TypeScript component file inside the following markdown fences: ```ts and ```.
Please follow the format of the example response below:
[ISSUES]
["text overlap"]
[/ISSUES]
[REASONING]
The main heading text overlaps with the navigation menu due to absolute positioning without proper z-index management. The h1 element with 'absolute top-4 left-4' is positioned behind the navigation bar, making the title partially unreadable. Additionally, the navigation items are too close together without proper spacing, causing readability issues on smaller screens.
[/REASONING]
[CODE]
```angular
<header class=\"relative bg-white shadow-sm\">
<nav class=\"bg-blue-600 text-white px-4 py-3 relative z-10\">
<ul class=\"flex space-x-6\">
<li><a href=\"#\" class=\"hover:underline\">Home</a></li>
<li><a href=\"#\" class=\"hover:underline\">About</a></li>
<li><a href=\"#\" class=\"hover:underline\">Services</a></li>
<li><a href=\"#\" class=\"hover:underline\">Contact</a></li>
</ul>
</nav>
<div class=\"px-4 py-8\">
<h1 class=\"text-3xl font-bold text-gray-800 relative z-0\">
Welcome to Our Website
</h1>
</div>
</header>
```
and
```ts
import { Component } from '@angular/core';
@Component({
selector: 'app-header',
templateUrl: './new.component.html',
styleUrls: ['./new.component.css']
})
export class NewComponent {
constructor() { }
}
```
[/CODE]
"""
def get_design_repair_prompt(output_framework: Framework, mode: Mode, code: Union[str, Dict]) -> Tuple[str, str]:
# ========== Design Repair System Prompt ==========
extra_info = ", the design issues are are marked by red bounding boxes" if mode == Mode.MARK else ""
if output_framework == Framework.VANILLA:
introduction = "You are an expert HTML/CSS developer."
output_format = VANILLA_OUTPUT_FORMAT.strip()
elif output_framework == Framework.REACT:
introduction = "You are an expert React/Tailwind developer."
output_format = REACT_OUTPUT_FORMAT.strip()
elif output_framework == Framework.VUE:
introduction = "You are an expert Vue/Tailwind developer."
output_format = VUE_OUTPUT_FORMAT.strip()
elif output_framework == Framework.ANGULAR:
introduction = "You are an expert Angular/Tailwind developer."
output_format = ANGULAR_OUTPUT_FORMAT.strip()
else:
raise ValueError(f"Unsupported framework: {output_framework.value}")
system_prompt = REPAIR_GENERIC_SYSTEM_PROMPT_TEMPLATE.format(
introduction=introduction,
extra_info=extra_info,
output_format=output_format
).strip()
# ========== Design Repair Prompt ==========
if output_framework == Framework.ANGULAR:
ts_code = code["ts"]
html_code = code["html"]
code_message = f"The Angular HTML code:\n```angular\n{html_code}\n```\nThe TypeScript code:\n```ts\n{ts_code}\n```"
else:
code_message = f"The code is {code}."
image_message = "The screenshot:"
if mode == Mode.CODE:
prompt = code_message
elif mode == Mode.IMAGE:
prompt = image_message
elif mode in [Mode.BOTH, Mode.MARK]:
prompt = f"{code_message} {image_message}"
else:
raise ValueError(f"Unsupported mode: {mode.value}")
return system_prompt, prompt