NAIA / ui /components /prompt_tabs.py
baqu2213's picture
Upload prompt_tabs.py
783199c verified
"""
NAIA-WEB Prompt Tabs Component
Tabbed interface for positive/negative prompts and prompt engineering settings
"""
import gradio as gr
def create_prompt_tabs():
"""
Create tabbed prompt input component with prompt engineering settings.
Returns:
Dict containing all prompt-related components:
- positive_prompt: Main prompt textbox
- negative_prompt: Negative/UC textbox
- pre_prompt: Pre-prompt (prepended to positive)
- post_prompt: Post-prompt (appended to positive)
- auto_hide: Auto-hide tags (removed from prompt)
- tabs: The tabs component
Design Notes:
- Tab 1: Positive Prompt (main creative input)
- Tab 2: Negative Prompt (UC - Undesired Content)
- Tab 3: Pre-prompt (prepended tags)
- Tab 4: Post-prompt (appended tags)
- Tab 5: Auto-hide (tag removal patterns)
"""
with gr.Tabs(elem_id="naia-prompt-tabs", elem_classes=["prompt-tabs"]) as prompt_tabs:
# Tab 1: Positive Prompt
with gr.Tab("Positive", id="positive"):
positive_prompt = gr.Textbox(
label="",
placeholder="Enter your prompt here...\nExample: 1girl, solo, standing, smile, blue eyes, blonde hair",
lines=4,
max_lines=10,
elem_id="naia-positive-prompt"
)
# Random Prompt Filter Options (checkbox row)
# Reference: NAIA2.0/modules/prompt_engineering_module.py
gr.Markdown("**Random Prompt Filters**", elem_classes=["filter-section-title"])
with gr.Row(elem_classes=["random-filter-row"]):
filter_characteristics = gr.Checkbox(
label="Remove Character Features",
value=True,
container=False,
elem_id="naia-filter-characteristics"
)
filter_clothes = gr.Checkbox(
label="Remove Clothes",
value=False,
container=False,
elem_id="naia-filter-clothes"
)
filter_location = gr.Checkbox(
label="Remove Location/Background",
value=False,
container=False,
elem_id="naia-filter-location"
)
with gr.Accordion("Random Image Generation Guide", open=False, elem_id="naia-random-guide"):
gr.Markdown(
"NAIA-WEB-Lite features a workflow where once you set your target prompt using Quick Search, you can generate random prompt-based images using the **[🎰 Random + Generate ]** button.\n\n"
"1. **The prompt area is volatile.** This space is merely for briefly displaying random prompts. You should modify the prompt in this area only when you like the composition after clicking \"Generate\" and want to create a better image.\n\n"
"2. **Pre-prompt and Post-prompt are non-volatile.** They are stored in your browser's LocalStorage. Every time an image is generated, it is combined in the format `[Person Count] + [Pre-prompt] + [Random Prompt - Auto-hide] + [Post-prompt]` and sent to the Novel AI API server.\n\n"
"3. Generally, it is recommended to place **artist tags in [Pre-prompt]**, and **background, various style tags, and quality tags in [Post-prompt]**."
)
gr.Image(
value="src/guide_4.png",
show_label=False,
container=False
)
# Tab 2: Negative Prompt
with gr.Tab("Negative (UC)", id="negative"):
negative_prompt = gr.Textbox(
label="",
placeholder="Enter undesired content...\nQuality tags are added automatically if empty",
lines=4,
max_lines=10,
elem_id="naia-negative-prompt"
)
# Tab 3: Pre-prompt
with gr.Tab("Pre-prompt", id="pre-prompt"):
with gr.Row():
with gr.Column(scale=2):
pre_prompt = gr.Textbox(
show_label=False,
placeholder="Tags added BEFORE your main prompt...\nExample: masterpiece, best quality, amazing quality",
lines=6,
max_lines=20,
elem_id="naia-pre-prompt",
elem_classes=["auto-expand-textbox"]
)
with gr.Column(scale=1, elem_classes=["guide-column"]):
gr.Markdown(
"### Guide\n\n"
"**Pre-prompt** tags are automatically inserted at the **beginning** of your prompt.\n\n"
"**Use cases:**\n"
"- Artist tags\n"
"- Style modifiers\n"
"- Character presets\n\n"
"**Result:** `[pre-prompt], [your prompt], [post-prompt]`",
elem_classes=["prompt-guide"]
)
gr.Textbox(
label="Example",
value="0.62::artist:your_favorite ::, 0.1::your_favorite ::, 0.04::your_favorite ::, 0.22::artist:your_favorite ::,",
lines=3,
max_lines=5,
interactive=False,
elem_classes=["example-box"]
)
# Tab 4: Post-prompt
with gr.Tab("Post-prompt", id="post-prompt"):
with gr.Row():
with gr.Column(scale=2):
post_prompt = gr.Textbox(
show_label=False,
placeholder="Tags added AFTER your main prompt...\nExample: detailed background, cinematic lighting, volumetric fog",
lines=6,
max_lines=20,
elem_id="naia-post-prompt",
elem_classes=["auto-expand-textbox"]
)
with gr.Column(scale=1, elem_classes=["guide-column"]):
gr.Markdown(
"### Guide\n\n"
"**Post-prompt** tags are automatically appended at the **end** of your prompt.\n\n"
"**Use cases:**\n"
"- Quality boosters (NAI)\n"
"- Background/lighting\n"
"- Negative weights\n\n"
"**Result:** `[pre-prompt], [your prompt], [post-prompt]`",
elem_classes=["prompt-guide"]
)
gr.Textbox(
label="Example",
value="0.28::traditional media, sketch, graphite (medium), simple background, blurry background ::, 0.28:: light particles, countershading ::, -1::mutated, ai-generated, skindentation ::, -0.33:: monochrome, cosplay photo, realistic, detailed background ::, very aesthetic, extremely absurdres, amazing quality, 1.5:: masterpiece, year 2024 ::, year 2023,",
lines=4,
max_lines=6,
interactive=False,
elem_classes=["example-box"]
)
# Tab 5: Auto-hide
with gr.Tab("Auto-hide", id="auto-hide"):
with gr.Row():
with gr.Column(scale=2):
auto_hide = gr.Textbox(
show_label=False,
placeholder="Tags to remove from prompt...\nExample: solo, __hair__, ~blonde",
lines=6,
max_lines=20,
elem_id="naia-auto-hide",
elem_classes=["auto-expand-textbox"]
)
with gr.Column(scale=1, elem_classes=["guide-column"]):
gr.Markdown(
"### Guide\n\n"
"**Auto-hide** removes matching tags from your prompt before generation.\n\n"
"**Pattern Syntax:**\n\n"
"| Pattern | Action |\n"
"|---------|--------|\n"
"| `tag` | Exact match |\n"
"| `__pattern__` | Contains |\n"
"| `_pattern` | Ends with |\n"
"| `pattern_` | Starts with |\n"
"| `~keyword` | Protect |\n\n"
"`~blurry background` protects it from `__background__` pattern.",
elem_classes=["prompt-guide"]
)
gr.Textbox(
label="Example",
value="loli, child, minigirl, chibi, chibi inset, toddlercon, monochrome, doujin cover, bad source, __censor__, uncensored, bad id, _logo, bad twitter id, __background__, ~blurry background, character doll, stuffed animal, stuffed toy, speech bubble, cyclops, pov, 3d, glasses, mole, text focus, thought bubble, watermark, web address, body writing, fake screenshot, facing away, |_|, __piercing__, tattoo, _tattoo, _text, sound effects, greyscale, multiple views, peeing, rabbit, __censor__, pregnant, __chess__, trading card, __(medium)__, __theme__, child on child, covered clitoris, _gag, sketch, poke_, __pokemon__, recording, viewfinder, multiple boys, __measuring__, multiple views, big belly, curvy, doll joints, dark-skinned male, timestamp, battery indicator, tan, fake phone screenshot, stomach bulge, __beach__, __shower__, on table, huge penis, __bug__, giant insect, belly, eye mask, circle cut, dark nipples, signature, alternate race, alternate species, dark nipples, livestream, slap mark, x-ray, armpit hair, health bar, snapchat, facial mark, emoji, command spell, dark areolae, __piercing__, __bed__, __pillow__, __sheet__, body markings, obese, __long tongue__, __name__, handprint, __pasties__, mini person, __butt plug__, __eyepatch__, makeup, mascara, gigantic breasts, runny makeup, third eye, anal hair, __halo__",
lines=6,
max_lines=10,
interactive=False,
elem_classes=["example-box"]
)
return {
"positive_prompt": positive_prompt,
"negative_prompt": negative_prompt,
"pre_prompt": pre_prompt,
"post_prompt": post_prompt,
"auto_hide": auto_hide,
"tabs": prompt_tabs,
# Random prompt filter checkboxes
"filter_characteristics": filter_characteristics,
"filter_clothes": filter_clothes,
"filter_location": filter_location,
}