Compare commits

..

2 Commits

Author SHA1 Message Date
w-e-w 9bc3332d86 make process_boolean_tag case insensitive 2024-08-06 19:25:30 +09:00
w-e-w f8395750f4 add Usage Syntax to Prompts from file or textbox 2024-08-06 19:25:30 +09:00
4 changed files with 30 additions and 45 deletions
-1
View File
@@ -14,7 +14,6 @@ def imports():
import torch # noqa: F401
startup_timer.record("import torch")
from modules import patch_hf_hub_download # noqa: F401
import pytorch_lightning # noqa: F401
startup_timer.record("import torch")
warnings.filterwarnings(action="ignore", category=DeprecationWarning, module="pytorch_lightning")
-41
View File
@@ -1,41 +0,0 @@
from modules.patches import patch
from modules.errors import report
from inspect import signature
from functools import wraps
try:
from huggingface_hub.utils import LocalEntryNotFoundError
from huggingface_hub import file_download
def try_local_files_only(func):
if (param := signature(func).parameters.get('local_files_only', None)) and not param.kind == param.KEYWORD_ONLY:
raise ValueError(f'{func.__name__} does not have keyword-only parameter "local_files_only"')
@wraps(func)
def wrapper(*args, **kwargs):
try:
from modules.shared import opts
try_offline_mode = not kwargs.get('local_files_only') and opts.hd_dl_local_first
except Exception:
report('Error in try_local_files_only - skip try_local_files_only', exc_info=True)
try_offline_mode = False
if try_offline_mode:
try:
return func(*args, **{**kwargs, 'local_files_only': True})
except LocalEntryNotFoundError:
pass
except Exception:
report('Unexpected exception in try_local_files_only - retry without patch', exc_info=True)
return func(*args, **kwargs)
return wrapper
try:
patch(__name__, file_download, 'hf_hub_download', try_local_files_only(file_download.hf_hub_download))
except RuntimeError:
pass # already patched
except Exception:
report('Error patching hf_hub_download', exc_info=True)
-1
View File
@@ -128,7 +128,6 @@ options_templates.update(options_section(('system', "System", "system"), {
"disable_mmap_load_safetensors": OptionInfo(False, "Disable memmapping for loading .safetensors files.").info("fixes very slow loading speed in some cases"),
"hide_ldm_prints": OptionInfo(True, "Prevent Stability-AI's ldm/sgm modules from printing noise to console."),
"dump_stacks_on_signal": OptionInfo(False, "Print stack traces before exiting the program with ctrl+c."),
"hd_dl_local_first": OptionInfo(False, "Prevent connecting to huggingface for assets if cache is available").info('this will also prevent assets from being updated'),
}))
options_templates.update(options_section(('profiler', "Profiler", "system"), {
+30 -2
View File
@@ -11,25 +11,30 @@ from modules.shared import state
def process_model_tag(tag):
"""\"mode-name\""""
info = sd_models.get_closet_checkpoint_match(tag)
assert info is not None, f'Unknown checkpoint: {tag}'
return info.name
def process_string_tag(tag):
"""\"str\""""
return tag
def process_int_tag(tag):
"""int-number"""
return int(tag)
def process_float_tag(tag):
"""float-number"""
return float(tag)
def process_boolean_tag(tag):
return True if (tag == "true") else False
"""true|false"""
return True if (tag.lower() == "true") else False
prompt_tags = {
@@ -60,6 +65,27 @@ prompt_tags = {
}
def doc_md():
md = '<details><summary>Usage Syntax</summary><p>\n\n'
for key, func in prompt_tags.items():
md += f'`--{key}` `{func.__doc__}`\n'
md += '''
<details><summary>Example</summary><p>
```shell
--prompt "photo of sunset"
--prompt "photo of sunset" --negative_prompt "orange, pink, red, sea, water, lake" --width 1024 --height 768 --sampler_name "DPM++ 2M Karras" --steps 10 --batch_size 2 --cfg_scale 3 --seed 9
--prompt "photo of winter mountains" --steps 7 --sampler_name "DDIM"
--prompt "photo of winter mountains" --width 1024
```
</p></details>
'''
md += '</p></details>'
return md
def cmdargs(line):
args = shlex.split(line)
pos = 0
@@ -84,7 +110,6 @@ def cmdargs(line):
res[tag] = prompt
continue
func = prompt_tags.get(tag, None)
assert func, f'unknown commandline option: {arg}'
@@ -125,6 +150,9 @@ class Script(scripts.Script):
# We don't shrink back to 1, because that causes the control to ignore [enter], and it may
# be unclear to the user that shift-enter is needed.
prompt_txt.change(lambda tb: gr.update(lines=7) if ("\n" in tb) else gr.update(lines=2), inputs=[prompt_txt], outputs=[prompt_txt], show_progress=False)
gr.Markdown(doc_md())
return [checkbox_iterate, checkbox_iterate_batch, prompt_position, prompt_txt]
def run(self, p, checkbox_iterate, checkbox_iterate_batch, prompt_position, prompt_txt: str):