{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: fal-client in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (0.5.0)\n",
      "Requirement already satisfied: python-dotenv in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (1.0.1)\n",
      "Requirement already satisfied: httpx<1,>=0.21.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from fal-client) (0.27.0)\n",
      "Requirement already satisfied: httpx-sse<0.5,>=0.4.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from fal-client) (0.4.0)\n",
      "Requirement already satisfied: anyio in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpx<1,>=0.21.0->fal-client) (3.6.2)\n",
      "Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpx<1,>=0.21.0->fal-client) (2022.12.7)\n",
      "Requirement already satisfied: httpcore==1.* in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpx<1,>=0.21.0->fal-client) (1.0.5)\n",
      "Requirement already satisfied: idna in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpx<1,>=0.21.0->fal-client) (3.4)\n",
      "Requirement already satisfied: sniffio in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpx<1,>=0.21.0->fal-client) (1.3.0)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from httpcore==1.*->httpx<1,>=0.21.0->fal-client) (0.14.0)\n",
      "\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install fal-client python-dotenv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'images': [{'url': 'https://fal.media/files/panda/GfghrsXA2Fv2ESUd44_jR.png', 'width': 1024, 'height': 768, 'content_type': 'image/jpeg'}], 'timings': {'inference': 2.032796171028167}, 'seed': 3356757010, 'has_nsfw_concepts': [False], 'prompt': \"Watercolor style image on a textured white paper background. In the center, elegant hand-lettered text reads 'Flux rules!' in a deep purple color with a slight watercolor bleed effect. Surrounding the text, soft watercolor illustrations represent key aspects of Flux rules!, with a paintbrush (for creativity), a swirling vortex (for dynamic generation), and a prism (for color manipulation). Use a muted color palette with purple, teal, gold, and soft pink tones. The watercolor elements should have gentle color gradients and subtle bleeding effects, with some areas of the white paper showing through. Add a few splatter effects in the background for texture. In the bottom right corner, a small graph with a rising trend line painted in a loose, artistic style.\"}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"https://fal.media/files/panda/GfghrsXA2Fv2ESUd44_jR.png\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import fal_client\n",
    "from IPython.display import Image, display\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "# Note: you need FAL_KEY set in your environment variables\n",
    "\n",
    "def generate_image(prompt, context):\n",
    "    handler = fal_client.submit(\n",
    "        \"fal-ai/flux\",\n",
    "        arguments={\n",
    "            \"prompt\": prompt.format(**context)\n",
    "        },\n",
    "    )\n",
    "\n",
    "    result = handler.get()\n",
    "    print(result)\n",
    "\n",
    "    image_url = result['images'][0]['url']\n",
    "    return image_url\n",
    "\n",
    "# https://x.com/jdnoc/status/1826701308365091262\n",
    "prompt = \"Watercolor style image on a textured white paper background. In the center, elegant hand-lettered text reads '{image_text}' in a deep {primary_color} color with a slight watercolor bleed effect. Surrounding the text, soft watercolor illustrations represent key aspects of {image_text}, with {image_illustrations}. Use a muted color palette with {primary_color}, {secondary_color}, {tertiary_color}, and soft {accent_color} tones. The watercolor elements should have gentle color gradients and subtle bleeding effects, with some areas of the white paper showing through. Add a few splatter effects in the background for texture. In the bottom right corner, a small graph with a rising trend line painted in a loose, artistic style.\"\n",
    "\n",
    "image_text = \"Flux rules!\"\n",
    "primary_color = \"purple\"\n",
    "secondary_color = \"teal\"\n",
    "tertiary_color = \"gold\"\n",
    "accent_color = \"pink\"\n",
    "image_illustrations = \"a paintbrush (for creativity), a swirling vortex (for dynamic generation), and a prism (for color manipulation)\"\n",
    "\n",
    "context = {\"image_text\": image_text, \"primary_color\": primary_color, \"secondary_color\": secondary_color, \"tertiary_color\": tertiary_color, \"accent_color\": accent_color, \"image_illustrations\": image_illustrations}\n",
    "\n",
    "blog_image = generate_image(prompt, context)\n",
    "display(Image(url=blog_image))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
