my-sd/modules_forge/gradio_compile.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.0 KiB
Python
Raw Permalink Normal View History

2024-01-26 06:15:39 +00:00
def gradio_compile(items, prefix):
2024-01-26 06:57:14 +00:00
names = []
2024-01-26 06:16:54 +00:00
for k, v in items["required"].items():
2024-01-26 06:31:06 +00:00
t = v[0]
d = v[1] if len(v) > 1 else None
2024-01-26 06:54:51 +00:00
if prefix != '':
2024-01-26 06:57:41 +00:00
name = (prefix + '_' + k).replace(' ', '_').lower()
2024-01-26 06:55:46 +00:00
else:
name = k.replace(' ', '_').lower()
2024-01-26 06:57:14 +00:00
2024-01-26 06:37:22 +00:00
title = name.replace('_', ' ').title()
2024-01-26 06:31:06 +00:00
if t == 'INT':
default = int(d['default'])
min = int(d['min'])
max = int(d['max'])
step = int(d.get('step', 1))
print(f'{name} = gr.Slider(label=\'{title}\', minimum={min}, maximum={max}, step={step}, value={default})')
2024-01-26 07:00:35 +00:00
names.append(name)
2024-01-26 06:31:06 +00:00
elif t == 'FLOAT':
default = float(d['default'])
min = float(d['min'])
max = float(d['max'])
step = float(d.get('step', 0.001))
print(f'{name} = gr.Slider(label=\'{title}\', minimum={min}, maximum={max}, step={step}, value={default})')
2024-01-26 07:00:35 +00:00
names.append(name)
2024-01-26 06:34:29 +00:00
elif isinstance(t, list):
2024-01-26 06:35:10 +00:00
print(f'{name} = gr.Radio(label=\'{title}\', choices={str(t)}, value=\'{t[0]}\')')
2024-01-26 07:00:35 +00:00
names.append(name)
2024-01-26 06:34:29 +00:00
elif t == 'MODEL':
pass
elif t == 'CONDITIONING':
pass
elif t == 'LATENT':
pass
2024-01-26 06:52:42 +00:00
elif t == 'CLIP_VISION':
pass
elif t == 'IMAGE':
pass
elif t == 'VAE':
pass
2024-01-26 06:31:06 +00:00
else:
2024-01-26 06:31:43 +00:00
print('error ' + str(t))
2024-01-26 06:31:06 +00:00
2024-02-09 22:38:57 +00:00
return ['enabled'] + names
def print_info_text(name_list, prefix):
print(', '.join(name_list))
print('p.extra_generation_params.update(dict(')
for n in name_list:
print(prefix + '_' + n + ' = ' + n + ', ')
print(')')
return
2024-01-26 08:32:54 +00:00
# from modules_forge.gradio_compile import gradio_compile
# ps = []
# ps += gradio_compile(SVD_img2vid_Conditioning.INPUT_TYPES(), prefix='')
# ps += gradio_compile(KSampler.INPUT_TYPES(), prefix='sampling')
# ps += gradio_compile(VideoLinearCFGGuidance.INPUT_TYPES(), prefix='guidance')
# print(', '.join(ps))
2024-02-09 22:38:57 +00:00
# print_info_text(ps, '123')