Spaces:
Running
Running
handle error
Browse files- app/_actions/generate.ts +34 -23
- app/_components/generation/index.tsx +7 -5
- app/layout.tsx +4 -0
- package-lock.json +21 -0
- package.json +1 -0
app/_actions/generate.ts
CHANGED
@@ -12,29 +12,40 @@ export async function generate({ brand_name, industry, description }: Form) {
|
|
12 |
}
|
13 |
const inference = new HfInference(process.env.HF_ACCESS_TOKEN);
|
14 |
|
15 |
-
const prompt = await inference
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
if (prompt?.choices[0]?.message?.content) {
|
40 |
const hfRequest = await inference.textToImage({
|
|
|
12 |
}
|
13 |
const inference = new HfInference(process.env.HF_ACCESS_TOKEN);
|
14 |
|
15 |
+
const prompt: any = await inference
|
16 |
+
.chatCompletion({
|
17 |
+
model: "meta-llama/Meta-Llama-3.1-70B-Instruct",
|
18 |
+
messages: [
|
19 |
+
{ role: "user", content: "lee, a noodle restaurant" },
|
20 |
+
{
|
21 |
+
role: "assistant",
|
22 |
+
content:
|
23 |
+
'logo,Minimalist,A pair of chopsticks and a bowl of rice with the word "Lee",',
|
24 |
+
},
|
25 |
+
{ role: "user", content: "cat shop" },
|
26 |
+
{ role: "assistant", content: "wablogo,Minimalist,Leaf and cat,logo," },
|
27 |
+
{ role: "user", content: "Ato, real estate company" },
|
28 |
+
{
|
29 |
+
role: "assistant",
|
30 |
+
content:
|
31 |
+
'logo,Minimalist,A man stands in front of a door,his shadow forming the word "A",',
|
32 |
+
},
|
33 |
+
{ role: "user", content: `${brand_name}, ${description}, ${industry}` },
|
34 |
+
],
|
35 |
+
temperature: 0.5,
|
36 |
+
max_tokens: 1024,
|
37 |
+
top_p: 0.7,
|
38 |
+
})
|
39 |
+
.then((res) => res)
|
40 |
+
.catch((err) => {
|
41 |
+
return { error: err.message };
|
42 |
+
});
|
43 |
+
|
44 |
+
if (prompt?.error) {
|
45 |
+
return {
|
46 |
+
error: prompt.error,
|
47 |
+
};
|
48 |
+
}
|
49 |
|
50 |
if (prompt?.choices[0]?.message?.content) {
|
51 |
const hfRequest = await inference.textToImage({
|
app/_components/generation/index.tsx
CHANGED
@@ -10,6 +10,7 @@ import { Steps } from "./step/list";
|
|
10 |
import { Industry } from "./step/industry";
|
11 |
import { Description } from "./step/description";
|
12 |
import classNames from "classnames";
|
|
|
13 |
|
14 |
export const Generation = () => {
|
15 |
const [form, setForm] = useState<Form>({
|
@@ -26,13 +27,14 @@ export const Generation = () => {
|
|
26 |
const handleGenerate = async () => {
|
27 |
if (loading) return;
|
28 |
setLoading(true);
|
29 |
-
|
30 |
-
|
31 |
setResult(response.data);
|
32 |
-
}
|
33 |
-
|
|
|
|
|
34 |
}
|
35 |
-
setLoading(false);
|
36 |
};
|
37 |
|
38 |
return (
|
|
|
10 |
import { Industry } from "./step/industry";
|
11 |
import { Description } from "./step/description";
|
12 |
import classNames from "classnames";
|
13 |
+
import { toast } from "react-toastify";
|
14 |
|
15 |
export const Generation = () => {
|
16 |
const [form, setForm] = useState<Form>({
|
|
|
27 |
const handleGenerate = async () => {
|
28 |
if (loading) return;
|
29 |
setLoading(true);
|
30 |
+
try {
|
31 |
+
const response = await generate(form);
|
32 |
setResult(response.data);
|
33 |
+
} catch (err) {
|
34 |
+
toast.error("An error occurred. Please try again later.");
|
35 |
+
} finally {
|
36 |
+
setLoading(false);
|
37 |
}
|
|
|
38 |
};
|
39 |
|
40 |
return (
|
app/layout.tsx
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
import type { Metadata } from "next";
|
2 |
import localFont from "next/font/local";
|
|
|
|
|
|
|
3 |
import "@/assets/globals.css";
|
4 |
import { Navigation } from "@/components/_navigation";
|
5 |
|
@@ -54,6 +57,7 @@ export default function RootLayout({
|
|
54 |
<Navigation />
|
55 |
{children}
|
56 |
</div>
|
|
|
57 |
</body>
|
58 |
</html>
|
59 |
);
|
|
|
1 |
import type { Metadata } from "next";
|
2 |
import localFont from "next/font/local";
|
3 |
+
import { ToastContainer } from "react-toastify";
|
4 |
+
import "react-toastify/dist/ReactToastify.css";
|
5 |
+
|
6 |
import "@/assets/globals.css";
|
7 |
import { Navigation } from "@/components/_navigation";
|
8 |
|
|
|
57 |
<Navigation />
|
58 |
{children}
|
59 |
</div>
|
60 |
+
<ToastContainer />
|
61 |
</body>
|
62 |
</html>
|
63 |
);
|
package-lock.json
CHANGED
@@ -16,6 +16,7 @@
|
|
16 |
"react": "^18",
|
17 |
"react-dom": "^18",
|
18 |
"react-icons": "^5.3.0",
|
|
|
19 |
"react-use": "^17.5.1"
|
20 |
},
|
21 |
"devDependencies": {
|
@@ -1400,6 +1401,14 @@
|
|
1400 |
"resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz",
|
1401 |
"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA=="
|
1402 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1403 |
"node_modules/color": {
|
1404 |
"version": "4.2.3",
|
1405 |
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
|
@@ -4494,6 +4503,18 @@
|
|
4494 |
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==",
|
4495 |
"dev": true
|
4496 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4497 |
"node_modules/react-universal-interface": {
|
4498 |
"version": "0.6.2",
|
4499 |
"resolved": "https://registry.npmjs.org/react-universal-interface/-/react-universal-interface-0.6.2.tgz",
|
|
|
16 |
"react": "^18",
|
17 |
"react-dom": "^18",
|
18 |
"react-icons": "^5.3.0",
|
19 |
+
"react-toastify": "^10.0.5",
|
20 |
"react-use": "^17.5.1"
|
21 |
},
|
22 |
"devDependencies": {
|
|
|
1401 |
"resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz",
|
1402 |
"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA=="
|
1403 |
},
|
1404 |
+
"node_modules/clsx": {
|
1405 |
+
"version": "2.1.1",
|
1406 |
+
"resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
|
1407 |
+
"integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==",
|
1408 |
+
"engines": {
|
1409 |
+
"node": ">=6"
|
1410 |
+
}
|
1411 |
+
},
|
1412 |
"node_modules/color": {
|
1413 |
"version": "4.2.3",
|
1414 |
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
|
|
|
4503 |
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==",
|
4504 |
"dev": true
|
4505 |
},
|
4506 |
+
"node_modules/react-toastify": {
|
4507 |
+
"version": "10.0.5",
|
4508 |
+
"resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-10.0.5.tgz",
|
4509 |
+
"integrity": "sha512-mNKt2jBXJg4O7pSdbNUfDdTsK9FIdikfsIE/yUCxbAEXl4HMyJaivrVFcn3Elvt5xvCQYhUZm+hqTIu1UXM3Pw==",
|
4510 |
+
"dependencies": {
|
4511 |
+
"clsx": "^2.1.0"
|
4512 |
+
},
|
4513 |
+
"peerDependencies": {
|
4514 |
+
"react": ">=18",
|
4515 |
+
"react-dom": ">=18"
|
4516 |
+
}
|
4517 |
+
},
|
4518 |
"node_modules/react-universal-interface": {
|
4519 |
"version": "0.6.2",
|
4520 |
"resolved": "https://registry.npmjs.org/react-universal-interface/-/react-universal-interface-0.6.2.tgz",
|
package.json
CHANGED
@@ -17,6 +17,7 @@
|
|
17 |
"react": "^18",
|
18 |
"react-dom": "^18",
|
19 |
"react-icons": "^5.3.0",
|
|
|
20 |
"react-use": "^17.5.1"
|
21 |
},
|
22 |
"devDependencies": {
|
|
|
17 |
"react": "^18",
|
18 |
"react-dom": "^18",
|
19 |
"react-icons": "^5.3.0",
|
20 |
+
"react-toastify": "^10.0.5",
|
21 |
"react-use": "^17.5.1"
|
22 |
},
|
23 |
"devDependencies": {
|