Skip to content

Commit 778c726

Browse files
committed
init
0 parents  commit 778c726

23 files changed

+5555
-0
lines changed

.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

app/favicon.ico

25.3 KB
Binary file not shown.

app/globals.css

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
@layer base {
6+
:root {
7+
--background: 0 0% 100%;
8+
--foreground: 222.2 84% 4.9%;
9+
10+
--card: 0 0% 100%;
11+
--card-foreground: 222.2 84% 4.9%;
12+
13+
--popover: 0 0% 100%;
14+
--popover-foreground: 222.2 84% 4.9%;
15+
16+
--primary: 222.2 47.4% 11.2%;
17+
--primary-foreground: 210 40% 98%;
18+
19+
--secondary: 210 40% 96.1%;
20+
--secondary-foreground: 222.2 47.4% 11.2%;
21+
22+
--muted: 210 40% 96.1%;
23+
--muted-foreground: 215.4 16.3% 46.9%;
24+
25+
--accent: 210 40% 96.1%;
26+
--accent-foreground: 222.2 47.4% 11.2%;
27+
28+
--destructive: 0 84.2% 60.2%;
29+
--destructive-foreground: 210 40% 98%;
30+
31+
--border: 214.3 31.8% 91.4%;
32+
--input: 214.3 31.8% 91.4%;
33+
--ring: 222.2 84% 4.9%;
34+
35+
--radius: 0.5rem;
36+
}
37+
38+
.dark {
39+
--background: 222.2 84% 4.9%;
40+
--foreground: 210 40% 98%;
41+
42+
--card: 222.2 84% 4.9%;
43+
--card-foreground: 210 40% 98%;
44+
45+
--popover: 222.2 84% 4.9%;
46+
--popover-foreground: 210 40% 98%;
47+
48+
--primary: 210 40% 98%;
49+
--primary-foreground: 222.2 47.4% 11.2%;
50+
51+
--secondary: 217.2 32.6% 17.5%;
52+
--secondary-foreground: 210 40% 98%;
53+
54+
--muted: 217.2 32.6% 17.5%;
55+
--muted-foreground: 215 20.2% 65.1%;
56+
57+
--accent: 217.2 32.6% 17.5%;
58+
--accent-foreground: 210 40% 98%;
59+
60+
--destructive: 0 62.8% 30.6%;
61+
--destructive-foreground: 210 40% 98%;
62+
63+
--border: 217.2 32.6% 17.5%;
64+
--input: 217.2 32.6% 17.5%;
65+
--ring: 212.7 26.8% 83.9%;
66+
}
67+
}
68+
69+
@layer base {
70+
* {
71+
@apply border-border;
72+
}
73+
body {
74+
@apply bg-background text-foreground;
75+
}
76+
}

app/layout.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Metadata } from "next";
2+
import { Inter } from "next/font/google";
3+
import "./globals.css";
4+
5+
const inter = Inter({ subsets: ["latin"] });
6+
7+
export const metadata: Metadata = {
8+
title: "Create Next App",
9+
description: "Generated by create next app",
10+
};
11+
12+
export default function RootLayout({
13+
children,
14+
}: Readonly<{
15+
children: React.ReactNode;
16+
}>) {
17+
return (
18+
<html lang="en">
19+
<body className={inter.className}>{children}</body>
20+
</html>
21+
);
22+
}

