Spaces:
Sleeping
Sleeping
FoodDesert
commited on
Commit
•
f57539d
1
Parent(s):
62e022b
Upload 4 files
Browse files- app.py +19 -13
- tf_idf_files_420.joblib +3 -0
- word_rating_probabilities.csv +0 -0
app.py
CHANGED
@@ -181,7 +181,7 @@ def load_model_components(file_path):
|
|
181 |
|
182 |
return model_components
|
183 |
# Load all components at the start
|
184 |
-
tf_idf_components = load_model_components('
|
185 |
|
186 |
# Load the model and data once at startup
|
187 |
with h5py.File('complete_artist_data.hdf5', 'r') as f:
|
@@ -670,24 +670,30 @@ def find_similar_artists(original_tags_string, top_n, similarity_weight, allow_n
|
|
670 |
suggested_tags_html_content = "<div class=\"scrollable-content\" style='display: inline-block; margin: 20px; text-align: center;'>"
|
671 |
|
672 |
suggested_tags_html_content += "<h1>Suggested Tags</h1>" # Heading for the table
|
673 |
-
suggested_tags = get_tfidf_reduced_similar_tags([item["tf_idf_matrix_tag"] for item in tag_data], allow_nsfw_tags)
|
674 |
|
675 |
# Create a set of tags that should be filtered out
|
676 |
filter_tags = {entry["original_tag"].strip() for entry in tag_data}
|
677 |
# Use this set to filter suggested_tags
|
678 |
suggested_tags_filtered = OrderedDict((k, v) for k, v in suggested_tags.items() if k not in filter_tags)
|
679 |
-
|
680 |
-
|
|
|
|
|
|
|
|
|
681 |
suggested_tags_html_content += create_html_tables_for_tags("Suggested Tag", topnsuggestions, find_similar_tags.tag2count, find_similar_tags.tag2idwiki)
|
682 |
|
683 |
#Artist stuff
|
684 |
-
artist_matrix_tags = [tag_info['artist_matrix_tag'] for tag_info in tag_data if tag_info['node_type'] == "tag"]
|
685 |
-
X_new_image = vectorizer.transform([','.join(artist_matrix_tags + removed_tags)])
|
686 |
-
similarities = cosine_similarity(X_new_image, X_artist)[0]
|
687 |
-
|
688 |
-
top_artist_indices = np.argsort(similarities)[-(top_n + 1):][::-1]
|
689 |
-
top_artists = [(artist_names[i], similarities[i]) for i in top_artist_indices if artist_names[i].lower() != "by conditional dnp"][:top_n]
|
690 |
-
|
|
|
|
|
691 |
top_artists_str = create_top_artists_table(top_artists)
|
692 |
dynamic_prompts_formatted_artists = "{" + "|".join([artist for artist, _ in top_artists]) + "}"
|
693 |
|
@@ -712,7 +718,7 @@ with gr.Blocks(css=css) as app:
|
|
712 |
with gr.Column(scale=1):
|
713 |
#image_path = os.path.join("https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main", "transparentsquirrel.png")
|
714 |
#gr.Image(label=" ", value=image_path, height=155, width=140)
|
715 |
-
|
716 |
#gr.HTML("<br>" * 2) # Adjust the number of line breaks ("<br>") as needed to push the button down
|
717 |
#image_path = os.path.join('mascotimages', "transparentsquirrel.png")
|
718 |
#random_image_path = os.path.join('mascotimages', random.choice([f for f in os.listdir('mascotimages') if os.path.isfile(os.path.join('mascotimages', f))]))
|
@@ -720,7 +726,7 @@ with gr.Blocks(css=css) as app:
|
|
720 |
# gr.Image(value=img,show_label=False, show_download_button=False, show_share_button=False, height=200)
|
721 |
#gr.Image(value="https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main/mascotimages/transparentsquirrel.png",show_label=False, show_download_button=False, show_share_button=False, height=200)
|
722 |
#I posted the image to discord, and that's where this link came from. This is a very ugly way to do this, but I could not, no matter what I tried, get it to display an image from within the space itself. The galleries work fine for some reason, but not this.
|
723 |
-
gr.Image(value="https://res.cloudinary.com/dnse84ol6/image/upload/v1713538125/transparentsquirrel_zhou7f.png",show_label=False, show_download_button=False, show_share_button=False, height=200)
|
724 |
submit_button = gr.Button(variant="primary")
|
725 |
with gr.Row():
|
726 |
with gr.Column(scale=3):
|
|
|
181 |
|
182 |
return model_components
|
183 |
# Load all components at the start
|
184 |
+
tf_idf_components = load_model_components('tf_idf_files_420.joblib')
|
185 |
|
186 |
# Load the model and data once at startup
|
187 |
with h5py.File('complete_artist_data.hdf5', 'r') as f:
|
|
|
670 |
suggested_tags_html_content = "<div class=\"scrollable-content\" style='display: inline-block; margin: 20px; text-align: center;'>"
|
671 |
|
672 |
suggested_tags_html_content += "<h1>Suggested Tags</h1>" # Heading for the table
|
673 |
+
suggested_tags = get_tfidf_reduced_similar_tags([item["tf_idf_matrix_tag"] for item in tag_data] + removed_tags, allow_nsfw_tags)
|
674 |
|
675 |
# Create a set of tags that should be filtered out
|
676 |
filter_tags = {entry["original_tag"].strip() for entry in tag_data}
|
677 |
# Use this set to filter suggested_tags
|
678 |
suggested_tags_filtered = OrderedDict((k, v) for k, v in suggested_tags.items() if k not in filter_tags)
|
679 |
+
|
680 |
+
# Splitting the dictionary into two based on the condition
|
681 |
+
suggested_artist_tags_filtered = OrderedDict((k, v) for k, v in suggested_tags_filtered.items() if k.startswith("by "))
|
682 |
+
suggested_non_artist_tags_filtered = OrderedDict((k, v) for k, v in suggested_tags_filtered.items() if not k.startswith("by ") and k not in special_tags)
|
683 |
+
|
684 |
+
topnsuggestions = list(islice(suggested_non_artist_tags_filtered.items(), 100))
|
685 |
suggested_tags_html_content += create_html_tables_for_tags("Suggested Tag", topnsuggestions, find_similar_tags.tag2count, find_similar_tags.tag2idwiki)
|
686 |
|
687 |
#Artist stuff
|
688 |
+
#artist_matrix_tags = [tag_info['artist_matrix_tag'] for tag_info in tag_data if tag_info['node_type'] == "tag"]
|
689 |
+
#X_new_image = vectorizer.transform([','.join(artist_matrix_tags + removed_tags)])
|
690 |
+
#similarities = cosine_similarity(X_new_image, X_artist)[0]
|
691 |
+
#
|
692 |
+
#top_artist_indices = np.argsort(similarities)[-(top_n + 1):][::-1]
|
693 |
+
#top_artists = [(artist_names[i], similarities[i]) for i in top_artist_indices if artist_names[i].lower() != "by conditional dnp"][:top_n]
|
694 |
+
|
695 |
+
excluded_artists = ["by conditional dnp", "by unknown artist"]
|
696 |
+
top_artists = [(key, value) for key, value in suggested_artist_tags_filtered.items() if key.lower() not in excluded_artists][:top_n]
|
697 |
top_artists_str = create_top_artists_table(top_artists)
|
698 |
dynamic_prompts_formatted_artists = "{" + "|".join([artist for artist, _ in top_artists]) + "}"
|
699 |
|
|
|
718 |
with gr.Column(scale=1):
|
719 |
#image_path = os.path.join("https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main", "transparentsquirrel.png")
|
720 |
#gr.Image(label=" ", value=image_path, height=155, width=140)
|
721 |
+
gr.HTML('<div style="text-align: center;"><img src="https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main/mascotimages/transparentsquirrel.png" alt="Cute Mascot" style="max-height: 180px; background: transparent;"></div><br>')
|
722 |
#gr.HTML("<br>" * 2) # Adjust the number of line breaks ("<br>") as needed to push the button down
|
723 |
#image_path = os.path.join('mascotimages', "transparentsquirrel.png")
|
724 |
#random_image_path = os.path.join('mascotimages', random.choice([f for f in os.listdir('mascotimages') if os.path.isfile(os.path.join('mascotimages', f))]))
|
|
|
726 |
# gr.Image(value=img,show_label=False, show_download_button=False, show_share_button=False, height=200)
|
727 |
#gr.Image(value="https://huggingface.co/spaces/FoodDesert/Prompt_Squirrel/resolve/main/mascotimages/transparentsquirrel.png",show_label=False, show_download_button=False, show_share_button=False, height=200)
|
728 |
#I posted the image to discord, and that's where this link came from. This is a very ugly way to do this, but I could not, no matter what I tried, get it to display an image from within the space itself. The galleries work fine for some reason, but not this.
|
729 |
+
#gr.Image(value="https://res.cloudinary.com/dnse84ol6/image/upload/v1713538125/transparentsquirrel_zhou7f.png",show_label=False, show_download_button=False, show_share_button=False, height=200)
|
730 |
submit_button = gr.Button(variant="primary")
|
731 |
with gr.Row():
|
732 |
with gr.Column(scale=3):
|
tf_idf_files_420.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ab3d2a7d71a6ca70cb7012885e6102bd13530872726320ba6798365089f16b3e
|
3 |
+
size 108548478
|
word_rating_probabilities.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|