Spaces:
Running
Running
FoodDesert
commited on
Commit
•
456433b
1
Parent(s):
b385d34
Upload app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,8 @@ with h5py.File('complete_artist_data.hdf5', 'r') as f:
|
|
20 |
artist_names = [name.decode() for name in f['artist_names'][:]]
|
21 |
|
22 |
def find_similar_artists(new_tags_string, top_n):
|
23 |
-
|
|
|
24 |
unseen_tags = set(new_image_tags) - set(vectorizer.vocabulary_.keys())
|
25 |
unseen_tags_str = f'Unseen Tags: {", ".join(unseen_tags)}' if unseen_tags else 'No unseen tags.'
|
26 |
|
@@ -28,24 +29,24 @@ def find_similar_artists(new_tags_string, top_n):
|
|
28 |
similarities = cosine_similarity(X_new_image, X_artist)[0]
|
29 |
|
30 |
top_artist_indices = np.argsort(similarities)[-top_n:][::-1]
|
31 |
-
bottom_artist_indices = np.argsort(similarities)[:top_n]
|
32 |
-
|
33 |
top_artists = [(artist_names[i], similarities[i]) for i in top_artist_indices]
|
34 |
-
bottom_artists = [(artist_names[i], similarities[i]) for i in bottom_artist_indices]
|
35 |
|
36 |
-
top_artists_str = "\n".join([f"{rank+1}. {artist}
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
return output_str
|
41 |
|
42 |
iface = gr.Interface(
|
43 |
fn=find_similar_artists,
|
44 |
inputs=[
|
45 |
-
gr.Textbox(label="Enter image tags", placeholder="fox, outside, detailed background"),
|
46 |
gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Number of artists")
|
47 |
],
|
48 |
-
outputs=
|
|
|
|
|
|
|
|
|
49 |
title="Tagset Completer",
|
50 |
description="Enter a list of comma-separated e6 tags"
|
51 |
)
|
|
|
20 |
artist_names = [name.decode() for name in f['artist_names'][:]]
|
21 |
|
22 |
def find_similar_artists(new_tags_string, top_n):
|
23 |
+
#
|
24 |
+
new_image_tags = [tag.replace('_', ' ').strip() for tag in new_tags_string.split(",")]
|
25 |
unseen_tags = set(new_image_tags) - set(vectorizer.vocabulary_.keys())
|
26 |
unseen_tags_str = f'Unseen Tags: {", ".join(unseen_tags)}' if unseen_tags else 'No unseen tags.'
|
27 |
|
|
|
29 |
similarities = cosine_similarity(X_new_image, X_artist)[0]
|
30 |
|
31 |
top_artist_indices = np.argsort(similarities)[-top_n:][::-1]
|
|
|
|
|
32 |
top_artists = [(artist_names[i], similarities[i]) for i in top_artist_indices]
|
|
|
33 |
|
34 |
+
top_artists_str = "\n".join([f"{rank+1}. {artist[3:]} ({score:.4f})" for rank, (artist, score) in enumerate(top_artists)])
|
35 |
+
dynamic_prompts_formatted_artists = "{" + "|".join([artist for artist, _ in top_artists]) + "}"
|
36 |
|
37 |
+
return unseen_tags_str, top_artists_str, dynamic_prompts_formatted_artists
|
|
|
38 |
|
39 |
iface = gr.Interface(
|
40 |
fn=find_similar_artists,
|
41 |
inputs=[
|
42 |
+
gr.Textbox(label="Enter image tags", placeholder="e.g. fox, outside, detailed background, ..."),
|
43 |
gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Number of artists")
|
44 |
],
|
45 |
+
outputs=[
|
46 |
+
gr.Textbox(label="Unseen Tags", info="These tags are not used in the artist calculation. Even valid e6 tags may be \"unseen\" if they have insufficient data."),
|
47 |
+
gr.Textbox(label="Top Artists", info="These are the artists most strongly associated with your tags. The number in parenthes is a similarity score between 0 and 1, with higher numbers indicating greater similarity."),
|
48 |
+
gr.Textbox(label="Dynamic Prompts Format", info="For if you're using the Automatic1111 webui (https://github.com/AUTOMATIC1111/stable-diffusion-webui) with the Dynamic Prompts extension activated (https://github.com/adieyal/sd-dynamic-prompts) and want to try them all individually.")
|
49 |
+
],
|
50 |
title="Tagset Completer",
|
51 |
description="Enter a list of comma-separated e6 tags"
|
52 |
)
|