Merge pull request #56 from light-and-ray/main

improve webui extension
dev
SpenserCai 2024-03-20 14:54:58 +08:00 committed by GitHub
commit fad43553bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 32 deletions

View File

@ -66,11 +66,9 @@ In web-ui, go to the "Extensions" tab and use this URL https://github.com/Spense
If your network is not good, you can download the extension from [![Hugging Face Model](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Model-blue)](https://huggingface.co/spensercai/DeOldify)
## Usage
1.To completely exit webui, you need to add `--disable-safe-unpickle` at startup.
1. In web-ui, go to the "Extra" tab and select "DeOldify" checkbox.
2.In web-ui, go to the "Extra" tab and select "DeOldify" checkbox.
3.Upload the old photo you want to colorize.
2. Upload the old photo you want to colorize.
## Application Scenario
Combining Upscale, GFPGAN, and Denoldify for old photo restoration effects
@ -127,7 +125,7 @@ release/DeOldifyBot
- [x] Improve video processing speed
- [ ] Support repair options
- [ ] Support for simultaneous generation of images with different Render Factor values and Artistic on/off like “X/Y/Z Script” [#2](https://github.com/SpenserCai/sd-webui-deoldify/issues/2)
- [ ] Support need not to add `--disable-safe-unpickle` at startup [#5](https://github.com/SpenserCai/sd-webui-deoldify/issues/5)
- [x] Support need not to add `--disable-safe-unpickle` at startup [#5](https://github.com/SpenserCai/sd-webui-deoldify/issues/5)

View File

@ -7,7 +7,7 @@ LastEditTime: 2023-09-07 10:49:32
Description: file content
'''
# DeOldify UI & Processing
from modules import scripts_postprocessing, paths_internal
from modules import scripts_postprocessing, paths_internal, shared
from modules.ui_components import FormRow
from scripts.deoldify_base import *
import gradio as gr
@ -54,8 +54,18 @@ class ScriptPostprocessingUpscale(scripts_postprocessing.ScriptPostprocessing):
return outImg
def process(self, pp: scripts_postprocessing.PostprocessedImage, is_enabled, render_factor, artistic, pre_decolorization):
if not is_enabled or is_enabled is False:
if not is_enabled:
return
restoreList = []
try:
old_disable_safe_unpickle = shared.cmd_opts.disable_safe_unpickle
def restore():
shared.cmd_opts.disable_safe_unpickle = old_disable_safe_unpickle
restoreList.append(restore)
shared.cmd_opts.disable_safe_unpickle = True
pp.image = self.process_image(pp.image, render_factor, artistic, pre_decolorization)
pp.info["deoldify"] = f"render_factor={render_factor}, artistic={artistic}, pre_decolorization={pre_decolorization}"
pp.image = self.process_image(pp.image, render_factor, artistic, pre_decolorization)
pp.info["deoldify"] = f"render_factor={render_factor}, artistic={artistic}, pre_decolorization={pre_decolorization}"
finally:
for restore in restoreList:
restore()

View File

@ -6,7 +6,8 @@ LastEditors: SpenserCai
LastEditTime: 2023-09-07 10:21:59
Description: file content
'''
from modules import script_callbacks, paths_internal
from modules import script_callbacks, paths_internal, shared
from modules.call_queue import wrap_queued_call
from scripts.deoldify_base import *
import gradio as gr
import tempfile
@ -14,25 +15,40 @@ import os
import shutil
def process_image(video, render_factor,process=gr.Progress()):
wkfolder = Path(tempfile.gettempdir() + '/deoldify')
if not wkfolder.exists():
wkfolder.mkdir()
colorizer = get_stable_video_colorizer(root_folder=Path(paths_internal.models_path) ,workfolder=wkfolder)
video_name = os.path.basename(video)
process(0,"Copying video to temp folder...")
# 把video复制到临时文件夹
source_path = wkfolder/"source"
if not source_path.exists():
source_path.mkdir()
shutil.copy(video, source_path/video_name)
out_video = colorizer.colorize_from_file_name(video_name, render_factor=render_factor,g_process_bar=process)
# 删除wkfolder中除了result以外的目录
for dir in wkfolder.iterdir():
if dir.name != 'result':
shutil.rmtree(dir)
# 把out_video从Path对象转换为str
out_video = str(out_video)
return out_video
restoreList = []
try:
old_disable_safe_unpickle = shared.cmd_opts.disable_safe_unpickle
def restore():
shared.cmd_opts.disable_safe_unpickle = old_disable_safe_unpickle
restoreList.append(restore)
shared.cmd_opts.disable_safe_unpickle = True
wkfolder = Path(tempfile.gettempdir() + '/deoldify')
if not wkfolder.exists():
wkfolder.mkdir()
colorizer = get_stable_video_colorizer(root_folder=Path(paths_internal.models_path) ,workfolder=wkfolder)
video_name = os.path.basename(video)
process(0,"Copying video to temp folder...")
# 把video复制到临时文件夹
source_path = wkfolder/"source"
if not source_path.exists():
source_path.mkdir()
shutil.copy(video, source_path/video_name)
out_video = colorizer.colorize_from_file_name(video_name, render_factor=render_factor,g_process_bar=process)
# 删除wkfolder中除了result以外的目录
for dir in wkfolder.iterdir():
if dir.name != 'result':
shutil.rmtree(dir)
# 把out_video从Path对象转换为str
out_video = str(out_video)
colorizer.vis._clean_mem()
return out_video
finally:
for restore in restoreList:
restore()
isChineese = shared.opts.localization.lower().startswith('zh')
def deoldify_tab():
with gr.Blocks(analytics_enabled=False) as ui:
@ -40,14 +56,14 @@ def deoldify_tab():
with gr.Tab("Video"):
with gr.Row():
with gr.Column():
video_input = gr.Video(label="原视频")
video_input = gr.Video(label="原视频" if isChineese else "Original Video")
# 一个名为render_factor的滑块范围是1-50初始值是35步长是1
render_factor = gr.Slider(minimum=1, maximum=50, step=1, label="Render Factor")
render_factor.value = 35
with gr.Column():
video_output = gr.Video(label="修复后的视频",interactive=False)
video_output = gr.Video(label="修复后的视频" if isChineese else "Repaired video", interactive=False)
run_button = gr.Button(label="Run")
run_button.click(inputs=[video_input,render_factor],outputs=[video_output],fn=process_image)
run_button.click(inputs=[video_input,render_factor],outputs=[video_output],fn=wrap_queued_call(process_image))
return [(ui,"DeOldify","DeOldify")]