Spaces:
Running
Running
File size: 5,469 Bytes
f51c1fd 78f883e f51c1fd bb45169 f51c1fd a26705a f51c1fd a26705a f51c1fd 13aeb09 f51c1fd 13aeb09 f51c1fd b322173 f51c1fd b0f25b3 545ba4b f51c1fd 9d1152f f51c1fd b0f25b3 545ba4b f51c1fd 24ee878 42c4f80 f51c1fd 42c4f80 24ee878 42c4f80 f51c1fd d0f716d aa2aec1 0e30f40 aa2aec1 c0f084a aa2aec1 78f883e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
"""
File: components.py
Author: Elena Ryumina and Dmitry Ryumin
Description: Utility functions for creating Gradio components.
License: MIT License
"""
import gradio as gr
from typing import Union, List, Callable, Optional, Literal
# Importing necessary components for the Gradio app
from app.config import config_data
def html_message(
message: str = "",
error: bool = True,
visible: bool = True,
elem_classes: Optional[str] = "html-container",
) -> gr.HTML:
css_class = "noti_err" if not error else "noti_true"
return gr.HTML(
value=f"<h3 class='{css_class}'>{message}</h3>",
visible=visible,
elem_classes=elem_classes,
)
def files_create_ui(
value: Union[str, List[str], Callable, None] = None,
file_count: str = "multiple",
file_types: List = ["video"],
label: str = config_data.OtherMessages_VIDEO_FILES[
config_data.AppSettings_DEFAULT_LANG_ID
],
show_label: bool = True,
interactive: bool = True,
visible: bool = True,
elem_classes: Optional[str] = "files-container",
) -> gr.File:
return gr.File(
value=value,
file_count=file_count,
file_types=file_types,
label=label,
show_label=show_label,
interactive=interactive,
visible=visible,
elem_classes=elem_classes,
)
def video_create_ui(
value: Optional[str] = None,
label: str = config_data.OtherMessages_VIDEO_PLAYER[
config_data.AppSettings_DEFAULT_LANG_ID
],
file_name: Optional[str] = None,
show_label: bool = True,
interactive: bool = False,
visible: bool = True,
elem_classes: Optional[str] = "video-container",
) -> gr.Video:
if file_name is not None:
label += f" ({file_name})"
return gr.Video(
value=value,
label=label,
show_label=show_label,
interactive=interactive,
visible=visible,
elem_classes=elem_classes,
)
def dataframe(
headers: Optional[List] = None,
values: Optional[List] = None,
height: int = 500,
wrap: bool = True,
visible: bool = True,
interactive: bool = False,
elem_classes: Optional[str] = "dataframe",
) -> gr.Dataframe:
if headers is None or values is None:
datatype = "str"
else:
datatype = ["markdown"] * len(headers)
return gr.Dataframe(
value=values,
headers=headers,
datatype=datatype,
max_height=height,
wrap=wrap,
visible=visible,
interactive=interactive,
elem_classes=elem_classes,
)
def button(
value: str = "",
interactive: bool = True,
scale: int = 3,
icon: Optional[str] = None,
visible: bool = True,
elem_classes: Optional[str] = None,
) -> gr.Button:
return gr.Button(
value=value,
interactive=interactive,
scale=scale,
icon=icon,
visible=visible,
elem_classes=elem_classes,
)
def radio_create_ui(
value: Union[str, int, float, Callable, None],
label: str,
choices: Union[List, None],
info: str,
interactive: bool,
visible: bool,
):
return gr.Radio(
value=value,
label=label,
choices=choices,
info=info,
show_label=True,
container=True,
interactive=interactive,
visible=visible,
)
def number_create_ui(
value: float = 0.5,
minimum: float = 0.0,
maximum: float = 1.0,
step: float = 0.01,
label: Optional[str] = None,
info: Optional[str] = None,
show_label: bool = True,
interactive: bool = True,
visible: bool = False,
render: bool = True,
elem_classes: Optional[str] = "number-container",
):
return gr.Number(
value=value,
minimum=minimum,
maximum=maximum,
step=step,
label=label,
info=info,
show_label=show_label,
interactive=interactive,
visible=visible,
render=render,
elem_classes=elem_classes,
)
def dropdown_create_ui(
label: Optional[str] = None,
info: Optional[str] = None,
choices: Optional[List[str]] = None,
value: Optional[List[str]] = None,
multiselect: bool = False,
show_label: bool = True,
interactive: bool = True,
visible: bool = True,
render: bool = True,
elem_classes: Optional[str] = None,
) -> gr.Dropdown:
return gr.Dropdown(
choices=choices,
value=value,
multiselect=multiselect,
label=label,
info=info,
show_label=show_label,
interactive=interactive,
visible=visible,
render=render,
elem_classes=elem_classes,
)
def textbox_create_ui(
value: Optional[str] = None,
type: Literal["text", "password", "email"] = "text",
label: Optional[str] = None,
placeholder: Optional[str] = None,
info: Optional[str] = None,
max_lines: int = 1,
show_label: bool = True,
interactive: bool = True,
visible: bool = True,
show_copy_button: bool = True,
scale: int = 1,
container: bool = False,
):
return gr.Textbox(
value=value,
type=type,
label=label,
placeholder=placeholder,
info=info,
max_lines=max_lines,
show_label=show_label,
interactive=interactive,
visible=visible,
show_copy_button=show_copy_button,
scale=scale,
container=container,
)
|