Skip to content

Commit

Permalink
🚧 新增了局部重绘插件支持
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulinyv committed Jul 3, 2024
1 parent d158367 commit c9b419c
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 97 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

- 实现动态加载插件, 提高本项目可扩展性!

- 已提交到商店的插件: [插件列表](https://github.com/zhulinyv/Semi-Auto-NovelAI-to-Pixiv/blob/main/files/plugins.json)
- 已提交到商店的插件: [插件列表](https://github.com/zhulinyv/Semi-Auto-NovelAI-to-Pixiv/blob/main/files/webui/plugins.json)

> [!TIP]
> 我独自一人走在湿滑泥泞的街头, 身旁只有寥寥几盏路灯在暗夜中孤寂地闪烁。
Expand Down Expand Up @@ -193,7 +193,7 @@
+ [x] 插件列表读取远程仓库
+ [x] 插件更新与卸载
+ [x] 图片筛选添加复制操作
+ [ ] 整合包
+ [x] 整合包
+ [x] 新增打码方式
+ [x] 局部重绘优化蒙版上传
+ [ ] 涂鸦重绘
Expand Down
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Learning Gradio, trying to create a WebUI for this project.

- Implementation of dynamically loading plugins to enhance the project's scalability!

- Plugins submitted to the store: [Plugin List](https://github.com/zhulinyv/Semi-Auto-NovelAI-to-Pixiv/blob/main/files/plugins.json)
- Plugins submitted to the store: [Plugin List](https://github.com/zhulinyv/Semi-Auto-NovelAI-to-Pixiv/blob/main/webui/files/plugins.json)

> [!TIP]
> I walked alone on the slippery and muddy streets, with only a few street lamps blinking lonely in the dark night.
Expand Down Expand Up @@ -193,7 +193,7 @@ Learning Gradio, trying to create a WebUI for this project.
+ [x] The list of plugins reads the remote repository
+ [x] Plugin updates and uninstallations
+ [x] Add copy operations for image filtering
+ [ ] Modpacks
+ [x] Modpacks
+ [x] New mosaic
+ [x] Partial redraw to optimize mask upload
+ [ ] Graffiti repaint
Expand Down
185 changes: 98 additions & 87 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,101 +696,112 @@ def open_output_folder_block(output_folder):
logger.error(f"插件: {plugin_name} 没有 plugin 函数!")
# ---------- 局部重绘 ---------- #
with gr.Tab(webui_language["inpaint"]["tab"]):
with gr.Row():
with gr.Column(scale=8):
gr.Markdown(webui_language["inpaint"]["description"])
open_output_folder_block("inpaint")
with gr.Column():
with gr.Column():
inpaint_positive_input = gr.Textbox(
value=webui_language["example"]["positive"],
lines=2,
label=webui_language["t2i"]["positive"],
)
with gr.Row():
inpaint_negative_input = gr.Textbox(
value=webui_language["example"]["negative"],
lines=3,
label=webui_language["t2i"]["negative"],
scale=3,
)
inpaint_generate_button = gr.Button(value=webui_language["t2i"]["generate_button"], scale=1)
with gr.Tab(webui_language["inpaint"]["tab"]):
with gr.Row():
inpaint_input_path = gr.Textbox(value="", label=webui_language["inpaint"]["input_path"], scale=5)
inpaint_mask_path = gr.Textbox(value="", label=webui_language["inpaint"]["mask_path"], scale=5)
inpaint_batch_switch = gr.Radio(
[True, False], value=False, label=webui_language["i2i"]["open_button"], scale=1
)
with gr.Row():
inpaint_input_image = gr.Sketchpad(
sources=["upload", "clipboard", "webcam"],
type="pil",
label=webui_language["inpaint"]["inpaint_img"],
)
with gr.Column():
inpaint_output_information = gr.Textbox(label=webui_language["i2i"]["output_info"])
inpaint_output_image = gr.Image()
with gr.Column(scale=8):
gr.Markdown(webui_language["inpaint"]["description"])
open_output_folder_block("inpaint")
with gr.Column():
with gr.Row():
inpaint_resolution = gr.Dropdown(
RESOLUTION,
value="832x1216",
label=webui_language["t2i"]["resolution"],
)
inpaint_sampler = gr.Dropdown(
SAMPLER,
value="k_euler",
label=webui_language["t2i"]["sampler"],
)
inpaint_noise_schedule = gr.Dropdown(
NOISE_SCHEDULE,
value="native",
label=webui_language["t2i"]["noise_schedule"],
with gr.Column():
inpaint_positive_input = gr.Textbox(
value=webui_language["example"]["positive"],
lines=2,
label=webui_language["t2i"]["positive"],
)
with gr.Row():
inpaint_negative_input = gr.Textbox(
value=webui_language["example"]["negative"],
lines=3,
label=webui_language["t2i"]["negative"],
scale=3,
)
inpaint_generate_button = gr.Button(value=webui_language["t2i"]["generate_button"], scale=1)
with gr.Row():
inpaint_strength = gr.Slider(
minimum=0, maximum=1, value=0.5, step=0.1, label=webui_language["i2i"]["strength"]
)
inpaint_noise = gr.Slider(
minimum=0, maximum=1, value=0, step=0.1, label=webui_language["i2i"]["noise"]
inpaint_input_path = gr.Textbox(
value="", label=webui_language["inpaint"]["input_path"], scale=5
)
inpaint_scale = gr.Slider(
minimum=0, maximum=10, value=5, step=0.1, label=webui_language["t2i"]["scale"]
)
inpaint_steps = gr.Slider(
minimum=0, maximum=50, value=28, step=1, label=webui_language["t2i"]["steps"]
inpaint_mask_path = gr.Textbox(value="", label=webui_language["inpaint"]["mask_path"], scale=5)
inpaint_batch_switch = gr.Radio(
[True, False], value=False, label=webui_language["i2i"]["open_button"], scale=1
)
with gr.Row():
inpaint_sm = gr.Radio([True, False], value=False, label="sm", scale=2)
inpaint_sm_dyn = gr.Radio(
[True, False], value=False, label=webui_language["t2i"]["smdyn"], scale=2
inpaint_input_image = gr.Sketchpad(
sources=["upload", "clipboard", "webcam"],
type="pil",
label=webui_language["inpaint"]["inpaint_img"],
)
with gr.Column(scale=1):
inpaint_seed = gr.Textbox(value="-1", label=webui_language["t2i"]["seed"], scale=7)
inpaint_random_button = gr.Button(value="♻️", size="sm", scale=1)
inpaint_random_button.click(return_random, inputs=None, outputs=inpaint_seed)
inpaint_generate_button.click(
fn=inpaint,
inputs=[
inpaint_input_path,
inpaint_mask_path,
inpaint_input_image,
inpaint_batch_switch,
inpaint_positive_input,
inpaint_negative_input,
inpaint_resolution,
inpaint_sampler,
inpaint_noise_schedule,
inpaint_strength,
inpaint_noise,
inpaint_scale,
inpaint_steps,
inpaint_sm,
inpaint_sm_dyn,
inpaint_seed,
],
outputs=[inpaint_output_image, inpaint_output_information],
)
with gr.Column():
inpaint_output_information = gr.Textbox(label=webui_language["i2i"]["output_info"])
inpaint_output_image = gr.Image()
with gr.Column():
with gr.Row():
inpaint_resolution = gr.Dropdown(
RESOLUTION,
value="832x1216",
label=webui_language["t2i"]["resolution"],
)
inpaint_sampler = gr.Dropdown(
SAMPLER,
value="k_euler",
label=webui_language["t2i"]["sampler"],
)
inpaint_noise_schedule = gr.Dropdown(
NOISE_SCHEDULE,
value="native",
label=webui_language["t2i"]["noise_schedule"],
)
with gr.Row():
inpaint_strength = gr.Slider(
minimum=0, maximum=1, value=0.5, step=0.1, label=webui_language["i2i"]["strength"]
)
inpaint_noise = gr.Slider(
minimum=0, maximum=1, value=0, step=0.1, label=webui_language["i2i"]["noise"]
)
inpaint_scale = gr.Slider(
minimum=0, maximum=10, value=5, step=0.1, label=webui_language["t2i"]["scale"]
)
inpaint_steps = gr.Slider(
minimum=0, maximum=50, value=28, step=1, label=webui_language["t2i"]["steps"]
)
with gr.Row():
inpaint_sm = gr.Radio([True, False], value=False, label="sm", scale=2)
inpaint_sm_dyn = gr.Radio(
[True, False], value=False, label=webui_language["t2i"]["smdyn"], scale=2
)
with gr.Column(scale=1):
inpaint_seed = gr.Textbox(value="-1", label=webui_language["t2i"]["seed"], scale=7)
inpaint_random_button = gr.Button(value="♻️", size="sm", scale=1)
inpaint_random_button.click(return_random, inputs=None, outputs=inpaint_seed)
inpaint_generate_button.click(
fn=inpaint,
inputs=[
inpaint_input_path,
inpaint_mask_path,
inpaint_input_image,
inpaint_batch_switch,
inpaint_positive_input,
inpaint_negative_input,
inpaint_resolution,
inpaint_sampler,
inpaint_noise_schedule,
inpaint_strength,
inpaint_noise,
inpaint_scale,
inpaint_steps,
inpaint_sm,
inpaint_sm_dyn,
inpaint_seed,
],
outputs=[inpaint_output_image, inpaint_output_information],
)
# ---------- Inpaint插件 ---------- #
inpaint_plugins = load_plugins(Path("./plugins/inpaint"))
for plugin_name, plugin_module in inpaint_plugins.items():
if hasattr(plugin_module, "plugin"):
plugin_module.plugin()
logger.success(f"成功加载插件: {plugin_name}")
else:
logger.error(f"插件: {plugin_name} 没有 plugin 函数!")
# ---------- 超分降噪 ---------- #
with gr.Tab(webui_language["super resolution"]["tab"]):
with gr.Row():
Expand Down
3 changes: 0 additions & 3 deletions src/image2image.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ def i2i_by_hand(
json_for_i2i["parameters"]["extra_noise_seed"] = seed
json_for_i2i["parameters"]["negative_prompt"] = negative

with open("test.txt", "w", encoding="utf-8") as f:
f.write(json.dumps(json_for_i2i))

saved_path = save_image(generate_image(json_for_i2i), "i2i", seed, "None", "None")
sleep_for_cool(2, 4)

Expand Down
7 changes: 6 additions & 1 deletion utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import shutil

import requests
from git import Git

try:
from git import Git
except Exception:
os.environ["PATH"] = os.path.abspath("./Git24521/bin")
from git import Git

from utils.update import update
from utils.utils import file_path2list, proxies, read_json
Expand Down
13 changes: 12 additions & 1 deletion utils/prepare.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import os
import shutil
from urllib.request import getproxies

from loguru import logger

VERSION = "2.18.5"
try:
proxies = getproxies()
os.environ["http_proxy"] = proxies["http"]
os.environ["https_proxy"] = proxies["https"]
os.environ["no_proxy"] = proxies.get("no", "localhost, 127.0.0.1, ::1")
except KeyError:
pass


VERSION = "2.19.0"

need_dir_list = [
"./output",
Expand All @@ -26,6 +36,7 @@
"./plugins/t2i",
"./plugins/i2i",
"./plugins/webui",
"./plugins/inpaint",
]


Expand Down
8 changes: 7 additions & 1 deletion utils/update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
from pathlib import Path

import git
try:
import git
except Exception:
os.environ["PATH"] = os.path.abspath("./Git24521/bin")
import git

import requests
from git.exc import InvalidGitRepositoryError

Expand Down

0 comments on commit c9b419c

Please sign in to comment.