Add --hide-ui-dir-config command line flag
Adds `--hide-ui-dir-config` flag to disable editing directory configs from the web UI. This can be set to prevent users from setting the directory to somewhere they shouldn't, for public (or semi-public) interfaces. Directories are still read from config.json, so the server admin can still set them in the web UI and then relaunch with the hide flag, or edit the config manually. Also: - fix OptionInfo `component_args` keyword argument not being read if `component` isn't also set - ensure that hidden settings aren't still read from the web UI (otherwise they could still be changed by tampering with the interface)
This commit is contained in:
parent
cacd14bee8
commit
29a2933e23
|
@ -42,6 +42,7 @@ parser.add_argument("--listen", action='store_true', help="launch gradio with 0.
|
||||||
parser.add_argument("--port", type=int, help="launch gradio with given server port, you need root/admin rights for ports < 1024, defaults to 7860 if available", default=None)
|
parser.add_argument("--port", type=int, help="launch gradio with given server port, you need root/admin rights for ports < 1024, defaults to 7860 if available", default=None)
|
||||||
parser.add_argument("--show-negative-prompt", action='store_true', help="does not do anything", default=False)
|
parser.add_argument("--show-negative-prompt", action='store_true', help="does not do anything", default=False)
|
||||||
parser.add_argument("--ui-config-file", type=str, help="filename to use for ui configuration", default=os.path.join(script_path, 'ui-config.json'))
|
parser.add_argument("--ui-config-file", type=str, help="filename to use for ui configuration", default=os.path.join(script_path, 'ui-config.json'))
|
||||||
|
parser.add_argument("--hide-ui-dir-config", action='store_true', help="hide directory configuration from webui", default=False)
|
||||||
|
|
||||||
cmd_opts = parser.parse_args()
|
cmd_opts = parser.parse_args()
|
||||||
|
|
||||||
|
@ -91,18 +92,19 @@ class Options:
|
||||||
self.component_args = component_args
|
self.component_args = component_args
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
|
hide_dirs = {"visible": False} if cmd_opts.hide_ui_dir_config else None
|
||||||
data_labels = {
|
data_labels = {
|
||||||
"outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below"),
|
"outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below", component_args=hide_dirs),
|
||||||
"outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images'),
|
"outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs),
|
||||||
"outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images'),
|
"outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs),
|
||||||
"outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab'),
|
"outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs),
|
||||||
"outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below"),
|
"outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs),
|
||||||
"outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids'),
|
"outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids', component_args=hide_dirs),
|
||||||
"outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids'),
|
"outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs),
|
||||||
"save_to_dirs": OptionInfo(False, "When writing images, create a directory with name derived from the prompt"),
|
"save_to_dirs": OptionInfo(False, "When writing images, create a directory with name derived from the prompt"),
|
||||||
"grid_save_to_dirs": OptionInfo(False, "When writing grids, create a directory with name derived from the prompt"),
|
"grid_save_to_dirs": OptionInfo(False, "When writing grids, create a directory with name derived from the prompt"),
|
||||||
"save_to_dirs_prompt_len": OptionInfo(10, "When using above, how many words from prompt to put into directory name", gr.Slider, {"minimum": 1, "maximum": 32, "step": 1}),
|
"save_to_dirs_prompt_len": OptionInfo(10, "When using above, how many words from prompt to put into directory name", gr.Slider, {"minimum": 1, "maximum": 32, "step": 1}),
|
||||||
"outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button"),
|
"outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs),
|
||||||
"samples_save": OptionInfo(True, "Save indiviual samples"),
|
"samples_save": OptionInfo(True, "Save indiviual samples"),
|
||||||
"samples_format": OptionInfo('png', 'File format for individual samples'),
|
"samples_format": OptionInfo('png', 'File format for individual samples'),
|
||||||
"grid_save": OptionInfo(True, "Save image grids"),
|
"grid_save": OptionInfo(True, "Save image grids"),
|
||||||
|
|
|
@ -661,19 +661,20 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
|
||||||
info = opts.data_labels[key]
|
info = opts.data_labels[key]
|
||||||
t = type(info.default)
|
t = type(info.default)
|
||||||
|
|
||||||
|
args = info.component_args() if callable(info.component_args) else info.component_args
|
||||||
|
|
||||||
if info.component is not None:
|
if info.component is not None:
|
||||||
args = info.component_args() if callable(info.component_args) else info.component_args
|
comp = info.component
|
||||||
item = info.component(label=info.label, value=fun, **(args or {}))
|
|
||||||
elif t == str:
|
elif t == str:
|
||||||
item = gr.Textbox(label=info.label, value=fun, lines=1)
|
comp = gr.Textbox
|
||||||
elif t == int:
|
elif t == int:
|
||||||
item = gr.Number(label=info.label, value=fun)
|
comp = gr.Number
|
||||||
elif t == bool:
|
elif t == bool:
|
||||||
item = gr.Checkbox(label=info.label, value=fun)
|
comp = gr.Checkbox
|
||||||
else:
|
else:
|
||||||
raise Exception(f'bad options item type: {str(t)} for key {key}')
|
raise Exception(f'bad options item type: {str(t)} for key {key}')
|
||||||
|
|
||||||
return item
|
return comp(label=info.label, value=fun, **(args or {}))
|
||||||
|
|
||||||
components = []
|
components = []
|
||||||
keys = list(opts.data_labels.keys())
|
keys = list(opts.data_labels.keys())
|
||||||
|
@ -684,6 +685,10 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
|
||||||
up = []
|
up = []
|
||||||
|
|
||||||
for key, value, comp in zip(opts.data_labels.keys(), args, components):
|
for key, value, comp in zip(opts.data_labels.keys(), args, components):
|
||||||
|
comp_args = opts.data_labels[key].component_args
|
||||||
|
if comp_args and isinstance(comp_args, dict) and comp_args.get('visible') is False:
|
||||||
|
continue
|
||||||
|
|
||||||
opts.data[key] = value
|
opts.data[key] = value
|
||||||
up.append(comp.update(value=value))
|
up.append(comp.update(value=value))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user