diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..bffb357 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "next/core-web-vitals" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd3dbb5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js +.yarn/install-state.gz + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..ae8e0d4 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "all", + "printWidth": 120, + "tabWidth": 2, + "useTabs": true +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..c403366 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +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). + +## Getting Started + +First, run the development server: + +```bash +npm run dev +# or +yarn dev +# or +pnpm dev +# or +bun dev +``` + +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + +You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. + +This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. + +## Learn More + +To learn more about Next.js, take a look at the following resources: + +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. +- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. + +You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! + +## Deploy on Vercel + +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. + +Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/app/api/generate-code-from-image/route.ts b/app/api/generate-code-from-image/route.ts new file mode 100644 index 0000000..3f894d7 --- /dev/null +++ b/app/api/generate-code-from-image/route.ts @@ -0,0 +1,66 @@ +// ./app/api/chat/route.js +import OpenAI from 'openai' +import { OpenAIStream, StreamingTextResponse } from 'ai' + +const USER_PROMPT = 'Generate code a web page that looks exactly like this' + +const SYSTEM_PROMPT= `You are an expert Tailwind developer +You take screenshots of a reference web page from the user, and then build single page apps +using Tailwind, HTML and JS. +You might also be given a screenshot(The second image) of a web page that you have already built, and asked to +update it to look more like the reference image(The first image). + +- Make sure the app looks exactly like the screenshot. +- Pay close attention to background color, text color, font size, font family, +padding, margin, border, etc. Match the colors and sizes exactly. +- Use the exact text from the screenshot. +- Do not add comments in the code such as "" and "" in place of writing the full code. WRITE THE FULL CODE. +- Repeat elements as needed to match the screenshot. For example, if there are 15 items, the code should have 15 items. DO NOT LEAVE comments like "" or bad things will happen. +- For images, use placeholder images from https://placehold.co and include a detailed description of the image in the alt text so that an image generation AI can generate the image later. + +In terms of libraries, + +- Use this script to include Tailwind: +- You can use Google Fonts +- Font Awesome for icons: + +Return only the full code in tags. +Do not include markdown "\`\`\`" or "\`\`\`html" at the start or end.` + + +const openai = new OpenAI({ + apiKey: process.env.OPENAI_API_KEY, +}) + +export const runtime = 'edge' //vs cloud. Edge is faster but more expensive + +export async function POST(req: Request) { + const { url } = await req.json() + const response = await openai.chat.completions.create({ + model: 'gpt-4-vision-preview', + stream: true, + max_tokens: 4096, + messages: [ + { + role: 'system', + content: SYSTEM_PROMPT, + }, + { + role: 'user', + content: [ + { + type: 'text', + text: USER_PROMPT, + }, + { + type: 'image_url', + image_url: url + }, + ], + } + ], + }); + + const stream = OpenAIStream(response) + return new StreamingTextResponse(stream) +} diff --git a/app/favicon.ico b/app/favicon.ico new file mode 100644 index 0000000..718d6fe Binary files /dev/null and b/app/favicon.ico differ diff --git a/app/form.tsx b/app/form.tsx new file mode 100644 index 0000000..6276d69 --- /dev/null +++ b/app/form.tsx @@ -0,0 +1,28 @@ +'use client' + +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { Label } from '@/components/ui/label' +import { FormEvent } from 'react' + +export const Form = ({transformUrlToCode} : {transformUrlToCode: (url: string) => void}) =>{ + + const handleSubmit = (evt: FormEvent) => { + const form = evt.currentTarget as HTMLFormElement; + const url = form.elements.namedItem('url') as HTMLInputElement; + transformUrlToCode(url.value); + } + + return ( +
{ + evt.preventDefault() + handleSubmit(evt) + }} + > +