Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyshv committed Oct 10, 2023
0 parents commit 5fbb80a
Show file tree
Hide file tree
Showing 47 changed files with 19,426 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "next/core-web-vitals",
"rules": {
"@next/next/no-img-element": "off"
}
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test

on:
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm test
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local
.env

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2022 Zeke Sikelianos

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 🖍️ Scribble Diffusion

Try it out at [scribblediffusion.com](https://scribblediffusion.com)

## How it works

This app is powered by:

🚀 [Replicate](https://replicate.com/?utm_source=project&utm_campaign=scribblediffusion), a platform for running machine learning models in the cloud.

🖍️ [ControlNet](https://replicate.com/rossjillian/controlnet?utm_source=project&utm_campaign=scribblediffusion), an open-source machine learning model that generates images from text and scribbles.

[Vercel](https://vercel.com/), a platform for running web apps.

⚡️ Next.js [server-side API routes](pages/api), for talking to the Replicate API.

👀 Next.js React components, for the browser UI.

🍃 [Tailwind CSS](https://tailwindcss.com/), for styles.

## Development

1. Install a recent version of [Node.js](https://nodejs.org/)
1. Copy your [Replicate API token](https://replicate.com/account?utm_source=project&utm_campaign=scribblediffusion) and set it in your environment:
```
echo "REPLICATE_API_TOKEN=<your-token-here>" > .env.local
```
1. Install dependencies and run the server:
```
npm install
npm run dev
```
1. Open [localhost:3000](http://localhost:3000) in your browser. That's it!
85 changes: 85 additions & 0 deletions components/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as React from "react";
import { useEffect } from "react";
import { ReactSketchCanvas } from "react-sketch-canvas";

import { Undo as UndoIcon, Trash as TrashIcon } from "lucide-react";

export default function Canvas({
startingPaths,
onScribble,
scribbleExists,
setScribbleExists,
}) {
const canvasRef = React.useRef(null);

useEffect(() => {
// Hack to work around Firfox bug in react-sketch-canvas
// https://github.com/vinothpandian/react-sketch-canvas/issues/54
document
.querySelector("#react-sketch-canvas__stroke-group-0")
?.removeAttribute("mask");

loadStartingPaths();
}, []);

async function loadStartingPaths() {
await canvasRef.current.loadPaths(startingPaths);
setScribbleExists(true);
onChange();
}

const onChange = async () => {
const paths = await canvasRef.current.exportPaths();
localStorage.setItem("paths", JSON.stringify(paths, null, 2));

if (!paths.length) return;

setScribbleExists(true);

const data = await canvasRef.current.exportImage("png");
onScribble(data);
};

const undo = () => {
canvasRef.current.undo();
};

const reset = () => {
setScribbleExists(false);
canvasRef.current.resetCanvas();
};

return (
<div className="relative">
{scribbleExists || (
<div>
<div className="absolute grid w-full h-full p-3 place-items-center pointer-events-none text-xl">
<span className="opacity-40">Draw something here.</span>
</div>
</div>
)}

<ReactSketchCanvas
ref={canvasRef}
className="w-full aspect-square border-none cursor-crosshair"
strokeWidth={4}
strokeColor="black"
onChange={onChange}
withTimestamp={true}
/>

{scribbleExists && (
<div className="animate-in fade-in duration-700 text-left">
<button className="lil-button" onClick={undo}>
<UndoIcon className="icon" />
Undo
</button>
<button className="lil-button" onClick={reset}>
<TrashIcon className="icon" />
Clear
</button>
</div>
)}
</div>
);
}
9 changes: 9 additions & 0 deletions components/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function Footer({ error }) {
if (!error) return null;

return (
<div className="mx-auto w-full">
{error && <p className="bold text-red-500 pb-5">{error}</p>}
</div>
);
}
96 changes: 96 additions & 0 deletions components/footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import Link from "next/link";
import Image from "next/image";
// import "react-tooltip/dist/react-tooltip.css";

const linkStyles =
"inline-block relative w-12 h-12 mx-2 opacity-40 hover:opacity-100 transition-all duration-200";
const imageStyles =
"p-3 hover:p-1 transition-all duration-200 hover:saturate-100";

export default function Footer() {
return (
<footer className="mt-20">
<div className="">
<p className="text-center">
Scribble Diffusion is an open-source project from{" "}
<Link
className="underline"
href="https://replicate.com?utm_source=project&utm_campaign=scribblediffusion"
target="_blank"
>
Replicate
</Link>
.
</p>

<nav className="text-center mt-16">
<Link
className={linkStyles}
href="https://replicate.com?utm_source=project&utm_campaign=scribblediffusion"
>
<Image
src="/logomarks/replicate.svg"
alt="Replicate"
data-tooltip-id="replicate-tooltip"
data-tooltip-content="Built by Replicate"
className={imageStyles}
fill={true}
unoptimized={true}
/>
</Link>
<Link
className={linkStyles}
href="https://www.bytescale.com/?utm_source=project&utm_campaign=scribblediffusion"
>
<Image
src="/logomarks/bytescale.svg"
data-tooltip-id="bytescale-tooltip"
data-tooltip-content="File storage from Bytescale"
alt="File storage from Bytescale"
className={imageStyles}
fill={true}
unoptimized={true}
/>
</Link>
<Link className={linkStyles} href="https://vercel.com/templates/ai">
<Image
src="/logomarks/vercel.svg"
data-tooltip-id="vercel-tooltip"
data-tooltip-content="Hosted on Vercel"
alt="Vercel"
className={imageStyles}
fill={true}
unoptimized={true}
/>
</Link>

<Link className={linkStyles} href="https://youtu.be/6z07OdbrWOs">
<Image
src="/logomarks/youtube.svg"
data-tooltip-id="youtube-tooltip"
data-tooltip-content="See how it was made"
alt="See how it was made"
className={imageStyles}
fill={true}
unoptimized={true}
/>
</Link>
<Link
className={linkStyles}
href="https://github.com/replicate/scribble-diffusion"
>
<Image
src="/logomarks/github.svg"
data-tooltip-id="github-tooltip"
data-tooltip-content="Fork it on GitHub"
alt="Fork it on GitHub"
className={imageStyles}
fill={true}
unoptimized={true}
/>
</Link>
</nav>
</div>
</footer>
);
}
9 changes: 9 additions & 0 deletions components/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import PulseLoader from "react-spinners/PulseLoader";

export default function Loader() {
return (
<div>
<PulseLoader size={12} margin={4} className="opacity-40" />
</div>
);
}
Loading

0 comments on commit 5fbb80a

Please sign in to comment.