app/page.tsx

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"use client";
2+
3+
import { EnterGuess } from "@/components/enter-guess";
4+
import { GeneratingScore } from "@/components/generating-score";
5+
import { YourScore } from "@/components/your-score";
6+
import { useEffect, useState } from "react";
7+
8+
export type OrginalGuess = {
9+
imageUrl: string;
10+
hints: string[];
11+
prompt: string;
12+
};
13+
14+
export type GuessScore = {
15+
generatedImage: string;
16+
score: number;
17+
};
18+
19+
export default function Home() {
20+
const [userPrompt, setUserPrompt] = useState("");
21+
const [originalGuess, setOriginalGuess] = useState<OrginalGuess>();
22+
const [guessScore, setGuessScore] = useState<GuessScore>();
23+
const [generating, setGenerating] = useState(false);
24+
25+
const handleSubmit = async (prompt: string) => {
26+
setGenerating(true);
27+
setUserPrompt(prompt);
28+
const response = await fetch(
29+
process.env.NEXT_PUBLIC_GET_SCORE_WORKFLOW as string,
30+
{
31+
method: "POST",
32+
body: JSON.stringify({
33+
guessedPrompt: prompt,
34+
originalPrompt: originalGuess?.prompt,
35+
}),
36+
headers: {
37+
Accept: "application/json",
38+
"Content-Type": "application/json",
39+
},
40+
}
41+
);
42+
const data = await response.json();
43+
setGuessScore(data);
44+
setGenerating(false);
45+
};
46+
47+
const fetchData = async () => {
48+
try {
49+
const response = await fetch(
50+
process.env.NEXT_PUBLIC_GET_RANDOM_PROMPT_WORKFLOW as string
51+
);
52+
const data = await response.json();
53+
console.log(data);
54+
setOriginalGuess(data);
55+
} catch (error) {
56+
console.error("Failed to fetch data:", error);
57+
}
58+
};
59+
60+
const reset = () => {
61+
setUserPrompt("");
62+
setOriginalGuess(undefined);
63+
setGuessScore(undefined);
64+
fetchData();
65+
};
66+
67+
useEffect(() => {
68+
fetchData();
69+
}, []);
70+
71+
if (generating)
72+
return <GeneratingScore originalImage={originalGuess!.imageUrl} />;
73+
74+
if (guessScore)
75+
return (
76+
<YourScore
77+
score={guessScore!}
78+
originalGuess={originalGuess!}
79+
userPrompt={userPrompt}
80+
reset={reset}
81+
/>
82+
);
83+
84+
return <EnterGuess onSubmit={handleSubmit} originalGuess={originalGuess} />;
85+
}

components.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "default",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.ts",
8+
"css": "app/globals.css",
9+
"baseColor": "slate",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils"
16+
}
17+
}

components/enter-guess.tsx

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* This code was generated by v0 by Vercel.
3+
* @see https://v0.dev/t/Vz30LKzXEsL
4+
*/
5+
import { Textarea } from "@/components/ui/textarea";
6+
import { Button } from "@/components/ui/button";
7+
import { OrginalGuess } from "@/app/page";
8+
import { useState } from "react";
9+
import { ReloadIcon } from "@radix-ui/react-icons";
10+
11+
type Props = {
12+
onSubmit: (text: string) => void;
13+
originalGuess?: OrginalGuess;
14+
};
15+
16+
export function EnterGuess({ onSubmit, originalGuess }: Props) {
17+
const [inputValue, setInputValue] = useState("");
18+
19+
const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
20+
setInputValue(event.target.value);
21+
};
22+
23+
const handleSubmit = () => {
24+
onSubmit(inputValue);
25+
};
26+
return (
27+
<div className="flex h-screen w-full items-center justify-center bg-white p-8">
28+
<div className="flex max-w-4xl flex-wrap items-center justify-center gap-8">
29+
<div className="flex w-full justify-center">
30+
<h1 className="text-3xl font-bold">Guess the prompt</h1>
31+
</div>
32+
<div className="grid grid-cols-2 gap-8 w-full">
33+
<div className="relative">
34+
{!originalGuess?.imageUrl && (
35+
<ReloadIcon
36+
className="absolute z-10 h-8 w-8 animate-spin text-slate-800"
37+
style={{
38+
top: "50%",
39+
left: "50%",
40+
}}
41+
/>
42+
)}
43+
<img
44+
className="h-[400px] w-[600px] object-cover"
45+
height="400"
46+
src={originalGuess?.imageUrl || "/placeholder.svg"}
47+
style={{
48+
aspectRatio: "600/400",
49+
objectFit: "cover",
50+
}}
51+
width="600"
52+
/>
53+
</div>
54+
<div className="flex flex-col items-start space-y-4">
55+
<p className="text-sm">
56+
Can you guess the prompt used to generate this image?
57+
</p>
58+
<Textarea
59+
className="h-24 w-full resize-none rounded-md border p-2"
60+
placeholder="Guess the prompt used to generate the image"
61+
value={inputValue}
62+
onChange={handleInputChange}
63+
/>
64+
{originalGuess?.hints && (
65+
<p className="text-sm">Hints: {originalGuess?.hints.join()}</p>
66+
)}
67+
<Button
68+
className="mt-2 w-full"
69+
onClick={handleSubmit}
70+
disabled={!originalGuess}
71+
>
72+
Submit
73+
</Button>
74+
</div>
75+
</div>
76+
</div>
77+
</div>
78+
);
79+
}

0 commit comments

Comments
 (0)