Esteves Enzo commited on
Commit
cca515d
1 Parent(s): 209a88f

store own generation in storage by id

Browse files
app/api/collections/route.ts CHANGED
@@ -2,10 +2,16 @@ import { PrismaClient } from '@prisma/client'
2
 
3
  const prisma = new PrismaClient()
4
 
5
- export async function GET() {
 
6
  const images = await prisma.image.findMany({
7
  orderBy: {
8
  id: 'desc'
 
 
 
 
 
9
  }
10
  })
11
 
 
2
 
3
  const prisma = new PrismaClient()
4
 
5
+ export async function POST(request: Request) {
6
+ const { ids } = await request.json()
7
  const images = await prisma.image.findMany({
8
  orderBy: {
9
  id: 'desc'
10
+ },
11
+ where: {
12
+ id: {
13
+ in: ids,
14
+ }
15
  }
16
  })
17
 
assets/list_styles.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name": "(No style)",
4
+ "prompt": "{prompt}",
5
+ "negative_prompt": ""
6
+ },
7
+ {
8
+ "name": "Cinematic",
9
+ "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
10
+ "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured"
11
+ },
12
+ {
13
+ "name": "Photographic",
14
+ "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
15
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"
16
+ },
17
+ {
18
+ "name": "Anime",
19
+ "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
20
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast"
21
+ },
22
+ {
23
+ "name": "Manga",
24
+ "prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
25
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style"
26
+ },
27
+ {
28
+ "name": "Digital Art",
29
+ "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
30
+ "negative_prompt": "photo, photorealistic, realism, ugly"
31
+ },
32
+ {
33
+ "name": "Pixel art",
34
+ "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
35
+ "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic"
36
+ },
37
+ {
38
+ "name": "Fantasy art",
39
+ "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
40
+ "negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white"
41
+ },
42
+ {
43
+ "name": "Neonpunk",
44
+ "prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
45
+ "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured"
46
+ },
47
+ {
48
+ "name": "3D Model",
49
+ "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
50
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting"
51
+ }
52
+ ]
components/main/collections/index.tsx CHANGED
@@ -1,19 +1,19 @@
1
  import classNames from "classnames";
2
- import { createBreakpoint } from "react-use";
3
 
4
  import { Collection as CollectionType } from "@/type";
5
 
6
- import { useCollections } from "../hooks/useCollections";
7
  import { Collection } from "./collection";
8
  import { CollectionLoading } from "./loading";
9
 
10
  const useBreakpoint = createBreakpoint({ XL: 1280, L: 1024, S: 768, XS: 640 });
11
 
