Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: support flux.1 image2image and inpainting #2296

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ jobs:
${{ env.SELF_HOST_PYTHON }} -m pip install -U "loguru"
${{ env.SELF_HOST_PYTHON }} -m pip install -U "natsort"
${{ env.SELF_HOST_PYTHON }} -m pip install -U "loralib"
${{ env.SELF_HOST_PYTHON }} -m pip install -U "ormsgpack"
${{ env.SELF_HOST_PYTHON }} -m pip uninstall -y opencc
${{ env.SELF_HOST_PYTHON }} -m pip uninstall -y "faster_whisper"
${{ env.SELF_HOST_PYTHON }} -m pytest --timeout=1500 \
Expand Down
8 changes: 6 additions & 2 deletions xinference/model/image/model_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"model_id": "black-forest-labs/FLUX.1-schnell",
"model_revision": "768d12a373ed5cc9ef9a9dea7504dc09fcc14842",
"model_ability": [
"text2image"
"text2image",
"image2image",
"inpainting"
]
},
{
Expand All @@ -14,7 +16,9 @@
"model_id": "black-forest-labs/FLUX.1-dev",
"model_revision": "01aa605f2c300568dd6515476f04565a954fcb59",
"model_ability": [
"text2image"
"text2image",
"image2image",
"inpainting"
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions xinference/model/image/model_spec_modelscope.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"model_id": "AI-ModelScope/FLUX.1-schnell",
"model_revision": "master",
"model_ability": [
"text2image"
"text2image",
"image2image",
"inpainting"
]
},
{
Expand All @@ -16,7 +18,9 @@
"model_id": "AI-ModelScope/FLUX.1-dev",
"model_revision": "master",
"model_ability": [
"text2image"
"text2image",
"image2image",
"inpainting"
]
},
{
Expand Down
20 changes: 17 additions & 3 deletions xinference/model/image/stable_diffusion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import base64
import contextlib
import inspect
import logging
import os
import re
Expand Down Expand Up @@ -408,12 +409,24 @@ def image_to_image(
width, height = image.size
kwargs["width"] = width
kwargs["height"] = height

else:
# SD3 image2image cannot accept width and height
parameters = inspect.signature(model.__call__).parameters # type: ignore
allow_width_height = False
for param in parameters.values():
if param.kind == inspect.Parameter.VAR_KEYWORD:
allow_width_height = True
break
if "width" in parameters or "height" in parameters:
allow_width_height = True
if allow_width_height:
kwargs["width"], kwargs["height"] = image.size

kwargs["negative_prompt"] = negative_prompt
self._filter_kwargs(kwargs)
return self._call_model(
image=image,
prompt=prompt,
negative_prompt=negative_prompt,
num_images_per_prompt=n,
response_format=response_format,
model=model,
Expand Down Expand Up @@ -463,11 +476,12 @@ def inpainting(
# calculate actual image size after padding
width, height = image.size

kwargs["negative_prompt"] = negative_prompt
self._filter_kwargs(kwargs)
return self._call_model(
image=image,
mask_image=mask_image,
prompt=prompt,
negative_prompt=negative_prompt,
height=height,
width=width,
num_images_per_prompt=n,
Expand Down
Loading