File size: 10,397 Bytes
c2578be 8c7758f c2578be 8c7758f e0594c4 c2578be 8c7758f c2578be 8c7758f c2578be e0594c4 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be e0594c4 8c7758f e0594c4 8c7758f e0594c4 8c7758f e0594c4 c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be 8c7758f c2578be |
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
---
tags: [gradio-custom-component, ]
title: gradio_taggrouphelper
short_description: A fast prompt generator based on tagged words
colorFrom: blue
colorTo: yellow
sdk: gradio
pinned: false
app_file: space.py
---
# `gradio_taggrouphelper`
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.3%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_taggrouphelper"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-blue"></a> <p><span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_taggrouphelper'>Component GitHub Code</a></span></p>
A fast text generator based on tagged words
## Installation
```bash
pip install gradio_taggrouphelper
```
## Usage
```python
#
# demo/app.py
#
import gradio as gr
from gradio_taggrouphelper import TagGroupHelper
# Example data structure for the tags and groups
TAG_DATA = {
"Quality": [
"best quality", "masterpiece", "high resolution", "4k", "8k",
"sharp focus", "detailed", "photorealistic"
],
"Lighting": [
"cinematic lighting", "volumetric lighting", "god rays",
"golden hour", "studio lighting", "dramatic lighting"
],
"Style": [
"anime style", "oil painting", "concept art", "fantasy",
"steampunk", "vaporwave", "line art"
],
"Negative Prompts": [
"blurry", "noisy", "low resolution", "low quality", "watermark",
"text", "bad anatomy", "extra limbs", "disfigured"
]
}
css="""
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
}
.gradio-container {
border-radius: 15px;
padding: 30px 40px;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
margin: 40px 340px;
}
.gradio-container h1 {
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}
.fillable {
width: 100% !important;
max-width: unset !important;
}
#examples_container {
margin: auto;
width: 90%;
}
#examples_row {
justify-content: center;
}
#tips_row{
padding-left: 20px;
}
.sidebar {
border-radius: 10px;
padding: 10px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.sidebar .toggle-button {
background: linear-gradient(90deg, #34d399, #10b981) !important;
border: none;
padding: 12px 18px;
text-transform: uppercase;
font-weight: bold;
letter-spacing: 1px;
border-radius: 5px;
cursor: pointer;
transition: transform 0.2s ease-in-out;
}
.toggle-button:hover {
transform: scale(1.05);
}
.sidebar .sidebar-content {
padding-left: 10px !important;
}
.sidebar .sidebar-content .column .block div .prose {
text-align: center;
}
"""
with gr.Blocks(theme=gr.themes.Ocean(), css=css) as demo:
gr.Markdown("# Tag Group Helper Demo")
gr.Markdown("Click on the tags below to add them to the prompt textboxes.")
gr.Markdown("<span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_taggrouphelper'>GitHub Code</a></span>")
with gr.Row():
with gr.Column(scale=2): # Give more space to the textboxes
# Create the target Textbox and give it a unique `elem_id`.
positive_prompt_box = gr.Textbox(
label="Positive Prompt",
placeholder="Click tags from 'Prompt Keywords' to add them here...",
lines=5,
elem_id="positive-prompt-textbox" # This ID must be unique
)
negative_prompt_box = gr.Textbox(
label="Negative Prompt",
placeholder="Click tags from 'Negative Keywords' to add them here...",
lines=5,
elem_id="negative-prompt-textbox" # This ID must be unique
)
with gr.Sidebar(position="right"):
# Create an instance of the TagGroupHelper for the Positive Prompt box.
TagGroupHelper(
label="Positive Prompt Keywords",
value={k: v for k, v in TAG_DATA.items() if "Negative" not in k},
target_textbox_id="positive-prompt-textbox",
separator=", ",
interactive=True,
width=250,
font_size_scale=90
)
# Create another instance for the Negative Prompt box.
TagGroupHelper(
label="Negative Prompt Keywords",
value={"Negative Prompts": TAG_DATA["Negative Prompts"]},
target_textbox_id="negative-prompt-textbox",
separator=", ",
interactive=True,
width=250,
font_size_scale=90
)
if __name__ == '__main__':
demo.launch()
```
## `TagGroupHelper`
### Initialization
<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>value</code></td>
<td align="left" style="width: 25%;">
```python
typing.Optional[typing.Dict[str, typing.List[str]]][
typing.Dict[str, typing.List[str]][
str, typing.List[str][str]
],
None,
]
```
</td>
<td align="left"><code>None</code></td>
<td align="left">A dictionary where keys are group names and values are lists of tags.</td>
</tr>
<tr>
<td align="left"><code>height</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">The height of the component container in pixels.</td>
</tr>
<tr>
<td align="left"><code>width</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">The width of the component container in pixels.</td>
</tr>
<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">The label for this component, displayed above the groups.</td>
</tr>
<tr>
<td align="left"><code>font_size_scale</code></td>
<td align="left" style="width: 25%;">
```python
int
```
</td>
<td align="left"><code>100</code></td>
<td align="left">A percentage to scale the font size of group headers and tags. Defaults to 100.</td>
</tr>
<tr>
<td align="left"><code>every</code></td>
<td align="left" style="width: 25%;">
```python
float | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">If `value` is a callable, run the function 'every' seconds while the client connection is open.</td>
</tr>
<tr>
<td align="left"><code>show_label</code></td>
<td align="left" style="width: 25%;">
```python
bool | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">If False, the label is not displayed.</td>
</tr>
<tr>
<td align="left"><code>container</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">If False, the component will not be wrapped in a container.</td>
</tr>
<tr>
<td align="left"><code>scale</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">The relative size of the component compared to others in a `gr.Row` or `gr.Column`.</td>
</tr>
<tr>
<td align="left"><code>min_width</code></td>
<td align="left" style="width: 25%;">
```python
int
```
</td>
<td align="left"><code>160</code></td>
<td align="left">The minimum width of the component in pixels.</td>
</tr>
<tr>
<td align="left"><code>interactive</code></td>
<td align="left" style="width: 25%;">
```python
bool | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">if True, will be rendered as an selectable component; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.</td>
</tr>
<tr>
<td align="left"><code>target_textbox_id</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">The `elem_id` of the `gr.Textbox` component to target. Required.</td>
</tr>
<tr>
<td align="left"><code>separator</code></td>
<td align="left" style="width: 25%;">
```python
str
```
</td>
<td align="left"><code>", "</code></td>
<td align="left">The string to use as a separator between tags. Defaults to ", ". Can be set to " " for space separation.</td>
</tr>
<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">If False, the component will be hidden.</td>
</tr>
<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">An optional string that is assigned as the id of this component in the HTML DOM.</td>
</tr>
<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">
```python
list[str] | str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">An optional list of strings to assign as CSS classes to the component.</td>
</tr>
</tbody></table>
### User function
The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.
The code snippet below is accurate in cases where the component is used as both an input and an output.
```python
def predict(
value: Any
) -> typing.Optional[typing.Dict[str, typing.List[str]]][
typing.Dict[str, typing.List[str]][
str, typing.List[str][str]
],
None,
]:
return value
```
|