2023-01-01 13:08:40 +03:00
|
|
|
import gradio as gr
|
|
|
|
|
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
class FormComponent:
|
|
|
|
def get_expected_parent(self):
|
|
|
|
return gr.components.Form
|
2023-01-01 13:08:40 +03:00
|
|
|
|
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
gr.Dropdown.get_expected_parent = FormComponent.get_expected_parent
|
2023-01-01 13:08:40 +03:00
|
|
|
|
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
class ToolButton(FormComponent, gr.Button):
|
|
|
|
"""Small button with single emoji as text, fits inside gradio forms"""
|
2023-01-21 08:36:07 +03:00
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
classes = kwargs.pop("elem_classes", [])
|
|
|
|
super().__init__(*args, elem_classes=["tool", *classes], **kwargs)
|
2023-01-21 08:36:07 +03:00
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "button"
|
|
|
|
|
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
class FormRow(FormComponent, gr.Row):
|
2023-01-01 13:08:40 +03:00
|
|
|
"""Same as gr.Row but fits inside gradio forms"""
|
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "row"
|
2023-01-03 09:04:29 +03:00
|
|
|
|
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
class FormColumn(FormComponent, gr.Column):
|
|
|
|
"""Same as gr.Column but fits inside gradio forms"""
|
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "column"
|
|
|
|
|
|
|
|
|
|
|
|
class FormGroup(FormComponent, gr.Group):
|
2023-08-04 07:50:17 +03:00
|
|
|
"""Same as gr.Group but fits inside gradio forms"""
|
2023-01-03 09:04:29 +03:00
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "group"
|
2023-01-07 09:56:37 +03:00
|
|
|
|
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
class FormHTML(FormComponent, gr.HTML):
|
2023-01-07 09:56:37 +03:00
|
|
|
"""Same as gr.HTML but fits inside gradio forms"""
|
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "html"
|
|
|
|
|
2023-01-10 23:47:02 +03:00
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
class FormColorPicker(FormComponent, gr.ColorPicker):
|
2023-01-10 23:47:02 +03:00
|
|
|
"""Same as gr.ColorPicker but fits inside gradio forms"""
|
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "colorpicker"
|
2023-01-22 15:38:39 +03:00
|
|
|
|
2023-01-26 23:29:27 +03:00
|
|
|
|
2023-03-20 16:09:36 +03:00
|
|
|
class DropdownMulti(FormComponent, gr.Dropdown):
|
2023-01-26 23:29:27 +03:00
|
|
|
"""Same as gr.Dropdown but always multiselect"""
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(multiselect=True, **kwargs)
|
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "dropdown"
|
2023-04-29 12:52:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
class DropdownEditable(FormComponent, gr.Dropdown):
|
|
|
|
"""Same as gr.Dropdown but allows editing value"""
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(allow_custom_value=True, **kwargs)
|
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "dropdown"
|
|
|
|
|