{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "NwX3beTv8Hun"
   },
   "outputs": [],
   "source": [
    "from diffusers import AutoPipelineForText2Image\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "LrjNA122zX44"
   },
   "outputs": [],
   "source": [
    "pipe = AutoPipelineForText2Image.from_pretrained(\n",
    "    \"stabilityai/sd-turbo\",\n",
    "    torch_dtype=torch.float16,\n",
    "    variant=\"fp16\",\n",
    ").to(\"cuda\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "IYDAYNSYb_d6"
   },
   "outputs": [],
   "source": [
    "prompt = \"\"\"\n",
    "A realistic pink ceramic piggy bank on a plain white background, glossy surface,\n",
    "coin slot on top, soft studio lighting, high detail.\n",
    "\"\"\"\n",
    "seed = 5667"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "Cf71D2ElzX7m"
   },
   "outputs": [],
   "source": [
    "generator = torch.Generator(device=\"cuda\").manual_seed(seed)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "8vWpiv8xzYA7"
   },
   "outputs": [],
   "source": [
    "image = pipe(\n",
    "    prompt=prompt,\n",
    "    num_inference_steps=4,\n",
    "    guidance_scale=0.0,\n",
    "    height=512,\n",
    "    width=768,\n",
    "    generator=generator,\n",
    ").images[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "xWIaY83azYDx"
   },
   "outputs": [],
   "source": [
    "image.save(\"piggy-bank.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 273
    },
    "id": "Qg6mmIQsZwJg",
    "outputId": "568654be-3709-470c-c6a9-73fde93ea31a"
   },
   "outputs": [],
   "source": [
    "display(image.resize((384, 256)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "Sk7A3yYjgbQj"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "gpuType": "T4",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
