basilicom/ai-image-generator-bundle

v0.9.0 2023-11-13 11:33 UTC

This package is auto-updated.

Last update: 2024-09-08 16:06:04 UTC


README

此扩展程序利用生成式图像AI的常用API,在Pimcore后端生成图像。

安装

composer update basilicom/ai-image-generator-bundle

请确保通过BundleSetupSubscriber或控制台安装此扩展程序。

支持

配置

ai_image_generator:
   brand:
    colors:
      - "#0062FF"
      - "#B34197"
      - "#FF444A"

  prompt_enhancement:
    service:        ~|ollama|basilicom|open_ai

    services:
      ollama:
        baseUrl:    "https://:11434/"
        model:      "llama2"

      basilicom:
        baseUrl:    "https://:8080/"

      open_ai:
        baseUrl:    "https://api.openai.com/v1"
        apiKey:     "%env(OPEN_AI_API_KEY)%"

  feature_services:
    txt2img:            open_ai | stable_diffusion_api | dream_studio | clip_drop
    image_variations:   open_ai | stable_diffusion_api | dream_studio | clip_drop
    upscale:            -       | stable_diffusion_api | dream_studio | clip_drop
    inpaint:            open_ai | stable_diffusion_api | dream_studio | -
    inpaint_background: open_ai | stable_diffusion_api | -            | clip_drop

  services:
    stable_diffusion_api:
      baseUrl:        "http://host.docker.internal:7860"
      model:          "JuggernautXL"
      inpaint_model:  "JuggernautXL"
      steps:          30
      upscaler:       "ESRGAN_4x"
    
    dream_studio:
      baseUrl:        "https://api.stability.ai"
      model:          "stable-diffusion-xl-beta-v2-2-2"
      inpaint_model:  "stable-diffusion-xl-1024-v1-0"
      steps:          10 
      apiKey:         "%env(DREAM_STUDIO_API_KEY)%"
      upscaler:       "esrgan-v1-x2plus"
      
    open_ai:
      baseUrl:        "https://api.openai.com/v1"
      apiKey:         "%env(OPEN_AI_API_KEY)%"
      
    clip_drop:
      baseUrl:        "https://clipdrop-api.co"
      apiKey:         "%env(CLIP_DROP_API_KEY)%"

使用方法

在文档中生成图像

如果没有给出提示,将从以下内容生成提示(不进行翻译):

  • 文档SEO标题
  • 文档SEO描述
  • h1元素
  • h2元素
  • h3和h4元素(如果上述来源为空)

Image editables will get a button to generate an image

在数据对象中生成图像

如果没有给出提示,将尝试访问以下属性来生成提示(不进行翻译):

  • key
  • title
  • name
  • productName
  • description

Image and ImageGallery fields will get a context-menu-item to generate an image

API

(POST) /admin/ai-images/generate/{context}-{id}

基于文档或对象上下文生成图像。如果提示为空,则将生效提示逻辑。

(POST) /admin/ai-images/upscale/{id}

提升图像大小,目标提升大小由AI服务指定

(POST) /admin/ai-images/vary/{id}

对于提供AI服务的不同背景逻辑,进行背景修复

响应

根据Accept头部,您可以指定您希望接收JSON响应还是图像本身。

Accept: application/json

{
  success: true,
  id: Pimcore-Asset-ID,
  image: "base64-decoded Image",   
}
{
  success: false,
  message: "..."
}

Accept: image/jpeg

// the base64 decoded image

使用Stable Diffusion API

当本地运行Automatic1111时,您可以定义http://host.docker.internal:7860作为您的本地API地址。

此外,请确保您以--api启动了Automatic1111

  ./webui.sh --api # windows
  ./webui.bat --api # linux/mac

如果您想了解您有哪些模型,请调用模型端点并复制您选择的模型名称。

使用的插件

  • ControlNet使用cannyip2p
  • SD Upscaler后处理脚本

使用LLM驱动的提示增强

为了增强提示,我们使用LLM的本地图像。目前支持三种提示增强服务:

  • open_ai(ChatGPT)
  • basilicom(一个简单的LLM实现,请参阅Docker Hub
  • ollama(请参阅Github

限制

其他想法

  • 提示
    • 增强提示,特别是背景修复,例如:
      background = "a creepy forest at night"
      image_type = "a haunted castle background"
      characters = "medieval warriors"
      action = "fighting for the honor"
      prompt = f"{image_type} in {background} with {characters} {action}"
      
  • 在发送前在灯箱中生成提示?
  • 使用掩模对其他服务进行背景修复
  • 使用CLIP进行查询以优化变体提示
    • 允许img2img和CLIP的变体
  • 在背景修复中使用低去噪的IMG2IMG
  • LCM用于快速预览生成,>在提升之前进行midjourney-like/inpainting-like图像选择等。
  • 通过缩略图进行外部绘制
  • 更好的错误处理(如果超出信用额,则警告和回退)
  • ComfyUI + Nodes到Python作为固定预设
    • 允许带有预设的Docker镜像
  • InvokeAI

作者

Alexander Heidrich