{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "4mDGz9V6JC0a", "outputId": "a52fc5ef-3095-4433-ab8f-3c9c80f96b51" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for diffusers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n" ] } ], "source": [ "!pip install git+https://github.com/cosmo3769/diffusers@standardize-model-card-template-t2i-adapter-sdxl -q" ] }, { "cell_type": "code", "source": [ "import os\n", "from PIL import Image\n", "from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card" ], "metadata": { "id": "r0rK5JfUrAfc" }, "execution_count": 4, "outputs": [] }, { "cell_type": "code", "source": [ "def image_grid(imgs, rows, cols):\n", " assert len(imgs) == rows * cols\n", "\n", " w, h = imgs[0].size\n", " grid = Image.new(\"RGB\", size=(cols * w, rows * h))\n", "\n", " for i, img in enumerate(imgs):\n", " grid.paste(img, box=(i % cols * w, i // cols * h))\n", " return grid" ], "metadata": { "id": "m68SWTnH4qGY" }, "execution_count": 5, "outputs": [] }, { "cell_type": "code", "source": [ "def save_model_card(repo_id: str, image_logs: dict = None, base_model: str = None, repo_folder: str = None):\n", " img_str = \"\"\n", " if image_logs is not None:\n", " img_str = \"You can find some example images below.\\n\"\n", " for i, log in enumerate(image_logs):\n", " images = log[\"images\"]\n", " validation_prompt = log[\"validation_prompt\"]\n", " validation_image = log[\"validation_image\"]\n", " validation_image.save(os.path.join(repo_folder, \"image_control.png\"))\n", " img_str += f\"prompt: {validation_prompt}\\n\"\n", " images = [validation_image] + images\n", " image_grid(images, 1, len(images)).save(os.path.join(repo_folder, f\"images_{i}.png\"))\n", " img_str += f\"![images_{i})](./images_{i}.png)\\n\"\n", "\n", " model_description = f\"\"\"\n", "# t2iadapter-{repo_id}\n", "\n", "These are t2iadapter weights trained on {base_model} with new type of conditioning.\n", "{img_str}\n", "\"\"\"\n", " model_card = load_or_create_model_card(\n", " repo_id_or_path=repo_id,\n", " from_training=True,\n", " license=\"creativeml-openrail-m\",\n", " base_model=base_model,\n", " model_description=model_description,\n", " inference=True,\n", " )\n", "\n", " tags = [\"stable-diffusion-xl\", \"stable-diffusion-xl-diffusers\", \"text-to-image\", \"diffusers\", \"t2iadapter\"]\n", " model_card = populate_model_card(model_card, tags=tags)\n", "\n", " model_card.save(os.path.join(repo_folder, \"README.md\"))" ], "metadata": { "id": "6mgnDhfzrTp4" }, "execution_count": 6, "outputs": [] }, { "cell_type": "code", "source": [ "from diffusers.utils import load_image\n", "\n", "images = [\n", " load_image(\"https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png\")\n", " for _ in range(3)\n", "]\n", "\n", "image_logs = [\n", " dict(\n", " images=[image],\n", " validation_prompt=\"validation_prompt\",\n", " validation_image=image,\n", " )\n", " for image in images\n", "]\n", "\n", "save_model_card(\n", " repo_id=\"cosmo3769/t2i-adapter-sdxl\",\n", " image_logs=image_logs,\n", " base_model=\"runwayml/stable-diffusion-v1-5\",\n", " repo_folder=\".\",\n", ")" ], "metadata": { "id": "JTEDsOd_rm7-" }, "execution_count": 7, "outputs": [] }, { "cell_type": "code", "source": [ "!cat README.md" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "NwCOmASdsUCT", "outputId": "c1422ff2-17ec-4917-f23f-1ebdcd9eab9c" }, "execution_count": 8, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "---\n", "license: creativeml-openrail-m\n", "library_name: diffusers\n", "tags:\n", "- stable-diffusion-xl\n", "- stable-diffusion-xl-diffusers\n", "- text-to-image\n", "- diffusers\n", "- t2iadapter\n", "inference: true\n", "base_model: runwayml/stable-diffusion-v1-5\n", "---\n", "\n", "\n", "\n", "\n", "# t2iadapter-cosmo3769/t2i-adapter-sdxl\n", "\n", "These are t2iadapter weights trained on runwayml/stable-diffusion-v1-5 with new type of conditioning.\n", "You can find some example images below.\n", "prompt: validation_prompt\n", "![images_0)](./images_0.png)\n", "prompt: validation_prompt\n", "![images_1)](./images_1.png)\n", "prompt: validation_prompt\n", "![images_2)](./images_2.png)\n", "\n", "\n", "\n", "## Intended uses & limitations\n", "\n", "#### How to use\n", "\n", "```python\n", "# TODO: add an example code snippet for running this diffusion pipeline\n", "```\n", "\n", "#### Limitations and bias\n", "\n", "[TODO: provide examples of latent issues and potential remediations]\n", "\n", "## Training details\n", "\n", "[TODO: describe the data used to train the model]" ] } ] }, { "cell_type": "code", "source": [], "metadata": { "id": "w7IqDNR72RGf" }, "execution_count": null, "outputs": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }