2022-10-24 03:31:41 +03:00
|
|
|
# This file is part of sygil-webui (https://github.com/Sygil-Dev/sygil-webui/).
|
2022-09-26 16:02:48 +03:00
|
|
|
|
2022-10-24 03:17:50 +03:00
|
|
|
# Copyright 2022 Sygil-Dev team.
|
2022-09-26 16:02:48 +03:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2022-08-30 13:37:16 +03:00
|
|
|
from os import path
|
2022-09-01 13:11:22 +03:00
|
|
|
import json
|
|
|
|
|
2022-08-29 12:13:34 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def readTextFile(*args):
|
2022-08-30 16:33:27 +03:00
|
|
|
dir = path.dirname(__file__)
|
|
|
|
entry = path.join(dir, *args)
|
2022-08-30 13:37:16 +03:00
|
|
|
with open(entry, "r", encoding="utf8") as f:
|
|
|
|
data = f.read()
|
|
|
|
return data
|
2022-08-29 17:05:28 +03:00
|
|
|
|
2022-09-01 13:11:22 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def css(opt):
|
|
|
|
styling = readTextFile("css", "styles.css")
|
|
|
|
if not opt.no_progressbar_hiding:
|
2022-09-01 16:18:17 +03:00
|
|
|
styling += readTextFile("css", "no_progress_bar.css")
|
2022-08-30 13:37:16 +03:00
|
|
|
return styling
|
2022-08-29 17:05:28 +03:00
|
|
|
|
2022-09-07 04:56:27 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def js(opt):
|
|
|
|
data = readTextFile("js", "index.js")
|
|
|
|
data = "(z) => {" + data + "; return z ?? [] }"
|
|
|
|
return data
|
2022-08-29 17:05:28 +03:00
|
|
|
|
2022-08-29 01:40:48 +03:00
|
|
|
|
2022-09-01 13:11:22 +03:00
|
|
|
# Wrap the typical SD method call into async closure for ease of use
|
|
|
|
# Supplies the js function with a params object
|
|
|
|
# That includes all the passed arguments and input from Gradio: x
|
2022-09-08 15:43:08 +03:00
|
|
|
# ATTENTION: x is an array of values of all components passed to your
|
|
|
|
# python event handler
|
2022-09-01 13:11:22 +03:00
|
|
|
# Example call in Gradio component's event handler (pass the result to _js arg):
|
|
|
|
# _js=call_JS("myJsMethod", arg1="string", arg2=100, arg3=[])
|
|
|
|
def call_JS(sd_method, **kwargs):
|
|
|
|
param_str = json.dumps(kwargs)
|
2022-09-08 15:43:08 +03:00
|
|
|
return f"async (...x) => {{ return await SD.{sd_method}({{ x, ...{param_str} }}) ?? []; }}"
|