12
- export const Collections = () => {
13
- const { collections, loading } = useCollections();
14
  const breakpoint = useBreakpoint();
15
 
16
- if (loading) return;
17
 
18
  return (
19
  <div className="mx-auto grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-5 mt-8 lg:mt-14">
@@ -22,11 +22,10 @@ export const Collections = () => {
22
  <CollectionLoading key={i} prompt={collection.prompt} />
23
  ) : (
24
  <Collection
25
- key={i}
26
  index={i}
27
  collection={collection}
28
  className={classNames("", {
29
- // translate second and fourth item per row, row of 5 items
30
  "!translate-y-12":
31
  breakpoint === "XL"
32
  ? i % 5 === 1 || i % 5 === 3
 
1
  import classNames from "classnames";
2
+ import { createBreakpoint, useLocalStorage } from "react-use";
3
 
4
  import { Collection as CollectionType } from "@/type";
5
 
6
+ import { useCollections } from "@/components/main/hooks/useCollections";
7
  import { Collection } from "./collection";
8
  import { CollectionLoading } from "./loading";
9
 
10
  const useBreakpoint = createBreakpoint({ XL: 1280, L: 1024, S: 768, XS: 640 });
11
 
12
+ export const Collections: React.FC<{ category: string }> = ({ category }) => {
13
+ const { collections, loading } = useCollections(category);
14
  const breakpoint = useBreakpoint();
15
 
16
+ if (loading) return null;
17
 
18
  return (
19
  <div className="mx-auto grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-5 mt-8 lg:mt-14">
 
22
  <CollectionLoading key={i} prompt={collection.prompt} />
23
  ) : (
24
  <Collection
25
+ key={category + collection.id}
26
  index={i}
27
  collection={collection}
28
  className={classNames("", {
 
29
  "!translate-y-12":
30
  breakpoint === "XL"
31
  ? i % 5 === 1 || i % 5 === 3
components/main/hooks/useCollections.ts CHANGED
@@ -1,14 +1,22 @@
1
- import { Collection } from "@/type";
2
  import { useQuery } from "@tanstack/react-query";
 
3
 
4
- export const useCollections = () => {
 
5
  const {
6
  data: collections,
7
- isLoading: loading,
 
8
  } = useQuery(
9
  ["collections"],
10
  async () => {
11
- const response = await fetch("/api/collections", { method: "GET" })
 
 
 
 
 
 
12
  const data = await response.json()
13
 
14
  if (!response.ok) {
@@ -23,6 +31,10 @@ export const useCollections = () => {
23
  }
24
  );
25
 
 
 
 
 
26
  return {
27
  collections,
28
  loading,
 
 
1
  import { useQuery } from "@tanstack/react-query";
2
+ import { useLocalStorage, useUpdateEffect } from "react-use";
3
 
4
+ export const useCollections = (category: string) => {
5
+ const [myGenerationsId] = useLocalStorage<any>('my-own-generations', []);
6
  const {
7
  data: collections,
8
+ isFetching: loading,
9
+ refetch,
10
  } = useQuery(
11
  ["collections"],
12
  async () => {
13
+ // if category is my-own, send to reauest myGenerationsId array
14
+ const response = await fetch("/api/collections", {
15
+ method: "POST",
16
+ body: JSON.stringify({
17
+ ids: category === 'my-own' ? myGenerationsId : undefined,
18
+ }),
19
+ })
20
  const data = await response.json()
21
 
22
  if (!response.ok) {
 
31
  }
32
  );
33
 
34
+ useUpdateEffect(() => {
35
+ refetch()
36
+ }, [category]);
37
+
38
  return {
39
  collections,
40
  loading,
components/main/hooks/useInputGeneration.ts CHANGED
@@ -1,62 +1,14 @@
1
  import { useState } from "react"
2
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
3
- import { Collection } from "@/type"
4
 
5
- const list_styles = [
6
- {
7
- "name": "(No style)",
8
- "prompt": "{prompt}",
9
- "negative_prompt": "",
10
- },
11
- {
12
- "name": "Cinematic",
13
- "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
14
- "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
15
- },
16
- {
17
- "name": "Photographic",
18
- "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
19
- "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
20
- },
21
- {
22
- "name": "Anime",
23
- "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
24
- "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
25
- },
26
- {
27
- "name": "Manga",
28
- "prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
29
- "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
30
- },
31
- {
32
- "name": "Digital Art",
33
- "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
34
- "negative_prompt": "photo, photorealistic, realism, ugly",
35
- },
36
- {
37
- "name": "Pixel art",
38
- "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
39
- "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
40
- },
41
- {
42
- "name": "Fantasy art",
43
- "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
44
- "negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
45
- },
46
- {
47
- "name": "Neonpunk",
48
- "prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
49
- "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
50
- },
51
- {
52
- "name": "3D Model",
53
- "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
54
- "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
55
- },
56
- ]
57
 
58
  export const useInputGeneration = () => {
 
59
  const [style, setStyle] = useState<string>(list_styles[0].name)
 
60
  const { data: prompt } = useQuery(["prompt"], () => {
61
  return ''
62
  }, {
@@ -65,9 +17,7 @@ export const useInputGeneration = () => {
65
  refetchOnReconnect: false,
66
  initialData: ''
67
  })
68
- const setPrompt = (str:string) => {
69
- client.setQueryData(["prompt"], () => str)
70
- }
71
 
72
  const client = useQueryClient()
73
 
@@ -110,7 +60,9 @@ export const useInputGeneration = () => {
110
  return newArray
111
  })
112
 
113
- return data ?? []
 
 
114
  },
115
  )
116
 
@@ -122,9 +74,7 @@ export const useInputGeneration = () => {
122
  refetchOnReconnect: false,
123
  initialData: false
124
  })
125
- const setFirstGenerationDone = () => {
126
- client.setQueryData(["firstGenerationDone"], () => true)
127
- }
128
 
129
  return {
130
  prompt,
 
1
  import { useState } from "react"
2
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
3
+ import { useLocalStorage } from 'react-use';
4
 
5
+ import { Collection } from "@/type"
6
+ import list_styles from "@/assets/list_styles.json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  export const useInputGeneration = () => {
9
+ const [myGenerationsId, setGenerationsId] = useLocalStorage<any>('my-own-generations', []);
10
  const [style, setStyle] = useState<string>(list_styles[0].name)
11
+
12
  const { data: prompt } = useQuery(["prompt"], () => {
13
  return ''
14
  }, {
 
17
  refetchOnReconnect: false,
18
  initialData: ''
19
  })
20
+ const setPrompt = (str:string) => client.setQueryData(["prompt"], () => str)
 
 
21
 
22
  const client = useQueryClient()
23
 
 
60
  return newArray
61
  })
62
 
63
+ setGenerationsId(myGenerationsId?.length ? [...myGenerationsId, data?.blob?.id] : [data?.blob?.id])
64
+
65
+ return data ?? {}
66
  },
67
  )
68
 
 
74
  refetchOnReconnect: false,
75
  initialData: false
76
  })
77
+ const setFirstGenerationDone = () => client.setQueryData(["firstGenerationDone"], () => true)
 
 
78
 
79
  return {
80
  prompt,
components/main/index.tsx CHANGED
@@ -68,7 +68,7 @@ export const Main = () => {
68
  list_styles={list_styles}
69
  />
70
  </div>
71
- <Collections />
72
  </main>
73
  );
74
  };
 
68
  list_styles={list_styles}
69
  />
70
  </div>
71
+ <Collections category={category} />
72
  </main>
73
  );
74
  };