Last active
October 26, 2022 14:57
-
-
Save odashi/11123dd282c15a48f076a4a285c93f6c to your computer and use it in GitHub Desktop.
Colab UI to generate NovelAI prompts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install ipywidgets &> /dev/null | |
import ipywidgets as wgt | |
controls = wgt.VBox([]) | |
add_button = wgt.Button(description="Add", icon="plus") | |
pos_prompt_area = wgt.Textarea(placeholder="Positive prompts appear here.") | |
neg_prompt_area = wgt.Textarea(placeholder="Negative prompts appear here.") | |
ui = wgt.VBox([pos_prompt_area, neg_prompt_area, add_button, controls]) | |
def generate_prompt(change): | |
pos_prompts = [] | |
neg_prompts = [] | |
for box in controls.children: | |
text = box.children[0].value | |
strength = box.children[1].value | |
abs_strength = abs(strength) - 1 | |
prompt = "{" * abs_strength + text + "}" * abs_strength | |
if strength > 0: | |
pos_prompts.append(prompt) | |
elif strength < 0: | |
neg_prompts.append(prompt) | |
pos_prompt_area.value = ", ".join(pos_prompts) | |
neg_prompt_area.value = ", ".join(neg_prompts) | |
def remove_prompt(button): | |
for i, box in enumerate(controls.children): | |
if box.children[2] is button: | |
controls.children = controls.children[:i] + controls.children[i+1:] | |
generate_prompt(None) | |
def add_prompt(button): | |
text = wgt.Text(description="Prompt:", placeholder="write here...") | |
text.observe(generate_prompt) | |
strength = wgt.IntSlider(description="Strength:", value=0, min=-10, max=10, step=1) | |
strength.observe(generate_prompt) | |
remove_button = wgt.Button(description="Remove", icon="trash") | |
remove_button.on_click(remove_prompt) | |
controls.children += (wgt.HBox([text, strength, remove_button]),) | |
add_button.on_click(add_prompt) | |
display(ui) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment