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:
|
|
|
|
styling += readTextFile("css", "no_progress_bar.css")
|
|
|
|
return styling
|
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 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
|
|
|
|
# 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)
|
|
|
|
return f"async (x) => {{ return await SD.{sd_method}({{ x, ...{param_str} }}) ?? []; }}"
|