Spaces:
Running
Running
add prompts text file
Browse files- server.js +8 -3
- src/components/App.tsx +11 -1
- src/components/ask-ai/ask-ai.tsx +3 -0
- src/components/deploy-button/deploy-button.tsx +3 -0
server.js
CHANGED
@@ -128,7 +128,7 @@ app.get("/api/@me", checkUser, async (req, res) => {
|
|
128 |
});
|
129 |
|
130 |
app.post("/api/deploy", checkUser, async (req, res) => {
|
131 |
-
const { html, title, path } = req.body;
|
132 |
if (!html || (!path && !title)) {
|
133 |
return res.status(400).send({
|
134 |
ok: false,
|
@@ -187,7 +187,12 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
|
|
187 |
const file = new Blob([newHtml], { type: "text/html" });
|
188 |
file.name = "index.html"; // Add name property to the Blob
|
189 |
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
191 |
if (readme) {
|
192 |
const readmeFile = new Blob([readme], { type: "text/markdown" });
|
193 |
readmeFile.name = "README.md"; // Add name property to the Blob
|
@@ -216,7 +221,7 @@ app.post("/api/ask-ai", async (req, res) => {
|
|
216 |
});
|
217 |
}
|
218 |
|
219 |
-
|
220 |
let token = hf_token;
|
221 |
|
222 |
if (process.env.HF_TOKEN && process.env.HF_TOKEN !== "") {
|
|
|
128 |
});
|
129 |
|
130 |
app.post("/api/deploy", checkUser, async (req, res) => {
|
131 |
+
const { html, title, path, prompts } = req.body;
|
132 |
if (!html || (!path && !title)) {
|
133 |
return res.status(400).send({
|
134 |
ok: false,
|
|
|
187 |
const file = new Blob([newHtml], { type: "text/html" });
|
188 |
file.name = "index.html"; // Add name property to the Blob
|
189 |
|
190 |
+
// create prompt.txt file with all the prompts used, split by new line
|
191 |
+
const newPrompts = ``.concat(prompts.map((prompt) => prompt).join("\n"));
|
192 |
+
const promptFile = new Blob([newPrompts], { type: "text/plain" });
|
193 |
+
promptFile.name = "prompts.txt"; // Add name property to the Blob
|
194 |
+
|
195 |
+
const files = [file, promptFile];
|
196 |
if (readme) {
|
197 |
const readmeFile = new Blob([readme], { type: "text/markdown" });
|
198 |
readmeFile.name = "README.md"; // Add name property to the Blob
|
|
|
221 |
});
|
222 |
}
|
223 |
|
224 |
+
let { hf_token } = req.cookies;
|
225 |
let token = hf_token;
|
226 |
|
227 |
if (process.env.HF_TOKEN && process.env.HF_TOKEN !== "") {
|
src/components/App.tsx
CHANGED
@@ -36,6 +36,7 @@ function App() {
|
|
36 |
const [currentView, setCurrentView] = useState<"editor" | "preview">(
|
37 |
"editor"
|
38 |
);
|
|
|
39 |
|
40 |
const fetchMe = async () => {
|
41 |
const res = await fetch("/api/@me");
|
@@ -182,7 +183,13 @@ function App() {
|
|
182 |
}
|
183 |
}}
|
184 |
>
|
185 |
-
<DeployButton
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
</Header>
|
187 |
<main className="max-lg:flex-col flex w-full">
|
188 |
<div
|
@@ -233,6 +240,9 @@ function App() {
|
|
233 |
isAiWorking={isAiWorking}
|
234 |
setisAiWorking={setisAiWorking}
|
235 |
setView={setCurrentView}
|
|
|
|
|
|
|
236 |
onScrollToBottom={() => {
|
237 |
editorRef.current?.revealLine(
|
238 |
editorRef.current?.getModel()?.getLineCount() ?? 0
|
|
|
36 |
const [currentView, setCurrentView] = useState<"editor" | "preview">(
|
37 |
"editor"
|
38 |
);
|
39 |
+
const [prompts, setPrompts] = useState<string[]>([]);
|
40 |
|
41 |
const fetchMe = async () => {
|
42 |
const res = await fetch("/api/@me");
|
|
|
183 |
}
|
184 |
}}
|
185 |
>
|
186 |
+
<DeployButton
|
187 |
+
html={html}
|
188 |
+
error={error}
|
189 |
+
auth={auth}
|
190 |
+
setHtml={setHtml}
|
191 |
+
prompts={prompts}
|
192 |
+
/>
|
193 |
</Header>
|
194 |
<main className="max-lg:flex-col flex w-full">
|
195 |
<div
|
|
|
240 |
isAiWorking={isAiWorking}
|
241 |
setisAiWorking={setisAiWorking}
|
242 |
setView={setCurrentView}
|
243 |
+
onNewPrompt={(prompt) => {
|
244 |
+
setPrompts((prev) => [...prev, prompt]);
|
245 |
+
}}
|
246 |
onScrollToBottom={() => {
|
247 |
editorRef.current?.revealLine(
|
248 |
editorRef.current?.getModel()?.getLineCount() ?? 0
|
src/components/ask-ai/ask-ai.tsx
CHANGED
@@ -21,11 +21,13 @@ function AskAI({
|
|
21 |
isAiWorking,
|
22 |
setisAiWorking,
|
23 |
setView,
|
|
|
24 |
}: {
|
25 |
html: string;
|
26 |
setHtml: (html: string) => void;
|
27 |
onScrollToBottom: () => void;
|
28 |
isAiWorking: boolean;
|
|
|
29 |
setView: React.Dispatch<React.SetStateAction<"editor" | "preview">>;
|
30 |
setisAiWorking: React.Dispatch<React.SetStateAction<boolean>>;
|
31 |
}) {
|
@@ -49,6 +51,7 @@ function AskAI({
|
|
49 |
let contentResponse = "";
|
50 |
let lastRenderTime = 0;
|
51 |
try {
|
|
|
52 |
const request = await fetch("/api/ask-ai", {
|
53 |
method: "POST",
|
54 |
body: JSON.stringify({
|
|
|
21 |
isAiWorking,
|
22 |
setisAiWorking,
|
23 |
setView,
|
24 |
+
onNewPrompt,
|
25 |
}: {
|
26 |
html: string;
|
27 |
setHtml: (html: string) => void;
|
28 |
onScrollToBottom: () => void;
|
29 |
isAiWorking: boolean;
|
30 |
+
onNewPrompt: (prompt: string) => void;
|
31 |
setView: React.Dispatch<React.SetStateAction<"editor" | "preview">>;
|
32 |
setisAiWorking: React.Dispatch<React.SetStateAction<boolean>>;
|
33 |
}) {
|
|
|
51 |
let contentResponse = "";
|
52 |
let lastRenderTime = 0;
|
53 |
try {
|
54 |
+
onNewPrompt(prompt);
|
55 |
const request = await fetch("/api/ask-ai", {
|
56 |
method: "POST",
|
57 |
body: JSON.stringify({
|
src/components/deploy-button/deploy-button.tsx
CHANGED
@@ -29,11 +29,13 @@ function DeployButton({
|
|
29 |
error = false,
|
30 |
auth,
|
31 |
setHtml,
|
|
|
32 |
}: {
|
33 |
html: string;
|
34 |
error: boolean;
|
35 |
auth?: Auth;
|
36 |
setHtml: (html: string) => void;
|
|
|
37 |
}) {
|
38 |
const [open, setOpen] = useState(false);
|
39 |
const [loading, setLoading] = useState(false);
|
@@ -53,6 +55,7 @@ function DeployButton({
|
|
53 |
title: config.title,
|
54 |
path,
|
55 |
html,
|
|
|
56 |
}),
|
57 |
headers: {
|
58 |
"Content-Type": "application/json",
|
|
|
29 |
error = false,
|
30 |
auth,
|
31 |
setHtml,
|
32 |
+
prompts,
|
33 |
}: {
|
34 |
html: string;
|
35 |
error: boolean;
|
36 |
auth?: Auth;
|
37 |
setHtml: (html: string) => void;
|
38 |
+
prompts: string[];
|
39 |
}) {
|
40 |
const [open, setOpen] = useState(false);
|
41 |
const [loading, setLoading] = useState(false);
|
|
|
55 |
title: config.title,
|
56 |
path,
|
57 |
html,
|
58 |
+
prompts,
|
59 |
}),
|
60 |
headers: {
|
61 |
"Content-Type": "application/json",
|