├── .gitattributes ├── .github └── workflows │ └── train.yaml ├── LICENSE ├── README.md └── data ├── README.md ├── puppy-01.jpeg ├── puppy-02.jpeg ├── puppy-03.jpeg ├── puppy-04.jpeg └── puppy-05.jpeg /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/train.yaml: -------------------------------------------------------------------------------- 1 | name: Train a model 2 | 3 | # This workflow is triggered manually from the GitHub website. 4 | # To run it, click the "Actions" tab on the repo page. 5 | on: 6 | workflow_dispatch: 7 | inputs: 8 | model-name: 9 | required: true 10 | description: The name of the Replicate model to publish, in the format `your-replicate-username/desired-model-name`. If the model doesn't already exist, it will be created automatically. 11 | prompt-identifier: 12 | required: true 13 | description: A short string representing your custom trained style or concept. This should be an uncommon string of letters like `zxz`, rather than a common word or name like `sarah` of `dog`. You'll use this string in prompts when running the model like "a pencil sketch of zxz sitting in a meadow". 14 | default: zxz 15 | max-train-steps: 16 | required: true 17 | description: Total number of training steps to perform. Higher numbers produce more accurate results, but take longer to run. Set this to something low like 100 to test that your workflow is working, then run again at a higher number like 2000 to train more accurately. 18 | type: number 19 | default: 2000 20 | 21 | # Find your Replicate API token at https://replicate.com/account 22 | env: 23 | replicate-api-token: ${{ secrets.REPLICATE_API_TOKEN }} 24 | 25 | jobs: 26 | train: 27 | runs-on: ubuntu-latest 28 | steps: 29 | 30 | - name: Check secrets 31 | if: ${{ env.replicate-api-token == '' }} 32 | run: | 33 | echo "🙈 Uh oh! Missing repository secret: REPLICATE_API_TOKEN" 34 | echo "Go to https://replicate.com/account to copy your API token," 35 | echo "then visit https://github.com/${{ github.repository }}/settings/secrets/actions/new to set it." 36 | echo 37 | echo 38 | echo 39 | exit 1 40 | 41 | - name: Checkout code 42 | uses: actions/checkout@v3 43 | 44 | - name: Zip training data 45 | run: | 46 | zip -r data.zip data 47 | 48 | - name: Upload training data 49 | id: upload-training-data 50 | run: | 51 | RESPONSE=$(curl -s -X POST -H "Authorization: Token ${{ secrets.REPLICATE_API_TOKEN }}" https://dreambooth-api-experimental.replicate.com/v1/upload/data.zip) 52 | curl -X PUT -H "Content-Type: application/zip" --upload-file data.zip "$(jq -r ".upload_url" <<< "$RESPONSE")" 53 | echo "INSTANCE_DATA_URL=$(jq -r '.serving_url' <<< $RESPONSE)" 54 | echo "INSTANCE_DATA_URL=$(jq -r '.serving_url' <<< $RESPONSE)" >> $GITHUB_OUTPUT 55 | 56 | - name: Start training 57 | run: | 58 | curl -s -X POST \ 59 | -H "Authorization: Token ${{ secrets.REPLICATE_API_TOKEN }}" \ 60 | -H "Content-Type: application/json" \ 61 | -d '{ 62 | "input": { 63 | "instance_prompt": "a photo of a ${{ inputs.prompt-identifier }} person", 64 | "class_prompt": "a photo of a person", 65 | "instance_data": "${{ steps.upload-training-data.outputs.INSTANCE_DATA_URL }}", 66 | "max_train_steps": ${{ inputs.max-train-steps }} 67 | }, 68 | "model": "${{ inputs.model-name }}", 69 | "trainer_version": "cd3f925f7ab21afaef7d45224790eedbb837eeac40d22e8fefe015489ab644aa" 70 | }' \ 71 | https://dreambooth-api-experimental.replicate.com/v1/trainings 72 | 73 | - name: Link to model 74 | run: | 75 | echo "🚂 Your model is now training!" 76 | echo "This takes about 10-30 minutes, depending on how many training steps you're running." 77 | echo "To see your model, visit https://replicate.com/${{ inputs.model-name }} and refresh until you see the prediction form." 78 | echo "For more info on how to run your new model, see https://replicate.com/blog/dreambooth-api" 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Zeke Sikelianos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DreamBooth Action 2 | 3 | This is a template repo for **training and publishing your own custom [DreamBooth](https://replicate.com/blog/dreambooth-api) model** using Replicate and GitHub Actions. 4 | 5 | ## Preqrequisites 6 | 7 | - A paid [Replicate](https://replicate.com/account) account 8 | - A handful of training images 9 | 10 | ## Training the model 11 | 12 | 🍿 Like to learn by watching? Check out the [video tutorial on YouTube](https://www.youtube.com/watch?v=jknKfY13LbY) 13 | 14 | 1. 🐣 Create your own copy of this repository by clicking the green "Use this template" button, then "Create a new repository". Name your new repository whatever you like, and choose whether you want to make it public or private. 15 | 1. 🐕 Remove the cute puppy images in the [data](data) directory and replace them with your own images. 16 | 1. 💾 Commit your changes to git and push to your main branch on GitHub. 17 | 1. 🕵️‍♀️ Copy your Replicate API token from [replicate.com/account](https://replicate.com/account) and [create a repository secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) named `REPLICATE_API_TOKEN`. 18 | 1. 🎬 Trigger the workflow from your GitHub repo page: "Actions" > "Train a model" > "Run workflow". 19 | 1. Go to the [replicate.com](https://replicate.com) homepage. At the top of your list of predictions, you'll see a replicate/dreambooth prediction in progress. This the request to train your model. Click that prediction to see the progress of the training process. 20 | 1. ☕️ Grab a coffee or a snack and watch the logs roll by! The training process takes a few minutes to run. 21 | 22 | ## Running the model 23 | 24 | Depending on the number of training steps you specified when running the workflow, the training process can take 10-40 minutes to run. 25 | 26 | When the training process has completed successfully, it pushes the model to Replicate. You can run it like any other Replicate model, using the website or the API. 27 | 28 | To run on the website, go to [your dashboard](https://replicate.com) then click on "Models". 29 | 30 | Your new model will be private by default, and only visible to you. If you want anyone to be able to see and run your model, you can make it public in the Settings tab on your model page. 31 | 32 | To run the model on the web, enter a prompt using the identifier you specified during training, e.g. `a pencil sketch of zxz`. 33 | 34 | To run the model from your own code, click the API tab on your model page for instructions on running with Python, cURL, etc. 35 | 36 | To learn more about running models on Replicate, take a look at the [Python getting started guide](https://replicate.com/docs/get-started/python) or the [HTTP API reference](https://replicate.com/docs/reference/http). 37 | 38 | If you have questions, open an issue on this repo or find us in [Discord](https://discord.gg/replicate). -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | # Data 2 | 3 | The images in this directory are the training data for your model. 4 | 5 | 🐕 Remove the cute puppy images and replace them with your own images. 6 | 7 | ## Guidelines 8 | 9 | - Images can be in JPEG or PNG format. 10 | - Dimensions and size don't matter. 11 | - Filenames don't matter. 12 | - Images can be of yourself, your pet, your favorite stuffed animal, or any unique object. For best results, your images should contain only the subject itself, with a minimum of background noise or other objects. 13 | - Use a minimum of three images, but the model will tend to produce better results if you train it with more images, around 10-20. 14 | - Do not use images of other people without their consent. -------------------------------------------------------------------------------- /data/puppy-01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/dreambooth-action/21268da7a1e0caa690e751346bf9f7c1b802713f/data/puppy-01.jpeg -------------------------------------------------------------------------------- /data/puppy-02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/dreambooth-action/21268da7a1e0caa690e751346bf9f7c1b802713f/data/puppy-02.jpeg -------------------------------------------------------------------------------- /data/puppy-03.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/dreambooth-action/21268da7a1e0caa690e751346bf9f7c1b802713f/data/puppy-03.jpeg -------------------------------------------------------------------------------- /data/puppy-04.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/dreambooth-action/21268da7a1e0caa690e751346bf9f7c1b802713f/data/puppy-04.jpeg -------------------------------------------------------------------------------- /data/puppy-05.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/replicate/dreambooth-action/21268da7a1e0caa690e751346bf9f7c1b802713f/data/puppy-05.jpeg --------------------------------------------------------------------------------