my-sd/modules_forge/gradio_compile.py

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

25 lines
905 B
Python
Raw Normal View History

2024-01-26 06:15:39 +00:00
def gradio_compile(items, prefix):
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
name = (prefix + '_' + k).replace(' ', '_').lower()
title = name.replace('_', ' ').capitalize()
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})')
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})')
else:
2024-01-26 06:31:43 +00:00
print('error ' + str(t))
2024-01-26 06:31:06 +00:00
2024-01-26 06:15:39 +00:00
return