Skip to content

Commit

Permalink
img2img fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hlky committed Sep 7, 2022
1 parent bf08b61 commit e66eddc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ condaenv.*.requirements.txt
/custom-conda-path.txt
/src/*
/outputs/*
/models/*
/log/**/*.png
/log/log.csv
/flagged/*
10 changes: 5 additions & 5 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ dependencies:
- facexlib>=0.2.3
- python-slugify>=6.1.2
- streamlit>=1.12.2
- taming-transformers>=0.0.1
- openai-clip>=1.0.1
- gfpgan>=1.3.5
- realesrgan>=0.2.5.0
- -e git+https://github.com/CompVis/taming-transformers#egg=taming-transformers
- -e git+https://github.com/openai/CLIP#egg=clip
- -e git+https://github.com/TencentARC/GFPGAN#egg=GFPGAN
- -e git+https://github.com/xinntao/Real-ESRGAN#egg=realesrgan
- -e git+https://github.com/hlky/k-diffusion-sd#egg=k_diffusion
- -e .
- -e .
24 changes: 12 additions & 12 deletions frontend/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
with gr.Tabs():
with gr.TabItem("Img2Img Input"):
#gr.Markdown('#### Img2Img Input')
img2img_image_editor = gr.Image(value=sample_img2img, source="upload", interactive=True,
img2img_image_mask = gr.Image(value=sample_img2img, source="upload", interactive=False,
type="pil", tool="select", elem_id="img2img_editor",
image_mode="RGBA")
img2img_image_mask = gr.Image(value=sample_img2img, source="upload", interactive=True,
type="pil", tool="sketch", visible=False,
image_mode="RGBA", visible=False)
img2img_image_editor = gr.Image(value=sample_img2img, source="upload", interactive=True,
type="pil", tool="sketch", visible=True,
elem_id="img2img_mask")

with gr.TabItem("Img2Img Mask Input"):
Expand All @@ -176,10 +176,10 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
with gr.TabItem("Editor Options"):
with gr.Row():
img2img_image_editor_mode = gr.Radio(choices=["Mask", "Crop", "Uncrop"], label="Image Editor Mode",
value="Crop", elem_id='edit_mode_select')
img2img_mask = gr.Radio(choices=["Keep masked area", "Regenerate only masked area", "Resize and regenerate only masked area"],
value="Mask", elem_id='edit_mode_select', visible=False)
img2img_mask = gr.Radio(choices=["Keep masked area", "Regenerate only masked area"],
label="Mask Mode", type="index",
value=img2img_mask_modes[img2img_defaults['mask_mode']], visible=False)
value=img2img_mask_modes[img2img_defaults['mask_mode']], visible=True)

img2img_mask_blur_strength = gr.Slider(minimum=1, maximum=10, step=1,
label="How much blurry should the mask be? (to avoid hard edges)",
Expand All @@ -188,7 +188,7 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
img2img_resize = gr.Radio(label="Resize mode",
choices=["Just resize", "Crop and resize", "Resize and fill"],
type="index",
value=img2img_resize_modes[img2img_defaults['resize_mode']])
value=img2img_resize_modes[img2img_defaults['resize_mode']], visible=False)

img2img_painterro_btn = gr.Button("Advanced Editor")
with gr.TabItem("Hints"):
Expand Down Expand Up @@ -323,16 +323,16 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda

def generate(*args):
args_list = list(args)
init_info_mask = args_list[3]
init_info_mask = args_list[2]
# Get the mask input and remove it from the list
mask_input = args_list[18]
del args_list[18]
mask_input = args_list[-1]
del args_list[-1]

# If an external mask is set, use it
if mask_input:
init_info_mask['mask'] = mask_input

args_list[3] = init_info_mask
args_list[2] = init_info_mask

# Return the result of img2img
return img2img_func(*args_list)
Expand Down
2 changes: 1 addition & 1 deletion frontend/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def _call_func(self, func_key: FuncKey, session_key: str) -> List[Component]:
return []

try:
outputs = job_info.func(*job_info.inputs, job_info=job_info)
outputs = job_info.func(*job_info.inputs)
except Exception as e:
job_info.job_status = f"Error: {e}"
print(f"Exception processing job {job_info}: {e}\n{traceback.format_exc()}")
Expand Down
6 changes: 3 additions & 3 deletions scripts/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,11 +1442,11 @@ def img2img(prompt: str, image_editor_mode: str, init_info: any, init_info_mask:

if image_editor_mode == 'Mask':
global returned_info
init_img = init_info_mask["image"]
init_img = init_info["image"]
init_img = init_img.convert("RGB")
init_img = resize_image(resize_mode, init_img, width, height)
image = image.convert("RGB")
init_mask = init_info_mask["mask"]
init_img = init_img.convert("RGB")
init_mask = init_info["mask"]
init_mask = resize_image(resize_mode, init_mask, width, height)
resize_mask = mask_mode == 2

Expand Down
1 change: 0 additions & 1 deletion webui.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ IF "%CONDA_PATH%"=="" (
:foundPath
call "%CONDA_PATH%\Scripts\activate.bat"
call conda env create -n "%conda_env_name%" -f environment.yaml
call conda env update -n "%conda_env_name%" --file environment.yaml --prune
call "%CONDA_PATH%\Scripts\activate.bat" "%conda_env_name%"
python "%CD%"\scripts\relauncher.py

Expand Down

0 comments on commit e66eddc

Please sign in to comment.