Spaces:
Runtime error
Runtime error
Esteves Enzo
commited on
Commit
·
02b9873
1
Parent(s):
6f0b822
add advanced settings
Browse files
components/main/collections/collection.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { useMemo } from "react";
|
|
| 2 |
import { motion } from "framer-motion";
|
| 3 |
|
| 4 |
import { Collection as CollectionType } from "@/type";
|
|
|
|
| 5 |
|
| 6 |
interface Props {
|
| 7 |
index: number;
|
|
@@ -14,6 +15,8 @@ export const Collection: React.FC<Props> = ({
|
|
| 14 |
index,
|
| 15 |
className,
|
| 16 |
}) => {
|
|
|
|
|
|
|
| 17 |
const arrayBufferToBase64 = (buffer: ArrayBuffer) => {
|
| 18 |
let binary = "";
|
| 19 |
const bytes = [].slice.call(new Uint8Array(buffer));
|
|
@@ -43,7 +46,10 @@ export const Collection: React.FC<Props> = ({
|
|
| 43 |
<p className="text-lg font-medium text-white lowercase leading-snug">
|
| 44 |
{collection.prompt}
|
| 45 |
</p>
|
| 46 |
-
<p
|
|
|
|
|
|
|
|
|
|
| 47 |
Try it now
|
| 48 |
</p>
|
| 49 |
</div>
|
|
|
|
| 2 |
import { motion } from "framer-motion";
|
| 3 |
|
| 4 |
import { Collection as CollectionType } from "@/type";
|
| 5 |
+
import { useInputGeneration } from "@/components/main/hooks/useInputGeneration";
|
| 6 |
|
| 7 |
interface Props {
|
| 8 |
index: number;
|
|
|
|
| 15 |
index,
|
| 16 |
className,
|
| 17 |
}) => {
|
| 18 |
+
const { setPrompt } = useInputGeneration();
|
| 19 |
+
|
| 20 |
const arrayBufferToBase64 = (buffer: ArrayBuffer) => {
|
| 21 |
let binary = "";
|
| 22 |
const bytes = [].slice.call(new Uint8Array(buffer));
|
|
|
|
| 46 |
<p className="text-lg font-medium text-white lowercase leading-snug">
|
| 47 |
{collection.prompt}
|
| 48 |
</p>
|
| 49 |
+
<p
|
| 50 |
+
className="text-white text-sm text-right font-semibold mt-2"
|
| 51 |
+
onClick={() => setPrompt(collection.prompt)}
|
| 52 |
+
>
|
| 53 |
Try it now
|
| 54 |
</p>
|
| 55 |
</div>
|
components/main/hooks/useInputGeneration.ts
CHANGED
|
@@ -2,8 +2,73 @@ import { useState } from "react"
|
|
| 2 |
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
| 3 |
import { Collection } from "@/type"
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
export const useInputGeneration = () => {
|
| 6 |
-
const [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
const client = useQueryClient()
|
| 8 |
|
| 9 |
const { mutate: submit, isLoading: loading } = useMutation(
|
|
@@ -21,10 +86,13 @@ export const useInputGeneration = () => {
|
|
| 21 |
}, ...old as Collection[]]
|
| 22 |
})
|
| 23 |
|
|
|
|
|
|
|
| 24 |
const response = await fetch("/api", {
|
| 25 |
method: "POST",
|
| 26 |
body: JSON.stringify({
|
| 27 |
-
inputs: prompt,
|
|
|
|
| 28 |
}),
|
| 29 |
})
|
| 30 |
const data = await response.json()
|
|
@@ -63,7 +131,10 @@ export const useInputGeneration = () => {
|
|
| 63 |
setPrompt,
|
| 64 |
loading,
|
| 65 |
submit,
|
| 66 |
-
hasMadeFirstGeneration
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
}
|
|
|
|
| 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 |
+
}, {
|
| 63 |
+
refetchOnWindowFocus: false,
|
| 64 |
+
refetchOnMount: false,
|
| 65 |
+
refetchOnReconnect: false,
|
| 66 |
+
initialData: ''
|
| 67 |
+
})
|
| 68 |
+
const setPrompt = (str:string) => {
|
| 69 |
+
client.setQueryData(["prompt"], () => str)
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
const client = useQueryClient()
|
| 73 |
|
| 74 |
const { mutate: submit, isLoading: loading } = useMutation(
|
|
|
|
| 86 |
}, ...old as Collection[]]
|
| 87 |
})
|
| 88 |
|
| 89 |
+
const findStyle = list_styles.find((item) => item.name === style)
|
| 90 |
+
|
| 91 |
const response = await fetch("/api", {
|
| 92 |
method: "POST",
|
| 93 |
body: JSON.stringify({
|
| 94 |
+
inputs: findStyle?.prompt.replace("{prompt}", prompt) ?? prompt,
|
| 95 |
+
negative_prompt: findStyle?.negative_prompt ?? "",
|
| 96 |
}),
|
| 97 |
})
|
| 98 |
const data = await response.json()
|
|
|
|
| 131 |
setPrompt,
|
| 132 |
loading,
|
| 133 |
submit,
|
| 134 |
+
hasMadeFirstGeneration,
|
| 135 |
+
list_styles,
|
| 136 |
+
style,
|
| 137 |
+
setStyle
|
| 138 |
}
|
| 139 |
|
| 140 |
}
|
components/main/index.tsx
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
import { useState } from "react";
|
| 4 |
-
import { HiUserGroup, HiHeart } from "react-icons/hi2";
|
| 5 |
|
| 6 |
import { InputGeneration } from "@/components/input-generation";
|
| 7 |
import { Button } from "@/components/button";
|
| 8 |
|
| 9 |
import { useInputGeneration } from "./hooks/useInputGeneration";
|
| 10 |
import { Collections } from "./collections";
|
|
|
|
| 11 |
|
| 12 |
const categories = [
|
| 13 |
{
|
|
@@ -17,25 +18,36 @@ const categories = [
|
|
| 17 |
},
|
| 18 |
{
|
| 19 |
key: "my-own",
|
| 20 |
-
label: "My
|
| 21 |
icon: <HiHeart className="text-2xl" />,
|
| 22 |
},
|
| 23 |
];
|
| 24 |
|
| 25 |
export const Main = () => {
|
| 26 |
-
const { prompt, setPrompt, submit, loading } =
|
|
|
|
| 27 |
const [category, setCategory] = useState<string>("community");
|
|
|
|
| 28 |
|
| 29 |
return (
|
| 30 |
<main className="px-6 z-[2] relative max-w-[1722px] mx-auto">
|
| 31 |
<div className="py-2 pl-2 pr-4 bg-black bg-opacity-30 backdrop-blur-sm sticky top-6 z-10 rounded-full">
|
| 32 |
<div className="flex flex-col lg:flex-row items-center justify-between w-full">
|
| 33 |
-
<
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
<div className="flex items-center justify-center lg:justify-end gap-5 w-full mt-6 lg:mt-0">
|
| 40 |
{categories.map(({ key, label, icon }) => (
|
| 41 |
<Button
|
|
@@ -49,6 +61,12 @@ export const Main = () => {
|
|
| 49 |
))}
|
| 50 |
</div>
|
| 51 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</div>
|
| 53 |
<Collections />
|
| 54 |
</main>
|
|
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
import { useState } from "react";
|
| 4 |
+
import { HiUserGroup, HiHeart, HiAdjustmentsHorizontal } from "react-icons/hi2";
|
| 5 |
|
| 6 |
import { InputGeneration } from "@/components/input-generation";
|
| 7 |
import { Button } from "@/components/button";
|
| 8 |
|
| 9 |
import { useInputGeneration } from "./hooks/useInputGeneration";
|
| 10 |
import { Collections } from "./collections";
|
| 11 |
+
import { Settings } from "./settings";
|
| 12 |
|
| 13 |
const categories = [
|
| 14 |
{
|
|
|
|
| 18 |
},
|
| 19 |
{
|
| 20 |
key: "my-own",
|
| 21 |
+
label: "My generations",
|
| 22 |
icon: <HiHeart className="text-2xl" />,
|
| 23 |
},
|
| 24 |
];
|
| 25 |
|
| 26 |
export const Main = () => {
|
| 27 |
+
const { prompt, setPrompt, submit, loading, list_styles, style, setStyle } =
|
| 28 |
+
useInputGeneration();
|
| 29 |
const [category, setCategory] = useState<string>("community");
|
| 30 |
+
const [advancedSettings, setAdvancedSettings] = useState<boolean>(false);
|
| 31 |
|
| 32 |
return (
|
| 33 |
<main className="px-6 z-[2] relative max-w-[1722px] mx-auto">
|
| 34 |
<div className="py-2 pl-2 pr-4 bg-black bg-opacity-30 backdrop-blur-sm sticky top-6 z-10 rounded-full">
|
| 35 |
<div className="flex flex-col lg:flex-row items-center justify-between w-full">
|
| 36 |
+
<div className="flex items-center justify-start gap-3 w-full">
|
| 37 |
+
<InputGeneration
|
| 38 |
+
prompt={prompt}
|
| 39 |
+
onChange={setPrompt}
|
| 40 |
+
onSubmit={submit}
|
| 41 |
+
loading={loading}
|
| 42 |
+
/>
|
| 43 |
+
<p
|
| 44 |
+
className="text-white/70 font-medium text-sm flex items-center justify-start gap-2 hover:text-white cursor-pointer"
|
| 45 |
+
onClick={() => setAdvancedSettings(!advancedSettings)}
|
| 46 |
+
>
|
| 47 |
+
<HiAdjustmentsHorizontal className="w-5 h-5" />
|
| 48 |
+
Advanced settings
|
| 49 |
+
</p>
|
| 50 |
+
</div>
|
| 51 |
<div className="flex items-center justify-center lg:justify-end gap-5 w-full mt-6 lg:mt-0">
|
| 52 |
{categories.map(({ key, label, icon }) => (
|
| 53 |
<Button
|
|
|
|
| 61 |
))}
|
| 62 |
</div>
|
| 63 |
</div>
|
| 64 |
+
<Settings
|
| 65 |
+
open={advancedSettings}
|
| 66 |
+
style={style}
|
| 67 |
+
setStyle={setStyle}
|
| 68 |
+
list_styles={list_styles}
|
| 69 |
+
/>
|
| 70 |
</div>
|
| 71 |
<Collections />
|
| 72 |
</main>
|
components/main/settings/index.tsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import classNames from "classnames";
|
| 2 |
+
|
| 3 |
+
interface Props {
|
| 4 |
+
style: string;
|
| 5 |
+
open: boolean;
|
| 6 |
+
setStyle: (style: string) => void;
|
| 7 |
+
list_styles: { name: string; negative_prompt: string; prompt: string }[];
|
| 8 |
+
}
|
| 9 |
+
export const Settings: React.FC<Props> = ({
|
| 10 |
+
open,
|
| 11 |
+
style,
|
| 12 |
+
setStyle,
|
| 13 |
+
list_styles,
|
| 14 |
+
}) => {
|
| 15 |
+
return (
|
| 16 |
+
<div
|
| 17 |
+
className={classNames(
|
| 18 |
+
"lg:justify-start overflow-hidden transition-all duration-1000 w-full",
|
| 19 |
+
{
|
| 20 |
+
"max-h-[300px]": open,
|
| 21 |
+
"max-h-0": !open,
|
| 22 |
+
}
|
| 23 |
+
)}
|
| 24 |
+
>
|
| 25 |
+
<div className="gap-2 flex items-center justify-start mt-6 flex-wrap w-full">
|
| 26 |
+
{list_styles.map((stl) => (
|
| 27 |
+
<div
|
| 28 |
+
key={stl.name}
|
| 29 |
+
className={classNames(
|
| 30 |
+
"rounded-full border-2 border-white text-xs lg:text-sm px-4 py-2 font-semibold text-white cursor-pointer",
|
| 31 |
+
{
|
| 32 |
+
"bg-white !text-gray-900": stl.name === style,
|
| 33 |
+
}
|
| 34 |
+
)}
|
| 35 |
+
onClick={() => setStyle(stl.name)}
|
| 36 |
+
>
|
| 37 |
+
{stl.name}
|
| 38 |
+
</div>
|
| 39 |
+
))}
|
| 40 |
+
</div>
|
| 41 |
+
</div>
|
| 42 |
+
);
|
| 43 |
+
};
|