Compare commits

..

2 Commits

Author SHA1 Message Date
w-e-w 60efbc4618 API /sdapi/v1/server-reload-script-bodies 2024-12-24 08:23:47 +09:00
w-e-w a56190cdb1 API /sdapi/v1/server-reload-ui 2024-12-24 08:23:47 +09:00
10 changed files with 32 additions and 88 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
- name: Install Ruff
run: pip install ruff==0.3.3
- name: Run Ruff
run: ruff check .
run: ruff .
lint-js:
name: eslint
runs-on: ubuntu-latest
-36
View File
@@ -69,39 +69,3 @@ onOptionsChanged(function() {
});
});
function downloadSysinfo() {
const pad = (n) => String(n).padStart(2, '0');
const now = new Date();
const YY = now.getFullYear();
const MM = pad(now.getMonth() + 1);
const DD = pad(now.getDate());
const HH = pad(now.getHours());
const mm = pad(now.getMinutes());
const link = document.createElement('a');
link.download = `sysinfo-${YY}-${MM}-${DD}-${HH}-${mm}.json`;
const sysinfo_textbox = gradioApp().querySelector('#internal-sysinfo-textbox textarea');
const content = sysinfo_textbox.value;
if (content.startsWith('file=')) {
link.href = content;
} else {
const blob = new Blob([content], {type: 'application/json'});
link.href = URL.createObjectURL(blob);
}
link.click();
sysinfo_textbox.value = '';
updateInput(sysinfo_textbox);
}
function openTabSysinfo() {
const sysinfo_textbox = gradioApp().querySelector('#internal-sysinfo-textbox textarea');
const content = sysinfo_textbox.value;
if (content.startsWith('file=')) {
window.open(content, '_blank');
} else {
const blob = new Blob([content], {type: 'application/json'});
const url = URL.createObjectURL(blob);
window.open(url, '_blank');
}
sysinfo_textbox.value = '';
updateInput(sysinfo_textbox);
}
+10 -4
View File
@@ -17,7 +17,7 @@ from fastapi.encoders import jsonable_encoder
from secrets import compare_digest
import modules.shared as shared
from modules import sd_samplers, deepbooru, sd_hijack, images, scripts, ui, postprocessing, errors, restart, shared_items, script_callbacks, infotext_utils, sd_models, sd_schedulers, sysinfo
from modules import sd_samplers, deepbooru, sd_hijack, images, scripts, ui, postprocessing, errors, restart, shared_items, script_callbacks, infotext_utils, sd_models, sd_schedulers
from modules.api import models
from modules.shared import opts
from modules.processing import StableDiffusionProcessingTxt2Img, StableDiffusionProcessingImg2Img, process_images
@@ -33,7 +33,6 @@ import piexif.helper
from contextlib import closing
from modules.progress import create_task_id, add_task_to_queue, start_task, finish_task, current_task
def script_name_to_index(name, scripts):
try:
return [script.title().lower() for script in scripts].index(name.lower())
@@ -245,13 +244,13 @@ class Api:
self.add_api_route("/sdapi/v1/scripts", self.get_scripts_list, methods=["GET"], response_model=models.ScriptsList)
self.add_api_route("/sdapi/v1/script-info", self.get_script_info, methods=["GET"], response_model=list[models.ScriptInfo])
self.add_api_route("/sdapi/v1/extensions", self.get_extensions_list, methods=["GET"], response_model=list[models.ExtensionItem])
self.add_api_route("/internal/sysinfo", sysinfo.download_sysinfo, methods=["GET"])
self.add_api_route("/internal/sysinfo-download", lambda: sysinfo.download_sysinfo(attachment=True), methods=["GET"])
if shared.cmd_opts.api_server_stop:
self.add_api_route("/sdapi/v1/server-kill", self.kill_webui, methods=["POST"])
self.add_api_route("/sdapi/v1/server-restart", self.restart_webui, methods=["POST"])
self.add_api_route("/sdapi/v1/server-stop", self.stop_webui, methods=["POST"])
self.add_api_route("/sdapi/v1/server-reload-ui", self.reload_webui, methods=["POST"])
self.add_api_route("/sdapi/v1/server-reload-script-bodies", self.reload_script_bodies, methods=["POST"])
self.default_script_arg_txt2img = []
self.default_script_arg_img2img = []
@@ -929,3 +928,10 @@ class Api:
shared.state.server_command = "stop"
return Response("Stopping.")
def reload_webui(self):
shared.state.request_restart()
return Response("Reloading.")
def reload_script_bodies(self):
scripts.reload_script_body_only()
return Response("Reload script bodies.")
+3 -1
View File
@@ -43,7 +43,9 @@ def check_python_version():
supported_minors = [7, 8, 9, 10, 11]
if not (major == 3 and minor in supported_minors):
errors.print_error_explanation(f"""
import modules.errors
modules.errors.print_error_explanation(f"""
INCOMPATIBLE PYTHON VERSION
This program is tested with 3.10.6 Python, but you have {major}.{minor}.{micro}.
+1 -1
View File
@@ -125,7 +125,7 @@ def ui_reorder_categories():
def callbacks_order_settings():
options = {
"callbacks_order_explanation": OptionHTML("""
"sd_vae_explanation": OptionHTML("""
For categories below, callbacks added to dropdowns happen before others, in order listed.
"""),
-10
View File
@@ -213,13 +213,3 @@ def get_config():
return json.load(f)
except Exception as e:
return str(e)
def download_sysinfo(attachment=False):
from fastapi.responses import PlainTextResponse
from datetime import datetime
text = get()
filename = f"sysinfo-{datetime.utcnow().strftime('%Y-%m-%d-%H-%M')}.json"
return PlainTextResponse(text, headers={'Content-Disposition': f'{"attachment" if attachment else "inline"}; filename="{filename}"'})
+14 -2
View File
@@ -1,3 +1,4 @@
import datetime
import mimetypes
import os
import sys
@@ -9,10 +10,10 @@ import gradio as gr
import gradio.utils
import numpy as np
from PIL import Image, PngImagePlugin # noqa: F401
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call, wrap_gradio_call_no_job # noqa: F401
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call, wrap_gradio_call_no_job # noqa: F401
from modules import gradio_extensons, sd_schedulers # noqa: F401
from modules import sd_hijack, sd_models, script_callbacks, ui_extensions, deepbooru, extra_networks, ui_common, ui_postprocessing, progress, ui_loadsave, shared_items, ui_settings, timer, ui_checkpoint_merger, scripts, sd_samplers, processing, ui_extra_networks, ui_toprow, launch_utils
from modules import sd_hijack, sd_models, script_callbacks, ui_extensions, deepbooru, extra_networks, ui_common, ui_postprocessing, progress, ui_loadsave, shared_items, ui_settings, timer, sysinfo, ui_checkpoint_merger, scripts, sd_samplers, processing, ui_extra_networks, ui_toprow, launch_utils
from modules.ui_components import FormRow, FormGroup, ToolButton, FormHTML, InputAccordion, ResizeHandleRow
from modules.paths import script_path
from modules.ui_common import create_refresh_button
@@ -1222,5 +1223,16 @@ def setup_ui_api(app):
app.add_api_route("/internal/profile-startup", lambda: timer.startup_record, methods=["GET"])
def download_sysinfo(attachment=False):
from fastapi.responses import PlainTextResponse
text = sysinfo.get()
filename = f"sysinfo-{datetime.datetime.utcnow().strftime('%Y-%m-%d-%H-%M')}.json"
return PlainTextResponse(text, headers={'Content-Disposition': f'{"attachment" if attachment else "inline"}; filename="{filename}"'})
app.add_api_route("/internal/sysinfo", download_sysinfo, methods=["GET"])
app.add_api_route("/internal/sysinfo-download", lambda: download_sysinfo(attachment=True), methods=["GET"])
import fastapi.staticfiles
app.mount("/webui-assets", fastapi.staticfiles.StaticFiles(directory=launch_utils.repo_dir('stable-diffusion-webui-assets')), name="webui-assets")
+3 -25
View File
@@ -1,13 +1,12 @@
import gradio as gr
from modules import ui_common, shared, script_callbacks, scripts, sd_models, sysinfo, timer, shared_items, paths_internal, util
from modules import ui_common, shared, script_callbacks, scripts, sd_models, sysinfo, timer, shared_items
from modules.call_queue import wrap_gradio_call_no_job
from modules.options import options_section
from modules.shared import opts
from modules.ui_components import FormRow
from modules.ui_gradio_extensions import reload_javascript
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path
def get_value_for_setting(key):
@@ -171,28 +170,7 @@ class UiSettings:
loadsave.create_ui()
with gr.TabItem("Sysinfo", id="sysinfo", elem_id="settings_tab_sysinfo"):
download_sysinfo = gr.Button(value='Download system info', elem_id="internal-download-sysinfo", visible=False)
open_sysinfo = gr.Button(value='Open as text in a new page', elem_id="internal-open-sysinfo", visible=False)
sysinfo_html = gr.HTML('''<a class="sysinfo_big_link" onclick="gradioApp().getElementById('internal-download-sysinfo').click();">Download system info</a><br/><a onclick="gradioApp().getElementById('internal-open-sysinfo').click();">(or open as text in a new page)</a>''', elem_id="sysinfo_download")
sysinfo_textbox = gr.Textbox(label='Sysinfo textarea', elem_id="internal-sysinfo-textbox", visible=False)
def create_sysinfo():
sysinfo_str = sysinfo.get()
if len(sysinfo_utf8 := sysinfo_str.encode('utf8')) > 2 ** 20: # 1MB
sysinfo_path = Path(paths_internal.script_path) / 'tmp' / 'sysinfo.json'
sysinfo_path.parent.mkdir(parents=True, exist_ok=True)
sysinfo_path.write_bytes(sysinfo_utf8)
return gr.update(), gr.update(value=f'file={util.truncate_path(sysinfo_path)}')
return gr.update(), gr.update(value=sysinfo_str)
download_sysinfo.click(
fn=create_sysinfo, outputs=[sysinfo_html, sysinfo_textbox], show_progress=True).success(
fn=None, _js='downloadSysinfo'
)
open_sysinfo.click(
fn=create_sysinfo, outputs=[sysinfo_html, sysinfo_textbox], show_progress=True).success(
fn=None, _js='openTabSysinfo'
)
gr.HTML('<a href="./internal/sysinfo-download" class="sysinfo_big_link" download>Download system info</a><br /><a href="./internal/sysinfo" target="_blank">(or open as text in a new page)</a>', elem_id="sysinfo_download")
with gr.Row():
with gr.Column(scale=1):
@@ -335,7 +313,7 @@ class UiSettings:
for method in methods:
method(
fn=lambda value, key=k: self.run_settings_single(value, key=key),
fn=lambda value, k=k: self.run_settings_single(value, key=k),
inputs=[component],
outputs=[component, self.text_settings],
show_progress=info.refresh is not None,
-4
View File
@@ -29,10 +29,6 @@ class ScriptPostprocessingCodeFormer(scripts_postprocessing.ScriptPostprocessing
res = Image.fromarray(restored_img)
if codeformer_visibility < 1.0:
if pp.image.size != res.size:
res = res.resize(pp.image.size)
if pp.image.mode != res.mode:
res = res.convert(pp.image.mode)
res = Image.blend(pp.image, res, codeformer_visibility)
pp.image = res
-4
View File
@@ -26,10 +26,6 @@ class ScriptPostprocessingGfpGan(scripts_postprocessing.ScriptPostprocessing):
res = Image.fromarray(restored_img)
if gfpgan_visibility < 1.0:
if pp.image.size != res.size:
res = res.resize(pp.image.size)
if pp.image.mode != res.mode:
res = res.convert(pp.image.mode)
res = Image.blend(pp.image, res, gfpgan_visibility)
pp.image = res