Skip to main content

A fast text generator based on tagged words

Project description


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

PyPI - Version

A fast text generator based on tagged words

Installation

pip install gradio_taggrouphelper

Usage

#
# 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"
    ]
}

with gr.Blocks() as demo:
    gr.Markdown("# Tag Group Helper Demo")
    gr.Markdown("Click on the tags below to add them to the prompt textboxes.")

    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.Column(scale=1): # Give less space to the helpers
            # 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=" "
            )
            
            # 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",
                min_width=150,
                separator=", "
            )

if __name__ == '__main__':
    demo.launch()

TagGroupHelper

Initialization

name type default description
value
typing.Optional[typing.Dict[str, typing.List[str]]][
    typing.Dict[str, typing.List[str]][
        str, typing.List[str][str]
    ],
    None,
]
None A dictionary where keys are group names and values are lists of tags.
target_textbox_id
str | None
None The `elem_id` of the `gr.Textbox` component to target. Required.
separator
str
", " The string to use as a separator between tags. Defaults to ", ". Can be set to " " for space separation.
label
str | None
None The label for this component, displayed above the groups.
visible
bool
True If False, the component will be hidden.
elem_id
str | None
None An optional string that is assigned as the id of this component in the HTML DOM.
scale
int | None
None The relative size of the component compared to others in a `gr.Row` or `gr.Column`.
min_width
int | None
None The minimum-width of the component in pixels.
container
bool
True If False, the component will not be wrapped in a container.
elem_classes
list[str] | str | None
None An optional list of strings to assign as CSS classes to the component.

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_taggrouphelper-0.0.2.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradio_taggrouphelper-0.0.2-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file gradio_taggrouphelper-0.0.2.tar.gz.

File metadata

  • Download URL: gradio_taggrouphelper-0.0.2.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for gradio_taggrouphelper-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3fcad685b4b4c51aa44132b4b73823a058ec05ee83d7ff242a7fb9785583d7e1
MD5 a927c575b6ad271ff1dcb13ff934c853
BLAKE2b-256 c717325b7e91a432e2a293e3185467b02ae68df472555ee31a91dd9e02b6d1e1

See more details on using hashes here.

File details

Details for the file gradio_taggrouphelper-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_taggrouphelper-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 51d7f3755c704b22705e2dd0880d6aaca335b0fdfb1c4faae2935ddb132571d2
MD5 294e8ae06562b99e5f2e184fd7d96442
BLAKE2b-256 6d704f22c3990912d1814159b67afa71cb44df2c6a012185b2d2d9b1c8da6aab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page