+
100
-

回答

可以用openai的最gpt-image-1或者google的gemini的api实现

我们以免费的gemini api为例来实现:

800_auto+800_auto

让左面美女的手中拿的盒子变成吹分机

800_auto

点击查看全文

from google import genai
from google.genai import types
from PIL import Image
from io import BytesIO
#
import PIL.Image


image1 = PIL.Image.open('prod2.png')
image2 = PIL.Image.open('prod3.png')
client = genai.Client(api_key="apikey")


text_input = ('更新图片:图片1中的人物手中拿的物品更换成图片2,并保持整体协调')


response = client.models.generate_content(
    model="gemini-2.0-flash-exp-image-generation",
    contents=[text_input, image1,image2],
    config=types.GenerateContentConfig(
      response_modalities=['TEXT', 'IMAGE']
    )
)


for part in response.candidates[0].content.parts:
  if part.text is not None:
    print(part.text)
  elif part.inline_data is not None:
    image = Image.open(BytesIO(part.inline_data.data))
    image.show()

网友回复

我知道答案,我要回答