Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4861dccf7c | |||
| eed3b43252 |
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
|
||||||
from modules import localization, shared, scripts, util
|
from modules import localization, shared, scripts, util
|
||||||
@@ -49,12 +50,21 @@ def css_html():
|
|||||||
return head
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
re_preconnect = re.compile(rb'<link\s+rel="preconnect"\s+href="([^"]+)"(?:\s+[^>]*)?/?>')
|
||||||
|
|
||||||
|
|
||||||
def reload_javascript():
|
def reload_javascript():
|
||||||
js = javascript_html()
|
js = javascript_html()
|
||||||
css = css_html()
|
css = css_html()
|
||||||
|
|
||||||
def template_response(*args, **kwargs):
|
def template_response(*args, **kwargs):
|
||||||
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
|
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
|
||||||
|
|
||||||
|
# remove preconnects
|
||||||
|
res.body = re_preconnect.sub(b'', res.body)
|
||||||
|
# replace iframeResizer with local version
|
||||||
|
res.body = res.body.replace(b'src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.6/iframeResizer.contentWindow.min.js"', b'src="webui-assets/js/iframe-resizer/4.3.6/iframeResizer.contentWindow.min.js"')
|
||||||
|
|
||||||
res.body = res.body.replace(b'</head>', f'{js}<meta name="referrer" content="no-referrer"/></head>'.encode("utf8"))
|
res.body = res.body.replace(b'</head>', f'{js}<meta name="referrer" content="no-referrer"/></head>'.encode("utf8"))
|
||||||
res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
|
res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
|
||||||
res.init_headers()
|
res.init_headers()
|
||||||
|
|||||||
@@ -11,30 +11,25 @@ from modules.shared import state
|
|||||||
|
|
||||||
|
|
||||||
def process_model_tag(tag):
|
def process_model_tag(tag):
|
||||||
"""\"mode-name\""""
|
|
||||||
info = sd_models.get_closet_checkpoint_match(tag)
|
info = sd_models.get_closet_checkpoint_match(tag)
|
||||||
assert info is not None, f'Unknown checkpoint: {tag}'
|
assert info is not None, f'Unknown checkpoint: {tag}'
|
||||||
return info.name
|
return info.name
|
||||||
|
|
||||||
|
|
||||||
def process_string_tag(tag):
|
def process_string_tag(tag):
|
||||||
"""\"str\""""
|
|
||||||
return tag
|
return tag
|
||||||
|
|
||||||
|
|
||||||
def process_int_tag(tag):
|
def process_int_tag(tag):
|
||||||
"""int-number"""
|
|
||||||
return int(tag)
|
return int(tag)
|
||||||
|
|
||||||
|
|
||||||
def process_float_tag(tag):
|
def process_float_tag(tag):
|
||||||
"""float-number"""
|
|
||||||
return float(tag)
|
return float(tag)
|
||||||
|
|
||||||
|
|
||||||
def process_boolean_tag(tag):
|
def process_boolean_tag(tag):
|
||||||
"""true|false"""
|
return True if (tag == "true") else False
|
||||||
return True if (tag.lower() == "true") else False
|
|
||||||
|
|
||||||
|
|
||||||
prompt_tags = {
|
prompt_tags = {
|
||||||
@@ -65,27 +60,6 @@ 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):
|
def cmdargs(line):
|
||||||
args = shlex.split(line)
|
args = shlex.split(line)
|
||||||
pos = 0
|
pos = 0
|
||||||
@@ -110,6 +84,7 @@ def cmdargs(line):
|
|||||||
res[tag] = prompt
|
res[tag] = prompt
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
func = prompt_tags.get(tag, None)
|
func = prompt_tags.get(tag, None)
|
||||||
assert func, f'unknown commandline option: {arg}'
|
assert func, f'unknown commandline option: {arg}'
|
||||||
|
|
||||||
@@ -150,9 +125,6 @@ class Script(scripts.Script):
|
|||||||
# We don't shrink back to 1, because that causes the control to ignore [enter], and it may
|
# 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.
|
# 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)
|
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]
|
return [checkbox_iterate, checkbox_iterate_batch, prompt_position, prompt_txt]
|
||||||
|
|
||||||
def run(self, p, checkbox_iterate, checkbox_iterate_batch, prompt_position, prompt_txt: str):
|
def run(self, p, checkbox_iterate, checkbox_iterate_batch, prompt_position, prompt_txt: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user