initial commit
This commit is contained in:
parent
c058df0041
commit
2567e4a368
18 changed files with 20435 additions and 0 deletions
27
ai_image_generator/.gitignore
vendored
Normal file
27
ai_image_generator/.gitignore
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/client/node_modules
|
||||
/client/.env
|
||||
/server/.env
|
||||
/server/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
70
ai_image_generator/README.md
Normal file
70
ai_image_generator/README.md
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||
|
||||
The page will reload when you make changes.\
|
||||
You may also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||
|
||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||
|
||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
18516
ai_image_generator/client/package-lock.json
generated
Normal file
18516
ai_image_generator/client/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
46
ai_image_generator/client/package.json
Normal file
46
ai_image_generator/client/package.json
Normal file
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"name": "client",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"axios": "^1.6.8",
|
||||
"file-saver": "^2.0.5",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-icons": "^5.2.0",
|
||||
"react-lazy-load-image-component": "^1.6.0",
|
||||
"react-router-dom": "^6.23.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"tailwindcss": "^3.4.3"
|
||||
}
|
||||
}
|
14
ai_image_generator/client/public/index.html
Normal file
14
ai_image_generator/client/public/index.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="description" content="Web site created using create-react-app"/>
|
||||
<title>AI Image Generator</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
20
ai_image_generator/client/src/App.js
Normal file
20
ai_image_generator/client/src/App.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import React from 'react'
|
||||
import Home from './pages/Home'
|
||||
import GenerateImg from './pages/GenerateImg'
|
||||
import {BrowserRouter, Route, Routes} from 'react-router-dom'
|
||||
import Navbar from './components/Navbar'
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Navbar/>
|
||||
<Routes>
|
||||
<Route exact path='/' element={<Home/>}/>
|
||||
<Route exact path='/generate' element={<GenerateImg/>}/>
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
29
ai_image_generator/client/src/components/Card.jsx
Normal file
29
ai_image_generator/client/src/components/Card.jsx
Normal file
|
@ -0,0 +1,29 @@
|
|||
import React from 'react'
|
||||
import { LazyLoadImage } from 'react-lazy-load-image-component';
|
||||
import { BiDownload } from "react-icons/bi";
|
||||
import FileSaver from "file-saver"
|
||||
|
||||
|
||||
|
||||
const Card = ({item}) => {
|
||||
|
||||
return (
|
||||
<div className='flex relative [&:nth-child(5n+1)]:col-span-2'>
|
||||
<LazyLoadImage
|
||||
src={item?.photo}
|
||||
alt={item?.prompt}
|
||||
width='100%'
|
||||
height='100%'
|
||||
/>
|
||||
<div className='flex flex-col justify-end absolute p-2 md:p-5 top-0 left-0 right-0 bottom-0 items-start gap-1 backdrop-blur-sm opacity-0 hover:opacity-100 duration-300'>
|
||||
<p className='flex gap-5'>{item?.prompt}</p>
|
||||
<div className='w-full flex justify-between items-center'>
|
||||
<p className='flex items-center justify-center gap-1'><span className='w-6 h-6 flex bg-gray-100 text-black rounded-full items-center justify-center'>{item?.author[0]}</span>{item.author}</p>
|
||||
<button onClick={() => FileSaver.saveAs(item?.photo, 'download.jpg')} className='md:text-2xl'><BiDownload/></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Card
|
30
ai_image_generator/client/src/components/GenerateForm.jsx
Normal file
30
ai_image_generator/client/src/components/GenerateForm.jsx
Normal file
|
@ -0,0 +1,30 @@
|
|||
import React from 'react'
|
||||
|
||||
const GenerateForm = ({post, setPost, postLoading, setPostLoading, imgLoading, setImgLoading}) => {
|
||||
const generateImageFunction = () => {
|
||||
setImgLoading(true)
|
||||
}
|
||||
const creatPostFunction = () => {
|
||||
setPostLoading(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='flex-1 flex flex-col gap-5 p-2 justify-center border rounded-md'>
|
||||
<div className='flex flex-col gap-1'>
|
||||
<p className='text-lg text-green-400 font-semibold'>Generate an image with your prompt</p>
|
||||
</div>
|
||||
<div className='flex flex-col gap-5 text-sm text-gray-200'>
|
||||
<p className='-mb-4 uppercase text-xs'>Author</p>
|
||||
<input placeholder='Enter your name' value={post.name} onChange={(e) => setPost({...post, name: e.target.value})} className='bg-transparent border rounded-sm p-2 outline-none'/>
|
||||
<p className='-mb-4 uppercase text-xs'>Prompt</p>
|
||||
<textarea placeholder='Enter your prompt' value={post.prompt} onChange={(e) => setPost({...post, prompt: e.target.value})} className='min-h-[100px] bg-transparent border rounded-sm p-2 outline-none resize-none'/>
|
||||
</div>
|
||||
<div className='flex-1 flex gap-2 mt-5'>
|
||||
<button onClick={() => generateImageFunction()} onLoad={() => imgLoading(true)} disabled={post.prompt === ""} className='w-full flex items-center justify-center rounded-md p-1 bg-[#FFC100] disabled:bg-opacity-70'>Generate</button>
|
||||
<button onClick={() => creatPostFunction()} onLoad={() => postLoading(true)} disabled={post.name === "" || post.prompt === "" || post.photo === ""} className='w-full flex items-center justify-center rounded-md p-1 bg-[#FF8A08] disabled:bg-opacity-70'>Post</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default GenerateForm
|
19
ai_image_generator/client/src/components/GenerateImgForm.jsx
Normal file
19
ai_image_generator/client/src/components/GenerateImgForm.jsx
Normal file
|
@ -0,0 +1,19 @@
|
|||
import React from 'react'
|
||||
|
||||
const GenerateImgForm = ({src, loading}) => {
|
||||
return (
|
||||
<div className='flex-1 flex p-2 border rounded-md items-center justify-center min-h-[300px]'>
|
||||
{
|
||||
loading ? <>Generating your image...</> : (
|
||||
<>
|
||||
{
|
||||
src ? <img src={src} alt='' className='w-full h-full object-cover'/> : <> Write your prompt </>
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default GenerateImgForm
|
0
ai_image_generator/client/src/components/Image.jsx
Normal file
0
ai_image_generator/client/src/components/Image.jsx
Normal file
31
ai_image_generator/client/src/components/Navbar.jsx
Normal file
31
ai_image_generator/client/src/components/Navbar.jsx
Normal file
|
@ -0,0 +1,31 @@
|
|||
import React from 'react'
|
||||
import {useNavigate, useLocation, Link} from 'react-router-dom'
|
||||
|
||||
const Navbar = () => {
|
||||
const router = useNavigate();
|
||||
const location = useLocation();
|
||||
const path = location.pathname.split('/')
|
||||
|
||||
|
||||
return (
|
||||
<div className='flex justify-between items-center p-5 sm:p-10'>
|
||||
<Link to='/' className='flex gap-1 items-center'>
|
||||
<p className='text-2xl sm:text-4xl text-[#C400FF] font-semibold'>DALL-E</p>
|
||||
<div className='font-bold text-[10px] sm:text-xs uppercase text-[#0CECDD]'>
|
||||
<p className='-mb-1 sm:mb-0'>Image</p>
|
||||
<p>Generator</p>
|
||||
</div>
|
||||
</Link>
|
||||
{
|
||||
path[1] === 'generate' ? (
|
||||
<button onClick={() => router('/')} className='p-2 border border-[#9F70FD] rounded-md text-[#E59BE9] font-semibold hover:bg-[#FFB5DA] hover:border-[#FFB5DA] hover:text-[#6420AA] duration-300 text-sm sm:text-base'>Expolre Images</button>
|
||||
) : (
|
||||
<button onClick={() => router('/generate')} className='p-2 border border-[#82CD47] rounded-md text-[#F0FF42] font-semibold hover:bg-[#BFEA7C] hover:border-[#BFEA7C] hover:text-[#416D19] duration-300 text-sm sm:text-base'>Generate</button>
|
||||
)
|
||||
}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Navbar
|
8
ai_image_generator/client/src/index.css
Normal file
8
ai_image_generator/client/src/index.css
Normal file
|
@ -0,0 +1,8 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
html{
|
||||
background-color: black;
|
||||
color: white;
|
||||
}
|
12
ai_image_generator/client/src/index.js
Normal file
12
ai_image_generator/client/src/index.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
21
ai_image_generator/client/src/pages/GenerateImg.jsx
Normal file
21
ai_image_generator/client/src/pages/GenerateImg.jsx
Normal file
|
@ -0,0 +1,21 @@
|
|||
import React, { useState } from 'react'
|
||||
import GenerateForm from '../components/GenerateForm'
|
||||
import GenerateImgForm from '../components/GenerateImgForm'
|
||||
|
||||
const GenerateImg = () => {
|
||||
const [imgLoading, setImgLoading] = useState(false)
|
||||
const [postLoading, setPostLoading] = useState(false)
|
||||
const [post, setPost] = useState({name: "", prompt: "", photo: "",})
|
||||
|
||||
return (
|
||||
<div className='h-full overflow-y-scroll p-5 flex flex-col gap-5 items-center justify-center'>
|
||||
<p className='flex px-2 text-2xl text-[#F6F1E9] text-center'>Generate an image using AI by describing what you want to see!</p>
|
||||
<div className='max-w-[1500px] w-full h-fit flex justify-center gap-5 py-10 max-[640px]:flex-col max-[640px]:gap-5'>
|
||||
<GenerateForm post={post} setPost={setPost} postLoading={postLoading} setPostLoading={setPostLoading} imgLoading={imgLoading} setImgLoading={setImgLoading}/>
|
||||
<GenerateImgForm loading={imgLoading} src={post?.photo}/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default GenerateImg
|
35
ai_image_generator/client/src/pages/Home.jsx
Normal file
35
ai_image_generator/client/src/pages/Home.jsx
Normal file
|
@ -0,0 +1,35 @@
|
|||
import React from 'react'
|
||||
import { IoSearchOutline } from "react-icons/io5";
|
||||
import Card from '../components/Card';
|
||||
|
||||
const Home = () => {
|
||||
const item = {
|
||||
photo: "https://images.unsplash.com/photo-1714547808442-e4199a7f8e09?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
|
||||
author: "Jtp",
|
||||
prompt: "This is prompt",
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className='h-full overflow-y-scroll p-5 flex flex-col gap-5 items-center'>
|
||||
<p className='flex px-2 text-2xl text-[#F6F1E9] text-center'>Explore our popular images using AI generator</p>
|
||||
{/*=== Search ===*/}
|
||||
<div className='w-[100%] sm:w-[50%] flex border rounded-sm overflow-hidden'>
|
||||
<input type="text" placeholder='What do you want to see?' className='w-[95%] border-none p-2 outline-none bg-black'/>
|
||||
<button className='w-[5%] flex justify-center items-center duration-300 font-semibold'><IoSearchOutline/></button>
|
||||
</div>
|
||||
<div className='max-w-[1500px] w-full flex justify-center py-5'>
|
||||
<div className='grid gap-2 grid-cols-4 max-[999px]:grid-cols-3 max-[640px]:grid-cols-2'>
|
||||
<Card item={item}/>
|
||||
<Card item={item}/>
|
||||
<Card item={item}/>
|
||||
<Card item={item}/>
|
||||
<Card item={item}/>
|
||||
<Card item={item}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Home
|
11
ai_image_generator/client/tailwind.config.js
Normal file
11
ai_image_generator/client/tailwind.config.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
"./src/**/*.{js,jsx,ts,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
1528
ai_image_generator/server/package-lock.json
generated
Normal file
1528
ai_image_generator/server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
18
ai_image_generator/server/package.json
Normal file
18
ai_image_generator/server/package.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"cloudinary": "^2.2.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.19.2",
|
||||
"mongoose": "^8.3.3",
|
||||
"nodemon": "^3.1.0",
|
||||
"openai": "^4.40.0"
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue