FoodDesert commited on
Commit
0e7f749
·
verified ·
1 Parent(s): d721885

Changing FAQ

Browse files
Files changed (1) hide show
  1. app.py +44 -51
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
- ## What is the purpose of this tool?
57
 
58
- Since Stable Diffusion's initial release in 2022, users have developed a myriad of fine-tuned text to image models, each with unique "linguistic" preferences depending on the data from which it was fine-tuned.
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
- When you enter a txt2img prompt and press the "submit" button, Prompt Squirrel parses your prompt and checks that all your tags are valid e621 tags.
63
- If it finds any that are not, it recommends some valid e621 tags you can use to replace them in the "Unknown Tags" section.
64
- Additionally, in the "Top Artists" text box, it lists the artists who would most likely draw an image having the set of tags you provided.
65
- This is useful to align your prompt with the expected input to an e621-trained model.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, e621-trained models replace underscores in tags with spaces, so spaces are preferred.
74
 
75
  ## Can I use parentheses or weights as in the Stable Diffusion Automatic1111 WebUI?
76
 
77
- Yes, but only '(' and ')' and numerical weights, and all of these things are ignored in all calculations. The main benefit of this is that you can copy/paste prompts from one program to another with minimal editing.
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 "unknown", and why don't some artists ever get returned?
82
 
83
- Some data is excluded from consideration if it did not occur frequently enough in the sample from which the application makes its calculations.
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 of those that do, why do some look truncated?
87
 
88
- Both of these features are extracted from the tag wiki pages, but some valid e621 tags do not have wiki pages. Additionally, the summaries are heuristically extracted from the beginning of the wiki pages, and this extraction process is prone to some amount of error.
89
 
90
  ## Are there any special tags?
91
 
92
- Yes. We normalized the favorite counts of each image to a range of 0-9, with 0 being the lowest favcount, and 9 being the highest.
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. If you want to more strongly bias the artist output toward a specific tag, you can just list it multiple times.
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 "not-for-all-audience"
103
- The "not-for-all-audience" tag informs users that this tool's text output is derived from e621.net data for tag prediction and completion.
104
- The app will try not to display nsfw tags unless the "Allow NSFW Tags" is checked, but the filter is not perfect.
 
 
105
 
106
  ## How is the artist list calculated?
107
 
108
- Each artist is represented by a "pseudo-document" composed of all the tags from their uploaded images, treating these tags similarly to words in a text document.
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 does the tag corrector work?
116
 
117
- We collect the tag sets from over 4 million e621 posts, treating the tag set from each image as an individual document.
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
- To enhance the tag corrector further, we employ the same TF-IDF method we used for artist tags to calculate a separate, context-sensitive similarity score for each of the top 100 tags selected via the FastText method.
125
- By considering the context in which tags are used, we can now not only correct misspellings and rephrasings but also make more contextually relevant suggestions.
126
- The "similarity weight" slider controls how much weight these TF-IDF scores are given vs how much weight the FastText similarity model is given when suggesting replacements for invalid tags.
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 the first row of galleries, for each artist in the dataset, we generated a sample image with the model Fluffyrock Unleashed using the prompt "by artist, soyjak, anthro, male, bust portrait, meme, grin" where "artist" is the name of an artist.
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="Allow NSFW Tag Suggestions", value=False)
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 09. 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 'notforallaudience'?
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 pseudodocument 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(