Spaces:
Running
Running
Changing FAQ
Browse files
app.py
CHANGED
|
@@ -51,92 +51,85 @@ MASCOT_DIR = Path(__file__).parent / "mascotimages"
|
|
| 51 |
MASCOT_FILE = MASCOT_DIR / "transparentsquirrel.png"
|
| 52 |
|
| 53 |
faq_content="""
|
| 54 |
-
# Questions:
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
Some models react best when prompted with verbose scene descriptions akin to DALL-E, while others fine-tuned on images scraped from popular image boards understand those boards' tag sets.
|
| 60 |
-
This tool serves as a linguistic bridge to the e621 image board tag lexicon, on which many popular models such as Fluffyrock, NoobAI, and Pony Diffusion v6 were trained.
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
## Does input order matter?
|
| 68 |
|
| 69 |
-
No
|
| 70 |
|
| 71 |
## Should I use underscores or spaces in the input tags?
|
| 72 |
|
| 73 |
-
As a rule,
|
| 74 |
|
| 75 |
## Can I use parentheses or weights as in the Stable Diffusion Automatic1111 WebUI?
|
| 76 |
|
| 77 |
-
Yes, but only '(' and ')' and numerical weights
|
| 78 |
-
An example that illustrates acceptable parentheses and weight formatting is:
|
| 79 |
((sunset over the mountains)), (clear sky:1.5), ((eagle flying high:2.0)), river, (fish swimming in the river:1.2), (campfire, (marshmallows:2.1):1.3), stars in the sky, ((full moon:1.8)), (wolf howling:1.7)
|
| 80 |
|
| 81 |
-
## Why are some valid tags marked as
|
| 82 |
|
| 83 |
-
Some
|
| 84 |
-
If an artist or tag is too infrequent, we might not think we have enough data to make predictions about it. Additionally, Prompt Squirrel gathers information from several sources, and the sources are not always consistent about things like exact tag names or counts, which vary over time.
|
| 85 |
|
| 86 |
-
## Why do some suggested tags not have summaries or wiki links, and
|
| 87 |
|
| 88 |
-
|
| 89 |
|
| 90 |
## Are there any special tags?
|
| 91 |
|
| 92 |
-
Yes.
|
| 93 |
-
You can include any of these special tags: "score:0", "score:1", "score:2", "score:3", "score:4", "score:5", "score:6", "score:7", "score:8", "score:9"
|
| 94 |
-
in your list to bias the output toward artists with higher or lower scoring images.
|
| 95 |
|
| 96 |
## Are there any other special tricks?
|
| 97 |
|
| 98 |
-
Yes.
|
| 99 |
-
So for example, the query "red fox, red fox, red fox, score:7" will yield a list of artists who are more strongly associated with the tag "red fox"
|
| 100 |
-
than the query "red fox, score:7".
|
| 101 |
|
| 102 |
-
## Why is this space tagged
|
| 103 |
-
|
| 104 |
-
The
|
|
|
|
|
|
|
| 105 |
|
| 106 |
## How is the artist list calculated?
|
| 107 |
|
| 108 |
-
Each artist is represented
|
| 109 |
-
Similarly, when you input a set of tags, the system creates a pseudo-document for your query out of all the tags.
|
| 110 |
-
It then compares your tags against each artist's collection, essentially finding which artist's tags are most "similar" to yours.
|
| 111 |
-
This method helps identify artists whose work is closely aligned with the themes or elements you're interested in.
|
| 112 |
-
For those curious about the underlying mechanics of comparing text-like data, we employ the TF-IDF (Term Frequency-Inverse Document Frequency) method, a standard approach in information retrieval, and reduce the TF-IDF matrix to a reasonable size using Singular Value Decomposition.
|
| 113 |
-
You can read more about TF-IDF on its [Wikipedia page](https://en.wikipedia.org/wiki/Tf%E2%80%93idf) and Singular Value Decomposition on its [Wikipedia page](https://en.wikipedia.org/wiki/Singular_value_decomposition).
|
| 114 |
|
| 115 |
-
## How
|
| 116 |
|
| 117 |
-
|
| 118 |
-
We then randomly replace about 10% of the tags in each document with a randomly selected alias from e621's list of aliases for the tag
|
| 119 |
-
(e.g. "canine" gets replaced with one of {k9,canines,mongrel,cannine,cnaine,feral_canine,anthro_canine}).
|
| 120 |
-
We then train a FastText (https://fasttext.cc/) model on the documents. The result of this training is a function that maps arbitrary words to vectors such that
|
| 121 |
-
the vector for a tag and the vectors for its aliases are all close together (because the model has seen them in similar contexts).
|
| 122 |
-
Since the lists of aliases contain misspellings and rephrasings of tags, the model should be robust to these kinds of problems as long as they are not too dissimilar from the alias lists.
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
A similarity weight slider value of 0 means that only the FastText model's predictions will be used to calculate similarity scores, and a value of 1 means only the TF-IDF scores are used (although the FastText model is still used to trim the list of candidates).
|
| 128 |
|
|
|
|
| 129 |
|
| 130 |
## How do the sample images work?
|
| 131 |
|
| 132 |
-
In
|
| 133 |
-
The simplicity of the prompt, the the simplicty of the default style, and the recognizability of the character make it easier to understand how artist names affect generated image styles.
|
| 134 |
-
The image on the left captioned "No Artist" was generated with the same prompt, but with no artist name.
|
| 135 |
-
You should compare all the images to the first to see how the artist names affect the output.
|
| 136 |
-
Each subsequent row of images was generated using the same process, but with a different prompt.
|
| 137 |
-
See SamplePrompts.csv for the list of prompts used and their descriptions.
|
| 138 |
"""
|
| 139 |
|
|
|
|
| 140 |
TOOLTIP_NOTE_HTML = '<div class="hover-hint">Hover over underlined items for more info.</div>'
|
| 141 |
|
| 142 |
HOVER_HINT_CSS = """
|
|
@@ -1193,7 +1186,7 @@ with gr.Blocks(css=css) as app:
|
|
| 1193 |
with gr.Group():
|
| 1194 |
with gr.Row():
|
| 1195 |
context_similarity_weight = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="Context Similarity Weight")
|
| 1196 |
-
allow_nsfw = gr.Checkbox(label="
|
| 1197 |
with gr.Row():
|
| 1198 |
with gr.Column(scale=2, elem_classes=["pane-left"]):
|
| 1199 |
unseen_tags = gr.HTML(
|
|
|
|
| 51 |
MASCOT_FILE = MASCOT_DIR / "transparentsquirrel.png"
|
| 52 |
|
| 53 |
faq_content="""
|
|
|
|
| 54 |
|
| 55 |
+
# Quick Start
|
| 56 |
|
| 57 |
+
Write your prompt as a simple comma‑separated list of things you want to see in your image, then press the Run button. Prompt Squirrel will:
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
* highlight any unknown or misspelled tags,
|
| 60 |
+
* suggest corrected tags based on context,
|
| 61 |
+
* recommend additional tags the model is likely to understand, and
|
| 62 |
+
* list artists who produce topically similar content
|
| 63 |
+
|
| 64 |
+
You do not need to structure the prompt in any special way; just describe what you want in short phrases separated by commas.
|
| 65 |
+
|
| 66 |
+
# System Overview
|
| 67 |
+
|
| 68 |
+
Prompt Squirrel uses NLP and vector‑space methods to map a free‑form prompt to the structured tag vocabulary expected by tag‑based Stable Diffusion models. Internally, we use a grammar parser, FastText embeddings, TF‑IDF and SVD for context scoring, and an approximate‑nearest‑neighbor index for artist and suggested tag retrieval. Our goal is to help users write prompts that align with the tag distributions the model was trained on.
|
| 69 |
+
|
| 70 |
+
See the Technical Details heading below for more information about how these all are used.
|
| 71 |
+
|
| 72 |
+
# Prompting Guidance and Common Questions
|
| 73 |
+
|
| 74 |
+
## What text to image models does this tool work for?
|
| 75 |
+
|
| 76 |
+
This instance of Prompt Squirrel works for tag-based Stable Diffusion models fine-tuned on the popular e621 dataset. The tags it returns and especially the artist names will only be recognized by models in this category, which includes popular models such as Chroma, Fluffyrock, and NoobAI.
|
| 77 |
|
| 78 |
## Does input order matter?
|
| 79 |
|
| 80 |
+
No.
|
| 81 |
|
| 82 |
## Should I use underscores or spaces in the input tags?
|
| 83 |
|
| 84 |
+
As a rule, models trained on the dataset replace underscores with spaces, so spaces are preferred
|
| 85 |
|
| 86 |
## Can I use parentheses or weights as in the Stable Diffusion Automatic1111 WebUI?
|
| 87 |
|
| 88 |
+
Yes, but only '(' and ')' and numerical weights. These are ignored in the underlying calculations but allowed so that prompts can be copied between tools with minimal editing. An acceptable example is:
|
|
|
|
| 89 |
((sunset over the mountains)), (clear sky:1.5), ((eagle flying high:2.0)), river, (fish swimming in the river:1.2), (campfire, (marshmallows:2.1):1.3), stars in the sky, ((full moon:1.8)), (wolf howling:1.7)
|
| 90 |
|
| 91 |
+
## Why are some valid tags marked as 'unknown', and why don't some artists ever get returned?
|
| 92 |
|
| 93 |
+
Some tags or artists are too infrequent in the dataset sample for us to make reliable predictions. Prompt Squirrel merges data from several sources, which may differ slightly in tag names or counts. Low‑frequency items or inconsistent entries may therefore not appear in results.
|
|
|
|
| 94 |
|
| 95 |
+
## Why do some suggested tags not have summaries or wiki links, and why do some look truncated?
|
| 96 |
|
| 97 |
+
Summaries and wiki links are extracted from dataset wiki pages. Some tags do not have pages, and summaries are heuristically extracted from the page beginnings, which can introduce small errors.
|
| 98 |
|
| 99 |
## Are there any special tags?
|
| 100 |
|
| 101 |
+
Yes. We normalized favorite counts to a range of 0–9. You may include: 'score:0' through 'score:9' These bias the output toward suggestions associated with images with higher or lower scores.
|
|
|
|
|
|
|
| 102 |
|
| 103 |
## Are there any other special tricks?
|
| 104 |
|
| 105 |
+
Yes. Repeating a tag gives it more weight in the artist‑similarity calculation. For example: 'red fox, red fox, red fox, score:7' will bias more strongly toward artists and suggested tags associated with 'red fox' than: 'red fox, score:7'.
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
## Why is this space tagged 'not‑for‑all‑audience'?
|
| 108 |
+
|
| 109 |
+
The dataset used by many tag‑based models contains both general‑audience and adult material. To avoid surprising users, mature tags are hidden unless the user explicitly enables them. This tool processes only text and metadata; no images from the dataset are displayed.
|
| 110 |
+
|
| 111 |
+
# Technical Details
|
| 112 |
|
| 113 |
## How is the artist list calculated?
|
| 114 |
|
| 115 |
+
Each artist is represented as a pseudo‑document containing the bag of all tags from their images. Your prompt is treated as another pseudo‑document. We compute similarity between the recognized tags in your prompt and each artist using TF‑IDF and truncated SVD, then retrieve the nearest artists using an approximate‑nearest‑neighbor index.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
## How do the Suggested Tags work?
|
| 118 |
|
| 119 |
+
Each tag is represented as a pseudo-document containing the bag of all tags it co-occurs with in the dataset. We then employ exactly the same method on them as we did with artists to suggest tags similar to your prompt.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
## How does the tag corrector work?
|
| 122 |
+
|
| 123 |
+
We treat each image as a document containing the set of its tags and randomly replace about 10% of the tags with aliases from the dataset's alias lists. We then train a FastText model on these documents so that tags and their aliases map to nearby vectors. This makes the system robust to spelling variations and rephrasings.
|
|
|
|
| 124 |
|
| 125 |
+
To incorporate the prompt's context, we again treat tags as pseudo-documents containing the bag of all tags they co-occur with, then compute TF‑IDF scores for the top candidate tags selected from the FastText Model, combining this similarity score with the FastText similarity. The Context Similarity Weight slider controls how much influence the TF‑IDF context score has relative to the FastText embedding similarity.
|
| 126 |
|
| 127 |
## How do the sample images work?
|
| 128 |
|
| 129 |
+
In each gallery row, we choose an illustrative prompt and generate one image for each artist using the popular model Fluffyrock Unleashed, which was trained on this dataset. The 'No Artist' image serves as a baseline, using the same prompt without an artist name. Each subsequent row repeats this process with a different prompt. The first prompt was chosen to illustrate foreground style, the second to illustrate background style, and the third to illustrate character design. See SamplePrompts.csv in the Files section for the list of prompts used.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
"""
|
| 131 |
|
| 132 |
+
|
| 133 |
TOOLTIP_NOTE_HTML = '<div class="hover-hint">Hover over underlined items for more info.</div>'
|
| 134 |
|
| 135 |
HOVER_HINT_CSS = """
|
|
|
|
| 1186 |
with gr.Group():
|
| 1187 |
with gr.Row():
|
| 1188 |
context_similarity_weight = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="Context Similarity Weight")
|
| 1189 |
+
allow_nsfw = gr.Checkbox(label="Include Mature Tags", value=False)
|
| 1190 |
with gr.Row():
|
| 1191 |
with gr.Column(scale=2, elem_classes=["pane-left"]):
|
| 1192 |
unseen_tags = gr.HTML(
|