├── .env.example ├── .gitignore ├── .npmrc ├── .yarnrc.yml ├── LICENSE ├── README.md ├── app.vue ├── assets └── css │ └── main.css ├── components ├── Footer.vue ├── Header.vue ├── Image.vue ├── Outpainter.vue └── SelectFile.vue ├── config.js ├── nuxt.config.ts ├── package-lock.json ├── package.json ├── prettier.config.js ├── public ├── checkerboard.png ├── cover.jpeg ├── favicon.ico ├── favicon.svg ├── fox.png └── logomarks │ ├── github.svg │ ├── replicate.svg │ └── vercel.svg ├── server ├── api │ └── prediction.post.ts └── tsconfig.json ├── services ├── EventBus.js ├── WS.js └── index.js ├── stores └── app.js ├── tailwind.config.js └── tsconfig.json /.env.example: -------------------------------------------------------------------------------- 1 | REPLICATE_API_TOKEN= 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Nuxt dev/build outputs 2 | .output 3 | .nuxt 4 | .nitro 5 | .cache 6 | dist 7 | 8 | # Node dependencies 9 | node_modules 10 | .yarn 11 | 12 | # Logs 13 | logs 14 | *.log 15 | 16 | # Misc 17 | .DS_Store 18 | .fleet 19 | .idea 20 | 21 | # Local env files 22 | .env 23 | .env.* 24 | !.env.example 25 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | strict-peer-dependencies=false 3 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 Pontus Aurdal 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Outpainter 2 | 3 | Expand the contents of an image using generative fill. 4 | 5 | ## How it works 6 | 7 | This app is powered by: 8 | 9 | 🚀 [Replicate](https://replicate.com/?utm_source=project&utm_campaign=outpainter), a platform for running machine learning models in the cloud. 10 | 11 | 🖍️ [Stable Diffusion Outpainting](https://replicate.com/stability-ai/stable-diffusion-inpainting?utm_source=project&utm_campaign=outpainter), an open-source machine learning model that generates images from text. 12 | 13 | ▲ [Vercel](https://vercel.com/), a platform for running web apps. 14 | 15 | ⚡️ Nuxt.js [server-side API routes](server/api), for talking to Replicate's API. 16 | 17 | 👀 Nuxt.js Vue components, for the browser UI. 18 | 19 | 🍃 [Tailwind CSS](https://tailwindcss.com/), for styles. 20 | 21 | ## Development 22 | 23 | 1. Install a recent version of [Node.js](https://nodejs.org/) 24 | 1. Copy your [Replicate API token](https://replicate.com/account?utm_source=project&utm_campaign=outpainter) and set it in your environment: 25 | ``` 26 | echo "REPLICATE_API_TOKEN=" > .env.local 27 | ``` 28 | 1. Install dependencies and run the server: 29 | ``` 30 | npm install 31 | npm run dev 32 | ``` 33 | 1. Open [localhost:3000](http://localhost:3000) in your browser. That's it! 34 | -------------------------------------------------------------------------------- /app.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 28 | -------------------------------------------------------------------------------- /assets/css/main.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | :root { 6 | --popper-theme-background-color: #333333; 7 | --popper-theme-background-color-hover: #333333; 8 | --popper-theme-text-color: #ffffff; 9 | --popper-theme-border-width: 0px; 10 | --popper-theme-border-style: solid; 11 | --popper-theme-border-radius: 4px; 12 | --popper-theme-padding: 5px 10px; 13 | } 14 | 15 | #__nuxt { 16 | min-height: 100vh; 17 | font-family: -apple-system, system-ui, BlinkMacSystemFont, Helvetiva Neue, 18 | Helvetica, Arial, sans-serif; 19 | } 20 | -------------------------------------------------------------------------------- /components/Footer.vue: -------------------------------------------------------------------------------- 1 | 54 | 55 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /components/Header.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /components/Image.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 19 | 20 | 27 | -------------------------------------------------------------------------------- /components/Outpainter.vue: -------------------------------------------------------------------------------- 1 | 37 | 38 | 148 | 149 | 194 | -------------------------------------------------------------------------------- /components/SelectFile.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 175 | 176 | 181 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | export const IMG_DIMENSIONS = 512 2 | export const IMG_PADDING = 256 3 | export const MASK_OVERLAP = 5 4 | -------------------------------------------------------------------------------- /nuxt.config.ts: -------------------------------------------------------------------------------- 1 | // https://nuxt.com/docs/api/configuration/nuxt-config 2 | export default defineNuxtConfig({ 3 | ssr: false, 4 | devtools: { 5 | enabled: false 6 | }, 7 | runtimeConfig: { 8 | replicateApiToken: process.env.REPLICATE_API_TOKEN || '' 9 | }, 10 | nitro: { 11 | preset: 'vercel-edge' 12 | }, 13 | modules: ['@pinia/nuxt'], 14 | css: ['~/assets/css/main.css'], 15 | postcss: { 16 | plugins: { 17 | tailwindcss: {}, 18 | autoprefixer: {} 19 | } 20 | }, 21 | app: { 22 | head: { 23 | title: 'Outpainter', 24 | meta: [ 25 | { charset: 'utf-8' }, 26 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 27 | { 28 | name: 'description', 29 | content: 'Expand the contents of an image using generative fill.' 30 | }, 31 | { 32 | property: 'og:title', 33 | content: 'Outpainter' 34 | }, 35 | { 36 | property: 'og:description', 37 | content: 'Expand the contents of an image using generative fill.' 38 | }, 39 | { 40 | property: 'og:url', 41 | content: 'https://outpainter.app/' 42 | }, 43 | { 44 | property: 'og:image', 45 | content: 'https://outpainter.app/cover.jpeg' 46 | }, 47 | { 48 | property: 'twitter:image', 49 | content: 'https://outpainter.app/cover.jpeg' 50 | }, 51 | { 52 | property: 'twitter:card', 53 | content: 'summary_large_image' 54 | }, 55 | { 56 | property: 'twitter:title', 57 | content: 'Outpainter' 58 | }, 59 | { 60 | property: 'twitter:description', 61 | content: 'Expand the contents of an image using generative fill.' 62 | } 63 | ], 64 | link: [ 65 | { 66 | rel: 'icon', 67 | type: 'image/x-icon', 68 | href: '/favicon.ico', 69 | sizes: 'any' 70 | }, 71 | { 72 | rel: 'icon', 73 | type: 'image/svg+xml', 74 | href: '/favicon.svg' 75 | } 76 | ] 77 | } 78 | } 79 | }) 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "outpainter", 3 | "description": "Expand the contents of an image using generative fill.", 4 | "private": true, 5 | "scripts": { 6 | "build": "nuxt build", 7 | "dev": "nuxt dev", 8 | "generate": "nuxt generate", 9 | "preview": "nuxt preview", 10 | "postinstall": "nuxt prepare" 11 | }, 12 | "dependencies": { 13 | "@pinia/nuxt": "^0.4.11", 14 | "lodash": "^4.17.21", 15 | "pinia": "^2.1.3", 16 | "replicate": "^0.12.2", 17 | "replicate-webhook-proxy": "^0.0.2", 18 | "tiny-emitter": "^2.1.0", 19 | "uuid": "^9.0.0", 20 | "vue": "^3.3.4", 21 | "vue3-popper": "^1.5.0" 22 | }, 23 | "devDependencies": { 24 | "@nuxt/devtools": "latest", 25 | "@types/node": "^18", 26 | "autoprefixer": "^10.4.14", 27 | "nuxt": "^3.5.2", 28 | "postcss": "^8.4.24", 29 | "pug": "^3.0.2", 30 | "pug-plain-loader": "^1.1.0", 31 | "stylus": "^0.59.0", 32 | "stylus-loader": "^7.1.2", 33 | "tailwindcss": "^3.3.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | trailingComma: 'none', 3 | tabWidth: 2, 4 | semi: false, 5 | singleQuote: true, 6 | bracketSpacing: true 7 | } 8 | -------------------------------------------------------------------------------- /public/checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/outpainter/08d1157ac41a202c8d503ae8c70d9c5b376429a3/public/checkerboard.png -------------------------------------------------------------------------------- /public/cover.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/outpainter/08d1157ac41a202c8d503ae8c70d9c5b376429a3/public/cover.jpeg -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/outpainter/08d1157ac41a202c8d503ae8c70d9c5b376429a3/public/favicon.ico -------------------------------------------------------------------------------- /public/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /public/fox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/outpainter/08d1157ac41a202c8d503ae8c70d9c5b376429a3/public/fox.png -------------------------------------------------------------------------------- /public/logomarks/github.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/logomarks/replicate.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /public/logomarks/vercel.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /server/api/prediction.post.ts: -------------------------------------------------------------------------------- 1 | import Replicate from 'replicate' 2 | 3 | const replicate = new Replicate({ 4 | auth: useRuntimeConfig().replicateApiToken 5 | }) 6 | 7 | export default defineEventHandler(async (event) => { 8 | const body = await readBody(event) 9 | const { ws_key, input } = body 10 | 11 | // https://replicate.com/stability-ai/stable-diffusion-inpainting 12 | const prediction = await replicate.predictions.create({ 13 | version: 'c28b92a7ecd66eee4aefcd8a94eb9e7f6c3805d5f06038165407fb5cb355ba67', 14 | input, 15 | webhook: `https://r3swiuknhh.execute-api.eu-west-1.amazonaws.com/prod/webhook?key=${ws_key}`, 16 | webhook_events_filter: ['start', 'output', 'logs', 'completed'] 17 | }) 18 | 19 | return prediction 20 | }) 21 | -------------------------------------------------------------------------------- /server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../.nuxt/tsconfig.server.json" 3 | } 4 | -------------------------------------------------------------------------------- /services/EventBus.js: -------------------------------------------------------------------------------- 1 | import emitter from 'tiny-emitter/instance' 2 | 3 | export default { 4 | $on: (...args) => emitter.on(...args), 5 | $once: (...args) => emitter.once(...args), 6 | $off: (...args) => emitter.off(...args), 7 | $emit: (...args) => emitter.emit(...args) 8 | } 9 | -------------------------------------------------------------------------------- /services/WS.js: -------------------------------------------------------------------------------- 1 | import { get } from 'lodash' 2 | import rwp from 'replicate-webhook-proxy' 3 | 4 | import { EventBus } from '@/services' 5 | 6 | class WS { 7 | constructor() { 8 | this.client = null 9 | } 10 | 11 | init(key) { 12 | this.client = rwp(key) 13 | 14 | // Setup event listeners 15 | this.client.on('open', () => console.log('ws: open')) 16 | this.client.on('close', () => console.log('ws: close')) 17 | this.client.on('message', (event) => this.onmessage(event)) 18 | this.client.on('error', (event) => console.log('ws: error', event.message)) 19 | } 20 | 21 | deinit() { 22 | this.client.close() 23 | this.client = null 24 | } 25 | 26 | onmessage(event) { 27 | const { body } = event.data 28 | const output = get(body, 'output[0]', null) 29 | 30 | if (output) EventBus.$emit('prediction:output', output) 31 | } 32 | } 33 | 34 | export default new WS() 35 | -------------------------------------------------------------------------------- /services/index.js: -------------------------------------------------------------------------------- 1 | export { default as EventBus } from './EventBus' 2 | export { default as WS } from './WS' 3 | -------------------------------------------------------------------------------- /stores/app.js: -------------------------------------------------------------------------------- 1 | import { defineStore } from 'pinia' 2 | import { v4 as uuidv4 } from 'uuid' 3 | 4 | import { WS } from '@/services' 5 | 6 | export default defineStore('app', { 7 | state: () => ({ 8 | ws_key: null 9 | }), 10 | actions: { 11 | reset() { 12 | this.ws_key = null 13 | WS.deinit() 14 | }, 15 | async init() { 16 | try { 17 | const jobs = [] 18 | const deferredJobs = [] 19 | 20 | await Promise.allSettled(jobs) 21 | Promise.allSettled(deferredJobs) 22 | 23 | this.ws_key = uuidv4() 24 | WS.init(this.ws_key) 25 | } catch (e) { 26 | throw new Error(`Failed to init app (${e.message})`) 27 | } 28 | }, 29 | async createPrediction(body = null) { 30 | const res = await fetch('/api/prediction', { 31 | method: 'post', 32 | body: JSON.stringify({ 33 | ws_key: this.ws_key, 34 | ...body 35 | }) 36 | }) 37 | return await res.json() 38 | } 39 | } 40 | }) 41 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | './components/**/*.{js,vue,ts}', 5 | './layouts/**/*.vue', 6 | './pages/**/*.vue', 7 | './plugins/**/*.{js,ts}', 8 | './nuxt.config.{js,ts}', 9 | './app.vue' 10 | ], 11 | theme: { 12 | container: { 13 | screens: { 14 | DEFAULT: '100%', 15 | sm: '640px', 16 | md: '768px', 17 | lg: '1024px', 18 | xl: '1024px', 19 | '2xl': '1024px' 20 | } 21 | } 22 | }, 23 | plugins: [] 24 | } 25 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // https://nuxt.com/docs/guide/concepts/typescript 3 | "extends": "./.nuxt/tsconfig.json" 4 | } 5 | --------------------------------------------------------------------------------