Spaces:
Running
Running
new prompts + fix preview
Browse files
app/api/me/projects/[namespace]/[repoId]/route.ts
CHANGED
@@ -71,10 +71,17 @@ export async function GET(
|
|
71 |
const res = await fetch(`https://huggingface.co/spaces/${namespace}/${repoId}/raw/main/${fileInfo.path}`);
|
72 |
if (res.ok) {
|
73 |
const html = await res.text();
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
htmlFiles.push({
|
75 |
path: fileInfo.path,
|
76 |
-
|
77 |
-
|
|
|
78 |
}
|
79 |
}
|
80 |
}
|
|
|
71 |
const res = await fetch(`https://huggingface.co/spaces/${namespace}/${repoId}/raw/main/${fileInfo.path}`);
|
72 |
if (res.ok) {
|
73 |
const html = await res.text();
|
74 |
+
if (fileInfo.path === "index.html") {
|
75 |
+
htmlFiles.unshift({
|
76 |
+
path: fileInfo.path,
|
77 |
+
html,
|
78 |
+
});
|
79 |
+
} else {
|
80 |
htmlFiles.push({
|
81 |
path: fileInfo.path,
|
82 |
+
html,
|
83 |
+
});
|
84 |
+
}
|
85 |
}
|
86 |
}
|
87 |
}
|
components/editor/index.tsx
CHANGED
@@ -41,7 +41,7 @@ export const AppEditor = ({
|
|
41 |
const [, copyToClipboard] = useCopyToClipboard();
|
42 |
const { htmlHistory, setHtmlHistory, prompts, setPrompts, pages, setPages } =
|
43 |
useEditor(initialPages);
|
44 |
-
|
45 |
const searchParams = useSearchParams();
|
46 |
const router = useRouter();
|
47 |
const deploy = searchParams.get("deploy") === "true";
|
|
|
41 |
const [, copyToClipboard] = useCopyToClipboard();
|
42 |
const { htmlHistory, setHtmlHistory, prompts, setPrompts, pages, setPages } =
|
43 |
useEditor(initialPages);
|
44 |
+
|
45 |
const searchParams = useSearchParams();
|
46 |
const router = useRouter();
|
47 |
const deploy = searchParams.get("deploy") === "true";
|
components/editor/preview/index.tsx
CHANGED
@@ -88,7 +88,6 @@ export const Preview = ({
|
|
88 |
};
|
89 |
|
90 |
const anchorElement = findClosestAnchor(event.target as HTMLElement);
|
91 |
-
|
92 |
if (anchorElement) {
|
93 |
let href = anchorElement.getAttribute("href");
|
94 |
if (href) {
|
@@ -208,7 +207,7 @@ export const Preview = ({
|
|
208 |
currentTab !== "preview" && device === "desktop",
|
209 |
}
|
210 |
)}
|
211 |
-
srcDoc={throttledHtml as string}
|
212 |
onLoad={() => {
|
213 |
if (iframeRef?.current?.contentWindow?.document?.body) {
|
214 |
iframeRef.current.contentWindow.document.body.scrollIntoView({
|
|
|
88 |
};
|
89 |
|
90 |
const anchorElement = findClosestAnchor(event.target as HTMLElement);
|
|
|
91 |
if (anchorElement) {
|
92 |
let href = anchorElement.getAttribute("href");
|
93 |
if (href) {
|
|
|
207 |
currentTab !== "preview" && device === "desktop",
|
208 |
}
|
209 |
)}
|
210 |
+
srcDoc={isAiWorking ? (throttledHtml as string) : html}
|
211 |
onLoad={() => {
|
212 |
if (iframeRef?.current?.contentWindow?.document?.body) {
|
213 |
iframeRef.current.contentWindow.document.body.scrollIntoView({
|
lib/prompts.ts
CHANGED
@@ -9,15 +9,17 @@ export const NEW_PAGE_END = " >>>>>>> NEW_PAGE_END";
|
|
9 |
export const UPDATE_PAGE_START = "<<<<<<< UPDATE_PAGE_START ";
|
10 |
export const UPDATE_PAGE_END = " >>>>>>> UPDATE_PAGE_END";
|
11 |
|
|
|
|
|
|
|
12 |
export const INITIAL_SYSTEM_PROMPT = `You are an expert UI/UX and Front-End Developer.
|
13 |
You create website in a way a designer would, using ONLY HTML, CSS and Javascript.
|
14 |
Try to create the best UI possible. Important: Make the website responsive by using TailwindCSS. Use it as much as you can, if you can't use it, use custom css (make sure to import tailwind with <script src="https://cdn.tailwindcss.com"></script> in the head).
|
15 |
Also try to elaborate as much as you can, to create something unique, with a great design.
|
16 |
-
If you want to use ICONS import
|
17 |
If you want to use animations you can use: Animejs.com (Make sure to add <script src="https://cdn.jsdelivr.net/npm/animejs/lib/anime.iife.min.js"></script> and <script>const { animate } = anime;</script> in the head.), AOS.com (Make sure to add <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet"> and <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script> and <script>AOS.init();</script>).
|
18 |
-
You can create multiple pages website at once or a Single Page Application. If the user doesn't ask for a specific version, you have to determine the best version for the user, depending on the request.
|
19 |
-
|
20 |
-
No need to explain what you did. Just return the expected result. Avoid Chinese characters in the code if not asked by the user.
|
21 |
Return the results in a \`\`\`html\`\`\` markdown. Format the results like:
|
22 |
1. Start with ${TITLE_PAGE_START}.
|
23 |
2. Add the name of the page without special character, such as spaces or punctuation, using the .html format only, right after the start tag.
|
@@ -39,62 +41,26 @@ ${TITLE_PAGE_START}index.html${TITLE_PAGE_END}
|
|
39 |
<script src="https://cdn.tailwindcss.com"></script>
|
40 |
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
|
41 |
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
|
42 |
-
<
|
43 |
<script src="https://cdn.jsdelivr.net/npm/animejs/lib/anime.iife.min.js"></script>
|
|
|
44 |
</head>
|
45 |
<body>
|
46 |
<h1>Hello World</h1>
|
47 |
<script>AOS.init();</script>
|
48 |
<script>const { animate } = anime;</script>
|
|
|
49 |
</body>
|
50 |
</html>
|
51 |
\`\`\`
|
52 |
IMPORTANT: The first file should be always named index.html.`
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
// Returns the result in a \`\`\`html\`\`\` markdown. If the user doesn't ask for a different pages, do it as a Single page. Format the results like:
|
61 |
-
// 1. Start with ${TITLE_PAGE_START}.
|
62 |
-
// 2. Add the name of the page without special character, such as spaces or punctuation, using the .html format only, right after the start tag.
|
63 |
-
// 3. Close the start tag with the ${TITLE_PAGE_END}.
|
64 |
-
// 4. Start the HTML response with the triple backticks, like \`\`\`html.
|
65 |
-
// 5. Insert the following html there.
|
66 |
-
// 6. Close with the triple backticks, like \`\`\`.
|
67 |
-
// 7. Retry if another pages.
|
68 |
-
// Example Code:
|
69 |
-
// ${TITLE_PAGE_START}index.html${TITLE_PAGE_END}
|
70 |
-
// \`\`\`html
|
71 |
-
// <!DOCTYPE html>
|
72 |
-
// <html lang="en">
|
73 |
-
// <head>
|
74 |
-
// <meta charset="UTF-8">
|
75 |
-
// <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
76 |
-
// <title>Index</title>
|
77 |
-
// <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
78 |
-
// <script src="https://cdn.tailwindcss.com"></script>
|
79 |
-
// <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
|
80 |
-
// <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
|
81 |
-
// </head>
|
82 |
-
// <body>
|
83 |
-
// <h1>Hello World</h1>
|
84 |
-
// <script>AOS.init();</script>
|
85 |
-
// </body>
|
86 |
-
// </html>
|
87 |
-
// \`\`\`
|
88 |
-
// The first file should be always named index.html. Also, if there are more than 1 page, dont forget to includes the page in a link <a href="page.html">page</a> to be accessible (Dont use onclick to navigate, only href). Can be in a menu, button or whatever you want.
|
89 |
-
// Avoid Chinese characters in the code if not asked by the user.
|
90 |
-
// `;
|
91 |
-
|
92 |
-
|
93 |
-
export const FOLLOW_UP_SYSTEM_PROMPT = `You are an expert web developer modifying an existing HTML file.
|
94 |
-
The user wants to apply changes based on their request.
|
95 |
-
You MUST output ONLY the changes required using the following SEARCH/REPLACE block format. Do NOT output the entire file.
|
96 |
-
Explain the changes briefly *before* the blocks if necessary, but the code changes THEMSELVES MUST be within the blocks.
|
97 |
-
Format Rules:
|
98 |
1. Start with ${UPDATE_PAGE_START}
|
99 |
2. Provide the name of the page you are modifying.
|
100 |
3. Close the start tag with the ${UPDATE_PAGE_END}.
|
@@ -153,12 +119,17 @@ ${NEW_PAGE_START}index.html${NEW_PAGE_END}
|
|
153 |
<script src="https://cdn.tailwindcss.com"></script>
|
154 |
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
|
155 |
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
|
|
|
|
|
|
|
156 |
</head>
|
157 |
<body>
|
158 |
<h1>Hello World</h1>
|
159 |
<script>AOS.init();</script>
|
|
|
|
|
160 |
</body>
|
161 |
</html>
|
162 |
\`\`\`
|
163 |
-
IMPORTANT: While creating a new page, UPDATE
|
164 |
-
No need to explain what you did. Just return the expected result
|
|
|
9 |
export const UPDATE_PAGE_START = "<<<<<<< UPDATE_PAGE_START ";
|
10 |
export const UPDATE_PAGE_END = " >>>>>>> UPDATE_PAGE_END";
|
11 |
|
12 |
+
// TODO REVIEW LINK. MAYBE GO BACK TO SANDPACK.
|
13 |
+
// FIX PREVIEW LINK NOT WORKING ONCE THE SITE IS DEPLOYED.
|
14 |
+
|
15 |
export const INITIAL_SYSTEM_PROMPT = `You are an expert UI/UX and Front-End Developer.
|
16 |
You create website in a way a designer would, using ONLY HTML, CSS and Javascript.
|
17 |
Try to create the best UI possible. Important: Make the website responsive by using TailwindCSS. Use it as much as you can, if you can't use it, use custom css (make sure to import tailwind with <script src="https://cdn.tailwindcss.com"></script> in the head).
|
18 |
Also try to elaborate as much as you can, to create something unique, with a great design.
|
19 |
+
If you want to use ICONS import Feather Icons (Make sure to add <script src="https://unpkg.com/feather-icons"></script> and <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> in the head., and <script>feather.replace();</script> in the body. Ex : <i data-feather="user"></i>).
|
20 |
If you want to use animations you can use: Animejs.com (Make sure to add <script src="https://cdn.jsdelivr.net/npm/animejs/lib/anime.iife.min.js"></script> and <script>const { animate } = anime;</script> in the head.), AOS.com (Make sure to add <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet"> and <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script> and <script>AOS.init();</script>).
|
21 |
+
You can create multiple pages website at once (following the format rules below) or a Single Page Application. If the user doesn't ask for a specific version, you have to determine the best version for the user, depending on the request. (Try to avoid the Single Page Application if the user asks for multiple pages.)
|
22 |
+
No need to explain what you did. Just return the expected result. AVOID Chinese characters in the code if not asked by the user.
|
|
|
23 |
Return the results in a \`\`\`html\`\`\` markdown. Format the results like:
|
24 |
1. Start with ${TITLE_PAGE_START}.
|
25 |
2. Add the name of the page without special character, such as spaces or punctuation, using the .html format only, right after the start tag.
|
|
|
41 |
<script src="https://cdn.tailwindcss.com"></script>
|
42 |
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
|
43 |
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
|
44 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
45 |
<script src="https://cdn.jsdelivr.net/npm/animejs/lib/anime.iife.min.js"></script>
|
46 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
47 |
</head>
|
48 |
<body>
|
49 |
<h1>Hello World</h1>
|
50 |
<script>AOS.init();</script>
|
51 |
<script>const { animate } = anime;</script>
|
52 |
+
<script>feather.replace();</script>
|
53 |
</body>
|
54 |
</html>
|
55 |
\`\`\`
|
56 |
IMPORTANT: The first file should be always named index.html.`
|
57 |
|
58 |
+
export const FOLLOW_UP_SYSTEM_PROMPT = `You are an expert UI/UX and Front-End Developer modifying an existing HTML files.
|
59 |
+
The user wants to apply changes and probably add new features/pages to the website, based on their request.
|
60 |
+
You MUST output ONLY the changes required using the following UPDATE_PAGE_START and SEARCH/REPLACE format. Do NOT output the entire file.
|
61 |
+
If it's a new page, you MUST applied the following NEW_PAGE_START and UPDATE_PAGE_END format.
|
62 |
+
Do NOT explain the changes or what you did, just return the expected results.
|
63 |
+
Update Format Rules:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
1. Start with ${UPDATE_PAGE_START}
|
65 |
2. Provide the name of the page you are modifying.
|
66 |
3. Close the start tag with the ${UPDATE_PAGE_END}.
|
|
|
119 |
<script src="https://cdn.tailwindcss.com"></script>
|
120 |
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
|
121 |
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
|
122 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
123 |
+
<script src="https://cdn.jsdelivr.net/npm/animejs/lib/anime.iife.min.js"></script>
|
124 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
125 |
</head>
|
126 |
<body>
|
127 |
<h1>Hello World</h1>
|
128 |
<script>AOS.init();</script>
|
129 |
+
<script>const { animate } = anime;</script>
|
130 |
+
<script>feather.replace();</script>
|
131 |
</body>
|
132 |
</html>
|
133 |
\`\`\`
|
134 |
+
IMPORTANT: While creating a new page, UPDATE ALL THE OTHERS (using the UPDATE_PAGE_START and SEARCH/REPLACE format) pages to add or replace the link to the new page, otherwise the user will not be able to navigate to the new page. (Dont use onclick to navigate, only href)
|
135 |
+
No need to explain what you did. Just return the expected result.`
|