{ "cells": [ { "cell_type": "code", "execution_count": 16, "id": "e33a98a1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from dotenv import load_dotenv\n", "load_dotenv(override=True)" ] }, { "cell_type": "code", "execution_count": 17, "id": "0f3d7535", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "โœ… API Key found\n", "๐Ÿ“‚ Input folder : C:\\Users\\ASUS\\projects\\agents\\1_foundations\\input_images\n", "๐Ÿ“‚ Output folder: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\n" ] } ], "source": [ "import os\n", "from pathlib import Path\n", "\n", "# Set your key in environment variable before running notebook\n", "# export OPENAI_API_KEY=\"your_key\" (mac/linux)\n", "# setx OPENAI_API_KEY \"your_key\" (windows)\n", "\n", "OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\")\n", "assert OPENAI_API_KEY, \"โŒ OPENAI_API_KEY not found in environment variables\"\n", "\n", "INPUT_DIR = Path(\"input_images\") # put images here\n", "OUTPUT_DIR = Path(\"synthetic_output\") # generated images saved here\n", "OUTPUT_DIR.mkdir(exist_ok=True)\n", "\n", "print(\"โœ… API Key found\")\n", "print(\"๐Ÿ“‚ Input folder :\", INPUT_DIR.resolve())\n", "print(\"๐Ÿ“‚ Output folder:\", OUTPUT_DIR.resolve())\n" ] }, { "cell_type": "code", "execution_count": 46, "id": "ba4cd0d2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Note: you may need to restart the kernel to use updated packages.\n", "โœ… Installed dependencies\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "[notice] A new release of pip is available: 25.3 -> 26.0.1\n", "[notice] To update, run: python.exe -m pip install --upgrade pip\n" ] } ], "source": [ "%pip install openai pillow tqdm diffusers transformers accelerate safetensors torch --quiet\n", "print(\"โœ… Installed dependencies\")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "58942a26", "metadata": {}, "outputs": [], "source": [ "# from openai import OpenAI\n", "# openai = OpenAI()\n", "# google_api_key=os.getenv(\"GOOGLE_API_KEY\")\n", "\n", "# gemini = OpenAI(api_key=google_api_key, base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\")\n" ] }, { "cell_type": "code", "execution_count": 19, "id": "997f9adf", "metadata": {}, "outputs": [], "source": [ "from openai import OpenAI\n", "import base64\n", "\n", "client = OpenAI(api_key=OPENAI_API_KEY)\n", "\n", "def to_base64_image(image_path: Path):\n", " return base64.b64encode(image_path.read_bytes()).decode(\"utf-8\")\n", "\n", "def anatomy_to_prompt(image_path: Path):\n", " \"\"\"\n", " Agent step:\n", " 1) Understand anatomy/tissue type + staining + constraints\n", " 2) Output a prompt to generate 1 synthetic image (same constraints)\n", " \"\"\"\n", " \n", " print(\"\\n\" + \"=\"*80)\n", " print(f\"๐Ÿง  AGENT: Analyzing image -> {image_path.name}\")\n", "\n", " b64 = to_base64_image(image_path)\n", "\n", "# system = \"\"\"You are a medical imaging expert assistant.\n", "# You must inspect the image and generate a SHORT prompt for synthetic image generation.\n", "# Constraints:\n", "# - Preserve tissue type and anatomical structure, tissue is of human\n", "# - Preserve staining style (H&E etc.)\n", "# - No text, no watermark, no labels\n", "# - Realistic microscopy / histopathology look\n", "# Return ONLY JSON with keys:\n", "# {\n", "# \"anatomy_guess\": \"...\",\n", "# \"stain_guess\": \"...\",\n", "# \"prompt\": \"...\",\n", "# \"negative_prompt\": \"...\"\n", "# }\n", "# \"\"\"\n", "\n", " system = \"\"\"\n", "You are a medical imaging expert specializing in cytology and histopathology.\n", "\n", "TASK:\n", "Inspect the provided microscopy image and generate a diffusion-ready text prompt\n", "to synthesize ONE realistic synthetic image with the SAME visual constraints.\n", "\n", "STRICT RULES:\n", "- Tissue is human breast (do NOT guess subtypes unless visually obvious)\n", "- Describe ONLY what is visually observable\n", "- Preserve staining style exactly as seen\n", "- Preserve cellularity, nuclear morphology, and spatial arrangement\n", "- Use concise, comma-separated phrases (diffusion prompt style)\n", "- Do NOT write full sentences\n", "- Do NOT repeat concepts\n", "- Do NOT add interpretations, diagnoses, or probabilities\n", "- No text, no watermark, no labels\n", "\n", "OUTPUT FORMAT (JSON ONLY):\n", "{\n", " \"anatomy_guess\": \"concise visual description of breast cytology / histology\",\n", " \"stain_guess\": \"observed stain only\",\n", " \"prompt\": \"comma-separated diffusion prompt describing malignant breast cytomorphology\",\n", " \"negative_prompt\": \"comma-separated exclusions including benign breast features and artifacts\"\n", "}\n", "\n", "NEGATIVE PROMPT MUST EXCLUDE:\n", "- benign breast epithelial patterns\n", "- myoepithelial cell layers\n", "- uniform nuclei\n", "- abundant cytoplasm\n", "- inflammatory predominance\n", "- stromal or histopathology sections\n", "- incorrect stains (e.g. H&E if not present)\n", "- labels, annotations, scale bars\n", "- cartoon or synthetic appearance\n", "\"\"\"\n", "\n", "\n", " resp = client.chat.completions.create(\n", " model=\"gpt-4o-mini\",\n", " response_format={\"type\":\"json_object\"},\n", " messages=[\n", " {\"role\":\"system\", \"content\": system},\n", " {\"role\":\"user\", \"content\": [\n", " {\"type\":\"text\", \"text\": \"Look at this medical microscopy image and produce the JSON output.\"},\n", " {\"type\":\"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{b64}\"}}\n", " ]}\n", " ],\n", " temperature=0.4\n", " )\n", "\n", " # resp = gemini.chat.completions.create(\n", " # model=\"gemini-3-flash-preview\",\n", " # response_format={\"type\":\"json_object\"},\n", " # messages=[\n", " # {\"role\":\"system\", \"content\": system},\n", " # {\"role\":\"user\", \"content\": [\n", " # {\"type\":\"text\", \"text\": \"Look at this medical microscopy image and produce the JSON output.\"},\n", " # {\"type\":\"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{b64}\"}}\n", " # ]}\n", " # ],\n", " # temperature=0.4\n", " # )\n", "\n", "\n", " \n", "\n", " data = resp.choices[0].message.content\n", " print(\"โœ… AGENT: Prompt JSON created\")\n", " print(\"๐Ÿ“ฆ RAW JSON:\", data)\n", "\n", " import json\n", " return json.loads(data)\n" ] }, { "cell_type": "code", "execution_count": 20, "id": "641ef424", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\ASUS\\projects\\.venv\\Lib\\site-packages\\diffusers\\models\\transformers\\transformer_kandinsky.py:168: UserWarning: CUDA is not available or torch_xla is imported. Disabling autocast.\n", " @torch.autocast(device_type=\"cuda\", dtype=torch.float32)\n", "c:\\Users\\ASUS\\projects\\.venv\\Lib\\site-packages\\diffusers\\models\\transformers\\transformer_kandinsky.py:272: UserWarning: CUDA is not available or torch_xla is imported. Disabling autocast.\n", " @torch.autocast(device_type=\"cuda\", dtype=torch.float32)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "๐Ÿ–ฅ๏ธ Device: cpu\n", "โณ Loading Stable Diffusion img2img model...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "88291aa8d2b147ddbe51e60d45e261d1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading pipeline components...: 0%| | 0/6 [00:00 by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "โœ… Model loaded\n" ] } ], "source": [ "import torch\n", "from diffusers import StableDiffusionImg2ImgPipeline\n", "from PIL import Image\n", "\n", "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n", "print(\"๐Ÿ–ฅ๏ธ Device:\", device)\n", "\n", "print(\"โณ Loading Stable Diffusion img2img model...\")\n", "pipe = StableDiffusionImg2ImgPipeline.from_pretrained(\n", " \"runwayml/stable-diffusion-v1-5\",\n", " torch_dtype=torch.float16 if device==\"cuda\" else torch.float32,\n", " safety_checker=None\n", ").to(device)\n", "\n", "print(\"โœ… Model loaded\")\n" ] }, { "cell_type": "markdown", "id": "b4f0cf6b", "metadata": {}, "source": [ "`try to vary strength(0.35 โ€“ 0.55) how much output change from input`" ] }, { "cell_type": "markdown", "id": "87817ad7", "metadata": {}, "source": [ "`for faster response reduce num_inference_steps(denoising) to 25-35`" ] }, { "cell_type": "code", "execution_count": null, "id": "22f99396", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 23, "id": "a8694154", "metadata": {}, "outputs": [], "source": [ "\n", "def generate_one_synthetic(image_path: Path, strength=0.35):\n", " \"\"\"\n", " strength controls how much the generated image changes:\n", " - 0.2 = very similar\n", " - 0.45 = good synthetic variation\n", " - 0.7 = large change\n", " \"\"\"\n", " meta = anatomy_to_prompt(image_path)\n", " \n", " print(\"\\n๐ŸŽฏ AGENT OUTPUT SUMMARY\")\n", " print(\" Anatomy guess:\", meta.get(\"anatomy_guess\"))\n", " print(\" Stain guess :\", meta.get(\"stain_guess\"))\n", " print(\" Prompt :\", meta.get(\"prompt\"))\n", " print(\" Neg Prompt :\", meta.get(\"negative_prompt\"))\n", "\n", " print(\"\\n๐Ÿงช GENERATION: Starting diffusion img2img...\")\n", " \n", " init_img = Image.open(image_path).convert(\"RGB\").resize((512,512))\n", " \n", " out_img = pipe(\n", " prompt=meta[\"prompt\"],\n", " negative_prompt=meta[\"negative_prompt\"],\n", " image=init_img,\n", " strength=strength,\n", " guidance_scale=7.5,\n", " num_inference_steps=28\n", " ).images[0]\n", "\n", " out_path = OUTPUT_DIR / f\"{image_path.stem}_synthetic.png\"\n", " out_img.save(out_path)\n", "\n", " print(\"โœ… GENERATION DONE\")\n", " print(\"๐Ÿ’พ Saved:\", out_path.resolve())\n", " \n", " return out_path\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "0f335c69", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "๐Ÿ“Œ Found 8 images\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ " 0%| | 0/8 [00:00 SOB_M_DC-14-16448-400-006.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast tissue, disorganized cellular arrangement, irregular nuclear shapes\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"disorganized cellular architecture, irregular nuclear contours, hyperchromatic nuclei, scant cytoplasm, necrotic debris, varying cell sizes, increased nuclear-to-cytoplasmic ratio\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast tissue, disorganized cellular arrangement, irregular nuclear shapes\n", " Stain guess : H&E\n", " Prompt : disorganized cellular architecture, irregular nuclear contours, hyperchromatic nuclei, scant cytoplasm, necrotic debris, varying cell sizes, increased nuclear-to-cytoplasmic ratio\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "49b39422794f44579167cf83321fb2c7", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00 SOB_M_DC-14-16448-400-008.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast tissue, irregular cellular arrangement, high cellularity\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"abnormal nuclei, prominent nucleoli, irregular nuclear contours, scant cytoplasm, pleomorphic cells, disorganized architecture, hyperchromatic nuclei\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast tissue, irregular cellular arrangement, high cellularity\n", " Stain guess : H&E\n", " Prompt : abnormal nuclei, prominent nucleoli, irregular nuclear contours, scant cytoplasm, pleomorphic cells, disorganized architecture, hyperchromatic nuclei\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "04e511456295434391fafaef7e5c2950", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00 SOB_M_DC-14-16448-400-009.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast tissue, disorganized architecture, irregular cellular arrangement\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"irregular nuclei, pleomorphic cells, high nuclear-to-cytoplasmic ratio, prominent nucleoli, scattered atypical cells, dense fibrous stroma, areas of necrosis\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast tissue, disorganized architecture, irregular cellular arrangement\n", " Stain guess : H&E\n", " Prompt : irregular nuclei, pleomorphic cells, high nuclear-to-cytoplasmic ratio, prominent nucleoli, scattered atypical cells, dense fibrous stroma, areas of necrosis\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dbcb755d526e4654b2d2e4c25fdfad69", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00 SOB_M_DC-14-16448-400-011.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast tissue with dense cellular arrangement\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"irregularly shaped nuclei, prominent nucleoli, eosinophilic cytoplasm, scattered atypical cells, dense fibrous stroma, varied nuclear sizes, disrupted architecture\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast tissue with dense cellular arrangement\n", " Stain guess : H&E\n", " Prompt : irregularly shaped nuclei, prominent nucleoli, eosinophilic cytoplasm, scattered atypical cells, dense fibrous stroma, varied nuclear sizes, disrupted architecture\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7aae4a1fc4364434b26f699508813f54", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00 SOB_M_DC-14-16448-400-012.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast tissue, fibrous stroma, scattered cells\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"pink-stained fibrous tissue, irregularly shaped cells, scattered nuclei, thin collagen fibers, high cellularity, varying nuclear sizes, prominent nucleoli\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast tissue, fibrous stroma, scattered cells\n", " Stain guess : H&E\n", " Prompt : pink-stained fibrous tissue, irregularly shaped cells, scattered nuclei, thin collagen fibers, high cellularity, varying nuclear sizes, prominent nucleoli\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d92c36f80aa948babcc732b02d88bddb", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00 SOB_M_DC-14-16448-400-013.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast tissue, fibrous stroma, scattered cells\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"fibroblasts, elongated nuclei, irregular cell shapes, dense collagen fibers, pink and purple staining, scattered cellularity\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast tissue, fibrous stroma, scattered cells\n", " Stain guess : H&E\n", " Prompt : fibroblasts, elongated nuclei, irregular cell shapes, dense collagen fibers, pink and purple staining, scattered cellularity\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "518bb8f999254edd8204ab407fcca5af", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00 SOB_M_DC-14-16448-400-014.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast tissue, fibrous stroma, scattered cells\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"pink and purple staining, elongated fibrous structures, irregular cell shapes, scattered dark nuclei, background of eosinophilic material, moderate cellularity\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast tissue, fibrous stroma, scattered cells\n", " Stain guess : H&E\n", " Prompt : pink and purple staining, elongated fibrous structures, irregular cell shapes, scattered dark nuclei, background of eosinophilic material, moderate cellularity\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a1434d0255ca4bb1828a3fd0f945b926", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00 SOB_M_DC-14-16601-400-001.png\n", "โœ… AGENT: Prompt JSON created\n", "๐Ÿ“ฆ RAW JSON: {\n", " \"anatomy_guess\": \"human breast cytology\",\n", " \"stain_guess\": \"H&E\",\n", " \"prompt\": \"irregular nuclei, prominent nucleoli, high nuclear-to-cytoplasmic ratio, scattered atypical cells, pleomorphic cell shapes, necrotic debris, background inflammation, pink and purple staining, cell clusters\",\n", " \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n", "}\n", "\n", "๐ŸŽฏ AGENT OUTPUT SUMMARY\n", " Anatomy guess: human breast cytology\n", " Stain guess : H&E\n", " Prompt : irregular nuclei, prominent nucleoli, high nuclear-to-cytoplasmic ratio, scattered atypical cells, pleomorphic cell shapes, necrotic debris, background inflammation, pink and purple staining, cell clusters\n", " Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n", "\n", "๐Ÿงช GENERATION: Starting diffusion img2img...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "007d766cd1994112b979d2dc9832e2f9", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/12 [00:00here for more info. \n", "\u001b[1;31mView Jupyter log for further details." ] } ], "source": [ "from tqdm import tqdm\n", "\n", "images = list(INPUT_DIR.glob(\"*.png\")) + list(INPUT_DIR.glob(\"*.jpg\")) + list(INPUT_DIR.glob(\"*.jpeg\"))\n", "\n", "print(f\"๐Ÿ“Œ Found {len(images)} images\")\n", "\n", "for img_path in tqdm(images):\n", " try:\n", " print(\"\\n\" + \"#\"*90)\n", " print(f\"๐Ÿš€ Processing: {img_path.name}\")\n", " generate_one_synthetic(img_path, strength=0.45)\n", " print(f\"โœ… Completed: {img_path.name}\")\n", " except Exception as e:\n", " print(f\"โŒ Failed: {img_path.name}\")\n", " print(\"Reason:\", str(e))\n" ] }, { "cell_type": "code", "execution_count": null, "id": "92463c80", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.13.7" } }, "nbformat": 4, "nbformat_minor": 5 }