{ "cells": [ { "cell_type": "markdown", "id": "d139ba53", "metadata": {}, "source": [ "# Stable Diffusion 3.5 Large - Professional Image Generator\n", "\n", "This notebook provides a clean, professional interface for generating high-quality images using Stability AI's Stable Diffusion 3.5 Large model.\n", "\n", "---" ] }, { "cell_type": "markdown", "id": "24d783a3", "metadata": {}, "source": [ "## š¦ Install Required Dependencies\n", "\n", "First, let's install all necessary packages:" ] }, { "cell_type": "code", "execution_count": null, "id": "169bbf1a", "metadata": {}, "outputs": [], "source": [ "!pip install -q accelerate diffusers torch transformers gradio sentencepiece" ] }, { "cell_type": "markdown", "id": "0c59eabf", "metadata": {}, "source": [ "## š§ Import Libraries and Setup\n", "\n", "Import all necessary libraries and configure the environment:" ] }, { "cell_type": "code", "execution_count": null, "id": "d54d02dd", "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "import numpy as np\n", "import random\n", "from diffusers import DiffusionPipeline\n", "import torch\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "print(\"ā Libraries imported successfully\")\n", "print(f\"š„ CUDA Available: {torch.cuda.is_available()}\")\n", "if torch.cuda.is_available():\n", " print(f\"š» GPU: {torch.cuda.get_device_name(0)}\")" ] }, { "cell_type": "markdown", "id": "a9d3f107", "metadata": {}, "source": [ "## š Load Stable Diffusion 3.5 Large Model\n", "\n", "This will download and initialize the model (may take a few minutes on first run):" ] }, { "cell_type": "code", "execution_count": null, "id": "bc662d4b", "metadata": {}, "outputs": [], "source": [ "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n", "model_repo_id = \"stabilityai/stable-diffusion-3.5-large\"\n", "\n", "if torch.cuda.is_available():\n", " torch_dtype = torch.bfloat16\n", "else:\n", " torch_dtype = torch.float32\n", "\n", "print(\"š„ Loading model... (this may take a few minutes)\")\n", "pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)\n", "pipe = pipe.to(device)\n", "print(\"ā Model loaded successfully!\")\n", "\n", "MAX_SEED = np.iinfo(np.int32).max\n", "MAX_IMAGE_SIZE = 1024" ] }, { "cell_type": "markdown", "id": "cd5d7f09", "metadata": {}, "source": [ "## šØ Define Image Generation Function\n", "\n", "Core function that handles the image generation process:" ] }, { "cell_type": "code", "execution_count": null, "id": "8a8c69ed", "metadata": {}, "outputs": [], "source": [ "def generate_image(\n", " prompt,\n", " negative_prompt=\"\",\n", " seed=42,\n", " randomize_seed=False,\n", " width=1024,\n", " height=1024,\n", " guidance_scale=4.5,\n", " num_inference_steps=40,\n", " progress=gr.Progress(track_tqdm=True),\n", "):\n", " \"\"\"\n", " Generate an image based on the provided prompt and parameters.\n", " \"\"\"\n", " if randomize_seed:\n", " seed = random.randint(0, MAX_SEED)\n", "\n", " generator = torch.Generator(device=device).manual_seed(seed)\n", "\n", " image = pipe(\n", " prompt=prompt,\n", " negative_prompt=negative_prompt,\n", " guidance_scale=guidance_scale,\n", " num_inference_steps=num_inference_steps,\n", " width=width,\n", " height=height,\n", " generator=generator,\n", " ).images[0]\n", "\n", " return image, seed\n", "\n", "print(\"ā Image generation function ready\")" ] }, { "cell_type": "markdown", "id": "52857ec3", "metadata": {}, "source": [ "## šÆ Launch Professional Gradio Interface\n", "\n", "Creating a clean, modern white UI with professional styling:" ] }, { "cell_type": "code", "execution_count": null, "id": "14c54e8f", "metadata": {}, "outputs": [], "source": [ "# Professional example prompts\n", "examples = [\n", " \"A serene mountain landscape at sunset with crystal clear lake reflections, photorealistic, 8k quality\",\n", " \"Modern minimalist office space with floor-to-ceiling windows, natural lighting, architectural photography\",\n", " \"Portrait of a woman in elegant evening dress, studio lighting, fashion photography, high detail\",\n", " \"Futuristic city skyline at night with neon lights, cyberpunk aesthetic, ultra detailed\",\n", " \"Cozy coffee shop interior with warm ambient lighting, bokeh effect, professional photography\",\n", "]\n", "\n", "# Modern, clean CSS styling\n", "css = \"\"\"\n", "@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');\n", "\n", "* {\n", " font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n", "}\n", "\n", "#main-container {\n", " max-width: 1400px;\n", " margin: 0 auto;\n", " padding: 2rem;\n", " background: #ffffff;\n", "}\n", "\n", ".header-section {\n", " text-align: center;\n", " padding: 2rem 0;\n", " border-bottom: 1px solid #e5e7eb;\n", " margin-bottom: 2rem;\n", "}\n", "\n", ".header-section h1 {\n", " font-size: 2.5rem;\n", " font-weight: 700;\n", " color: #111827;\n", " margin-bottom: 0.5rem;\n", " letter-spacing: -0.025em;\n", "}\n", "\n", ".header-section p {\n", " font-size: 1.125rem;\n", " color: #6b7280;\n", " font-weight: 400;\n", "}\n", "\n", ".input-section {\n", " background: #f9fafb;\n", " padding: 2rem;\n", " border-radius: 12px;\n", " border: 1px solid #e5e7eb;\n", " margin-bottom: 1.5rem;\n", "}\n", "\n", ".output-section {\n", " background: #ffffff;\n", " padding: 1.5rem;\n", " border-radius: 12px;\n", " border: 1px solid #e5e7eb;\n", " box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);\n", "}\n", "\n", "button.primary {\n", " background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;\n", " border: none !important;\n", " color: white !important;\n", " font-weight: 600 !important;\n", " padding: 0.75rem 2rem !important;\n", " border-radius: 8px !important;\n", " font-size: 1rem !important;\n", " transition: all 0.3s ease !important;\n", " box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;\n", "}\n", "\n", "button.primary:hover {\n", " transform: translateY(-2px);\n", " box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1) !important;\n", "}\n", "\n", ".accordion {\n", " background: #ffffff !important;\n", " border: 1px solid #e5e7eb !important;\n", " border-radius: 8px !important;\n", " margin-top: 1rem;\n", "}\n", "\n", "label {\n", " font-weight: 500 !important;\n", " color: #374151 !important;\n", " font-size: 0.875rem !important;\n", " text-transform: uppercase;\n", " letter-spacing: 0.05em;\n", " margin-bottom: 0.5rem !important;\n", "}\n", "\n", "input, textarea {\n", " border: 1px solid #d1d5db !important;\n", " border-radius: 8px !important;\n", " padding: 0.75rem !important;\n", " font-size: 1rem !important;\n", " transition: border-color 0.2s ease !important;\n", "}\n", "\n", "input:focus, textarea:focus {\n", " border-color: #667eea !important;\n", " outline: none !important;\n", " box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;\n", "}\n", "\n", ".slider {\n", " margin: 1rem 0;\n", "}\n", "\n", ".examples {\n", " margin-top: 2rem;\n", " padding-top: 2rem;\n", " border-top: 1px solid #e5e7eb;\n", "}\n", "\n", ".footer {\n", " text-align: center;\n", " padding: 2rem 0;\n", " color: #9ca3af;\n", " font-size: 0.875rem;\n", " margin-top: 3rem;\n", " border-top: 1px solid #e5e7eb;\n", "}\n", "\n", "/* Clean scrollbar */\n", "::-webkit-scrollbar {\n", " width: 8px;\n", " height: 8px;\n", "}\n", "\n", "::-webkit-scrollbar-track {\n", " background: #f1f1f1;\n", "}\n", "\n", "::-webkit-scrollbar-thumb {\n", " background: #888;\n", " border-radius: 4px;\n", "}\n", "\n", "::-webkit-scrollbar-thumb:hover {\n", " background: #555;\n", "}\n", "\"\"\"\n", "\n", "# Create the Gradio interface\n", "with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue=\"indigo\", neutral_hue=\"slate\")) as demo:\n", " with gr.Column(elem_id=\"main-container\"):\n", " \n", " # Header\n", " with gr.Row(elem_classes=\"header-section\"):\n", " gr.HTML(\"\"\"\n", "
Professional AI Image Generation - 8B Parameter Model
\n", "