Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

add a vue tailwind generation option

Abi Rajafa7ffdfaebde
diff --git a/backend/eval.py b/backend/eval.py
index 000c6fe9..60ef409e 100644
--- a/backend/eval.py
+++ b/backend/eval.py
@@ -49,7 +49,7 @@ async def main():
for filename in evals:
filepath = os.path.join(INPUT_DIR, filename)
data_url = await image_to_data_url(filepath)
- task = generate_code_core(data_url, "svg")
+ task = generate_code_core(data_url, "vue_tailwind")
tasks.append(task)
results = await asyncio.gather(*tasks)
diff --git a/backend/prompts.py b/backend/prompts.py
index 1fe4f9bb..d3d3b18a 100644
--- a/backend/prompts.py
+++ b/backend/prompts.py
@@ -15,6 +15,7 @@ from screenshot_system_prompts import (
REACT_TAILWIND_SYSTEM_PROMPT,
TAILWIND_SYSTEM_PROMPT,
SVG_SYSTEM_PROMPT,
+ VUE_TAILWIND_SYSTEM_PROMPT,
)
@@ -77,6 +78,8 @@ def assemble_prompt(
system_content = BOOTSTRAP_SYSTEM_PROMPT
elif generated_code_config == "ionic_tailwind":
system_content = IONIC_TAILWIND_SYSTEM_PROMPT
+ elif generated_code_config == "vue_tailwind":
+ system_content = VUE_TAILWIND_SYSTEM_PROMPT
elif generated_code_config == "svg":
system_content = SVG_SYSTEM_PROMPT
else:
diff --git a/backend/screenshot_system_prompts.py b/backend/screenshot_system_prompts.py
index 3308d03e..1dfcca43 100644
--- a/backend/screenshot_system_prompts.py
+++ b/backend/screenshot_system_prompts.py
@@ -111,6 +111,48 @@ Return only the full code in <html></html> tags.
Do not include markdown "```" or "```html" at the start or end.
"""
+VUE_TAILWIND_SYSTEM_PROMPT = """
+You are an expert Vue/Tailwind developer
+You take screenshots of a reference web page from the user, and then build single page apps
+using Vue and Tailwind CSS.
+You might also be given a screenshot(The second image) of a web page that you have already built, and asked to
+update it to look more like the reference image(The first image).
+
+- 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.
+- Use Vue using the global build like so:
+
+<div id="app">{{ message }}</div>
+<script>
+ const { createApp, ref } = Vue
+ createApp({
+ setup() {
+ const message = ref('Hello vue!')
+ return {
+ message
+ }
+ }
+ }).mount('#app')
+</script>
+
+In terms of libraries,
+
+- Use these script to include Vue so that it can run on a standalone page:
+ <script src="https://registry.npmmirror.com/vue/3.3.11/files/dist/vue.global.js"></script>
+- Use this script to include Tailwind: <script src="https://cdn.tailwindcss.com"></script>
+- You can use Google Fonts
+- Font Awesome for icons: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"></link>
+
+Return only the full code in <html></html> tags.
+Do not include markdown "```" or "```html" at the start or end.
+The return result must only include the code.
+"""
+
SVG_SYSTEM_PROMPT = """
You are an expert at building SVGs.
diff --git a/backend/test_prompts.py b/backend/test_prompts.py
index 303e3a9b..e12a207d 100644
--- a/backend/test_prompts.py
+++ b/backend/test_prompts.py
@@ -113,6 +113,48 @@ Return only the full code in <html></html> tags.
Do not include markdown "```" or "```html" at the start or end.
"""
+VUE_TAILWIND_SYSTEM_PROMPT = """
+You are an expert Vue/Tailwind developer
+You take screenshots of a reference web page from the user, and then build single page apps
+using Vue and Tailwind CSS.
+You might also be given a screenshot(The second image) of a web page that you have already built, and asked to
+update it to look more like the reference image(The first image).
+
+- 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.
+- Use Vue using the global build like so:
+
+<div id="app">{{ message }}</div>
+<script>
+ const { createApp, ref } = Vue
+ createApp({
+ setup() {
+ const message = ref('Hello vue!')
+ return {
+ message
+ }
+ }
+ }).mount('#app')
+</script>
+
+In terms of libraries,
+
+- Use these script to include Vue so that it can run on a standalone page:
+ <script src="https://registry.npmmirror.com/vue/3.3.11/files/dist/vue.global.js"></script>
+- Use this script to include Tailwind: <script src="https://cdn.tailwindcss.com"></script>
+- You can use Google Fonts
+- Font Awesome for icons: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"></link>
+
+Return only the full code in <html></html> tags.
+Do not include markdown "```" or "```html" at the start or end.
+The return result must only include the code.
+"""
+
SVG_SYSTEM_PROMPT = """
You are an expert at building SVGs.
You take screenshots of a reference web page from the user, and then build a SVG that looks exactly like the screenshot.
@@ -257,6 +299,10 @@ def test_prompts():
assert ionic_tailwind[0]["content"] == IONIC_TAILWIND_SYSTEM_PROMPT
assert ionic_tailwind[1]["content"][2]["text"] == USER_PROMPT # type: ignore
+ vue = assemble_prompt("image_data_url", "vue_tailwind", "result_image_data_url")
+ assert vue[0]["content"] == VUE_TAILWIND_SYSTEM_PROMPT
+ assert vue[1]["content"][2]["text"] == USER_PROMPT # type: ignore
+
svg_prompt = assemble_prompt("image_data_url", "svg", "result_image_data_url")
assert svg_prompt[0]["content"] == SVG_SYSTEM_PROMPT
assert svg_prompt[1]["content"][2]["text"] == SVG_USER_PROMPT # type: ignore
diff --git a/frontend/src/components/OutputSettingsSection.tsx b/frontend/src/components/OutputSettingsSection.tsx
index f671b586..4398f1bb 100644
--- a/frontend/src/components/OutputSettingsSection.tsx
+++ b/frontend/src/components/OutputSettingsSection.tsx
@@ -37,6 +37,13 @@ function generateDisplayComponent(config: GeneratedCodeConfig) {
<span className="font-semibold">Tailwind</span>
</div>
);
+ case GeneratedCodeConfig.VUE_TAILWIND:
+ return (
+ <div>
+ <span className="font-semibold">Vue</span> +{" "}
+ <span className="font-semibold">Tailwind</span>
+ </div>
+ );
case GeneratedCodeConfig.SVG:
return (
<div>
@@ -90,6 +97,14 @@ function OutputSettingsSection({
<SelectItem value={GeneratedCodeConfig.BOOTSTRAP}>
{generateDisplayComponent(GeneratedCodeConfig.BOOTSTRAP)}
</SelectItem>
+ <SelectItem value={GeneratedCodeConfig.VUE_TAILWIND}>
+ <div className="flex items-center">
+ {generateDisplayComponent(GeneratedCodeConfig.VUE_TAILWIND)}
+ <Badge className="ml-2" variant="secondary">
+ Beta
+ </Badge>
+ </div>
+ </SelectItem>
<SelectItem value={GeneratedCodeConfig.IONIC_TAILWIND}>
<div className="flex items-center">
{generateDisplayComponent(GeneratedCodeConfig.IONIC_TAILWIND)}
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 2820427a..e0c10262 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -7,6 +7,7 @@ export enum EditorTheme {
export enum GeneratedCodeConfig {
HTML_TAILWIND = "html_tailwind",
REACT_TAILWIND = "react_tailwind",
+ VUE_TAILWIND = "vue_tailwind",
BOOTSTRAP = "bootstrap",
IONIC_TAILWIND = "ionic_tailwind",
SVG = "svg",