{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "gpuType": "T4" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "L1CPm6HAZuTg", "outputId": "3a85cb03-b18f-4e5b-8c5f-2f577bc46598" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (2.4.0+cu121)\n", "Collecting diffusers\n", " Downloading diffusers-0.30.2-py3-none-any.whl.metadata (18 kB)\n", "Collecting spaces\n", " Downloading spaces-0.30.2-py3-none-any.whl.metadata (1.0 kB)\n", "Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (4.44.2)\n", "Collecting peft\n", " Downloading peft-0.12.0-py3-none-any.whl.metadata (13 kB)\n", "Requirement already satisfied: sentencepiece in /usr/local/lib/python3.10/dist-packages (0.1.99)\n", "Collecting gradio\n", " Downloading gradio-4.43.0-py3-none-any.whl.metadata (15 kB)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch) (3.15.4)\n", "Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from torch) (4.12.2)\n", "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch) (1.13.2)\n", "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch) (3.3)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch) (3.1.4)\n", "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch) (2024.6.1)\n", "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.10/dist-packages (from diffusers) (8.4.0)\n", "Requirement already satisfied: huggingface-hub>=0.23.2 in /usr/local/lib/python3.10/dist-packages (from diffusers) (0.24.6)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from diffusers) (1.26.4)\n", "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from diffusers) (2024.5.15)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from diffusers) (2.32.3)\n", "Requirement already satisfied: safetensors>=0.3.1 in /usr/local/lib/python3.10/dist-packages (from diffusers) (0.4.4)\n", "Requirement already satisfied: Pillow in /usr/local/lib/python3.10/dist-packages (from diffusers) (9.4.0)\n", "Collecting httpx>=0.20 (from spaces)\n", " Downloading httpx-0.27.2-py3-none-any.whl.metadata (7.1 kB)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from spaces) (24.1)\n", "Requirement already satisfied: psutil<6,>=2 in /usr/local/lib/python3.10/dist-packages (from spaces) (5.9.5)\n", "Requirement already satisfied: pydantic<3,>=1 in /usr/local/lib/python3.10/dist-packages (from spaces) (2.8.2)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (6.0.2)\n", "Requirement already satisfied: tokenizers<0.20,>=0.19 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.19.1)\n", "Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.10/dist-packages (from transformers) (4.66.5)\n", "Requirement already satisfied: accelerate>=0.21.0 in /usr/local/lib/python3.10/dist-packages (from peft) (0.33.0)\n", "Collecting aiofiles<24.0,>=22.0 (from gradio)\n", " Downloading aiofiles-23.2.1-py3-none-any.whl.metadata (9.7 kB)\n", "Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n", "Collecting fastapi<0.113.0 (from gradio)\n", " Downloading fastapi-0.112.4-py3-none-any.whl.metadata (27 kB)\n", "Collecting ffmpy (from gradio)\n", " Downloading ffmpy-0.4.0-py3-none-any.whl.metadata (2.9 kB)\n", "Collecting gradio-client==1.3.0 (from gradio)\n", " Downloading gradio_client-1.3.0-py3-none-any.whl.metadata (7.1 kB)\n", "Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.4.4)\n", "Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.5)\n", "Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n", "Collecting orjson~=3.0 (from gradio)\n", " Downloading orjson-3.10.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (50 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.4/50.4 kB\u001b[0m \u001b[31m1.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.4)\n", "Collecting pydub (from gradio)\n", " Downloading pydub-0.25.1-py2.py3-none-any.whl.metadata (1.4 kB)\n", "Collecting python-multipart>=0.0.9 (from gradio)\n", " Downloading python_multipart-0.0.9-py3-none-any.whl.metadata (2.5 kB)\n", "Collecting ruff>=0.2.2 (from gradio)\n", " Downloading ruff-0.6.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (25 kB)\n", "Collecting semantic-version~=2.0 (from gradio)\n", " Downloading semantic_version-2.10.0-py2.py3-none-any.whl.metadata (9.7 kB)\n", "Collecting tomlkit==0.12.0 (from gradio)\n", " Downloading tomlkit-0.12.0-py3-none-any.whl.metadata (2.7 kB)\n", "Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.5)\n", "Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.7)\n", "Collecting uvicorn>=0.14.0 (from gradio)\n", " Downloading uvicorn-0.30.6-py3-none-any.whl.metadata (6.6 kB)\n", "Collecting websockets<13.0,>=10.0 (from gradio-client==1.3.0->gradio)\n", " Downloading websockets-12.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.6 kB)\n", "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (3.8)\n", "Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\n", "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.2.2)\n", "Collecting starlette<0.39.0,>=0.37.2 (from fastapi<0.113.0->gradio)\n", " Downloading starlette-0.38.5-py3-none-any.whl.metadata (6.0 kB)\n", "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.20->spaces) (2024.8.30)\n", "Collecting httpcore==1.* (from httpx>=0.20->spaces)\n", " Downloading httpcore-1.0.5-py3-none-any.whl.metadata (20 kB)\n", "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx>=0.20->spaces)\n", " Downloading h11-0.14.0-py3-none-any.whl.metadata (8.2 kB)\n", "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.3.0)\n", "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n", "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.53.1)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n", "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.4)\n", "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->spaces) (0.7.0)\n", "Requirement already satisfied: pydantic-core==2.20.1 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->spaces) (2.20.1)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->diffusers) (3.3.2)\n", "Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n", "Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n", "Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (13.8.0)\n", "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.10/dist-packages (from importlib-metadata->diffusers) (3.20.1)\n", "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy->torch) (1.3.0)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.16.1)\n", "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n", "Downloading diffusers-0.30.2-py3-none-any.whl (2.6 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.6/2.6 MB\u001b[0m \u001b[31m38.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading spaces-0.30.2-py3-none-any.whl (27 kB)\n", "Downloading peft-0.12.0-py3-none-any.whl (296 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m296.4/296.4 kB\u001b[0m \u001b[31m21.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading gradio-4.43.0-py3-none-any.whl (18.1 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m18.1/18.1 MB\u001b[0m \u001b[31m67.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading gradio_client-1.3.0-py3-none-any.whl (318 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.7/318.7 kB\u001b[0m \u001b[31m20.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading tomlkit-0.12.0-py3-none-any.whl (37 kB)\n", "Downloading aiofiles-23.2.1-py3-none-any.whl (15 kB)\n", "Downloading fastapi-0.112.4-py3-none-any.whl (93 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m93.9/93.9 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading httpx-0.27.2-py3-none-any.whl (76 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.4/76.4 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading orjson-3.10.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (141 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.9/141.9 kB\u001b[0m \u001b[31m12.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading python_multipart-0.0.9-py3-none-any.whl (22 kB)\n", "Downloading ruff-0.6.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.3 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.3/10.3 MB\u001b[0m \u001b[31m82.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n", "Downloading uvicorn-0.30.6-py3-none-any.whl (62 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.8/62.8 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading ffmpy-0.4.0-py3-none-any.whl (5.8 kB)\n", "Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n", "Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading starlette-0.38.5-py3-none-any.whl (71 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.4/71.4 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading websockets-12.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (130 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.2/130.2 kB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hInstalling collected packages: pydub, websockets, tomlkit, semantic-version, ruff, python-multipart, orjson, h11, ffmpy, aiofiles, uvicorn, starlette, httpcore, httpx, fastapi, diffusers, gradio-client, peft, gradio, spaces\n", " Attempting uninstall: tomlkit\n", " Found existing installation: tomlkit 0.13.2\n", " Uninstalling tomlkit-0.13.2:\n", " Successfully uninstalled tomlkit-0.13.2\n", "Successfully installed aiofiles-23.2.1 diffusers-0.30.2 fastapi-0.112.4 ffmpy-0.4.0 gradio-4.43.0 gradio-client-1.3.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.2 orjson-3.10.7 peft-0.12.0 pydub-0.25.1 python-multipart-0.0.9 ruff-0.6.4 semantic-version-2.10.0 spaces-0.30.2 starlette-0.38.5 tomlkit-0.12.0 uvicorn-0.30.6 websockets-12.0\n" ] } ], "source": [ "!pip install torch diffusers spaces transformers peft sentencepiece gradio" ] }, { "cell_type": "code", "source": [ "# Authenticate with Hugging Face\n", "from huggingface_hub import login\n", "\n", "# Log in to Hugging Face using the provided token\n", "hf_token = 'hf-token-authentication'\n", "login(hf_token)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "1Q39l67NZ4F-", "outputId": "d5c36fff-c230-4101-917b-8bb13a717d40" }, "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n", "Token is valid (permission: fineGrained).\n", "Your token has been saved to /root/.cache/huggingface/token\n", "Login successful\n" ] } ] }, { "cell_type": "code", "source": [ "import spaces\n", "import gradio as gr\n", "import torch\n", "from PIL import Image\n", "from diffusers import DiffusionPipeline\n", "import random\n", "import uuid\n", "from typing import Tuple\n", "import numpy as np\n", "\n", "DESCRIPTIONz = \"\"\"## FLUX REALISM 🔥\"\"\"\n", "\n", "def save_image(img):\n", " unique_name = str(uuid.uuid4()) + \".png\"\n", " img.save(unique_name)\n", " return unique_name\n", "\n", "def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:\n", " if randomize_seed:\n", " seed = random.randint(0, MAX_SEED)\n", " return seed\n", "\n", "MAX_SEED = np.iinfo(np.int32).max\n", "\n", "if not torch.cuda.is_available():\n", " DESCRIPTIONz += \"\\n

⚠️Running on CPU, This may not work on CPU.

\"\n", "\n", "base_model = \"black-forest-labs/FLUX.1-dev\"\n", "pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)\n", "\n", "lora_repo = \"prithivMLmods/Canopus-LoRA-Flux-FaceRealism\"\n", "trigger_word = \"Realism\" # Leave trigger_word blank if not used.\n", "pipe.load_lora_weights(lora_repo)\n", "\n", "pipe.to(\"cuda\")\n", "\n", "style_list = [\n", " {\n", " \"name\": \"3840 x 2160\",\n", " \"prompt\": \"hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic\",\n", " },\n", " {\n", " \"name\": \"2560 x 1440\",\n", " \"prompt\": \"hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic\",\n", " },\n", " {\n", " \"name\": \"HD+\",\n", " \"prompt\": \"hyper-realistic 2K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic\",\n", " },\n", " {\n", " \"name\": \"Style Zero\",\n", " \"prompt\": \"{prompt}\",\n", " },\n", "]\n", "\n", "styles = {k[\"name\"]: k[\"prompt\"] for k in style_list}\n", "\n", "DEFAULT_STYLE_NAME = \"3840 x 2160\"\n", "STYLE_NAMES = list(styles.keys())\n", "\n", "def apply_style(style_name: str, positive: str) -> str:\n", " return styles.get(style_name, styles[DEFAULT_STYLE_NAME]).replace(\"{prompt}\", positive)\n", "\n", "@spaces.GPU(duration=60, enable_queue=True)\n", "def generate(\n", " prompt: str,\n", " seed: int = 0,\n", " width: int = 1024,\n", " height: int = 1024,\n", " guidance_scale: float = 3,\n", " randomize_seed: bool = False,\n", " style_name: str = DEFAULT_STYLE_NAME,\n", " progress=gr.Progress(track_tqdm=True),\n", "):\n", " seed = int(randomize_seed_fn(seed, randomize_seed))\n", "\n", " positive_prompt = apply_style(style_name, prompt)\n", "\n", " if trigger_word:\n", " positive_prompt = f\"{trigger_word} {positive_prompt}\"\n", "\n", " images = pipe(\n", " prompt=positive_prompt,\n", " width=width,\n", " height=height,\n", " guidance_scale=guidance_scale,\n", " num_inference_steps=16,\n", " num_images_per_prompt=1,\n", " output_type=\"pil\",\n", " ).images\n", " image_paths = [save_image(img) for img in images]\n", " print(image_paths)\n", " return image_paths, seed\n", "\n", "\n", "def load_predefined_images():\n", " predefined_images = [\n", " \"assets/11.png\",\n", " \"assets/22.png\",\n", " \"assets/33.png\",\n", " \"assets/44.png\",\n", " \"assets/55.webp\",\n", " \"assets/66.png\",\n", " \"assets/77.png\",\n", " \"assets/88.png\",\n", " \"assets/99.png\",\n", " ]\n", " return predefined_images\n", "\n", "\n", "\n", "examples = [\n", " \"A portrait of an attractive woman in her late twenties with light brown hair and purple, wearing large a a yellow sweater. She is looking directly at the camera, standing outdoors near trees.. --ar 128:85 --v 6.0 --style raw\",\n", " \"A photo of the model wearing a white bodysuit and beige trench coat, posing in front of a train station with hands on head, soft light, sunset, fashion photography, high resolution, 35mm lens, f/22, natural lighting, global illumination. --ar 85:128 --v 6.0 --style raw\",\n", "]\n", "\n", "\n", "css = '''\n", ".gradio-container{max-width: 575px !important}\n", "h1{text-align:center}\n", "footer {\n", " visibility: hidden\n", "}\n", "'''\n", "\n", "with gr.Blocks(css=css, theme=\"bethecloud/storj_theme\") as demo:\n", " gr.Markdown(DESCRIPTIONz)\n", " with gr.Row():\n", " prompt = gr.Text(\n", " label=\"Prompt\",\n", " show_label=False,\n", " max_lines=1,\n", " placeholder=\"Enter your prompt\",\n", " container=False,\n", " )\n", " run_button = gr.Button(\"Run\", scale=0)\n", " result = gr.Gallery(label=\"Result\", columns=1, show_label=False)\n", "\n", " with gr.Accordion(\"Advanced options\", open=False, visible=True):\n", " seed = gr.Slider(\n", " label=\"Seed\",\n", " minimum=0,\n", " maximum=MAX_SEED,\n", " step=1,\n", " value=0,\n", " visible=True\n", " )\n", " randomize_seed = gr.Checkbox(label=\"Randomize seed\", value=True)\n", "\n", " with gr.Row(visible=True):\n", " width = gr.Slider(\n", " label=\"Width\",\n", " minimum=512,\n", " maximum=2048,\n", " step=64,\n", " value=1024,\n", " )\n", " height = gr.Slider(\n", " label=\"Height\",\n", " minimum=512,\n", " maximum=2048,\n", " step=64,\n", " value=1024,\n", " )\n", "\n", " with gr.Row():\n", " guidance_scale = gr.Slider(\n", " label=\"Guidance Scale\",\n", " minimum=0.1,\n", " maximum=20.0,\n", " step=0.1,\n", " value=3.0,\n", " )\n", " num_inference_steps = gr.Slider(\n", " label=\"Number of inference steps\",\n", " minimum=1,\n", " maximum=40,\n", " step=1,\n", " value=16,\n", " )\n", "\n", " style_selection = gr.Radio(\n", " show_label=True,\n", " container=True,\n", " interactive=True,\n", " choices=STYLE_NAMES,\n", " value=DEFAULT_STYLE_NAME,\n", " label=\"Quality Style\",\n", " )\n", "\n", "\n", "\n", " gr.Examples(\n", " examples=examples,\n", " inputs=prompt,\n", " outputs=[result, seed],\n", " fn=generate,\n", " cache_examples=False,\n", " )\n", "\n", " gr.on(\n", " triggers=[\n", " prompt.submit,\n", " run_button.click,\n", " ],\n", " fn=generate,\n", " inputs=[\n", " prompt,\n", " seed,\n", " width,\n", " height,\n", " guidance_scale,\n", " randomize_seed,\n", " style_selection,\n", " ],\n", " outputs=[result, seed],\n", " api_name=\"run\",\n", " )\n", "\n", " gr.Markdown(\"### Generated Images\")\n", " predefined_gallery = gr.Gallery(label=\"Generated Images\", columns=3, show_label=False, value=load_predefined_images())\n", " gr.Markdown(\"**Disclaimer/Note:**\")\n", "\n", " gr.Markdown(\"🔥This space provides realistic image generation, which works better for human faces and portraits. Realistic trigger works properly, better for photorealistic trigger words, close-up shots, face diffusion, male, female characters.\")\n", "\n", " gr.Markdown(\"🔥users are accountable for the content they generate and are responsible for ensuring it meets appropriate ethical standards.\")\n", "\n", "if __name__ == \"__main__\":\n", " demo.queue(max_size=40).launch()" ], "metadata": { "id": "35LXnZWVaBZ_" }, "execution_count": null, "outputs": [] } ] }