Spaces:
Running
Running
FoodDesert
commited on
Commit
•
5d5efcb
1
Parent(s):
a7e0646
sample images
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- app.py +62 -24
- artistsoyjaks/00016-0.jpg +0 -0
- artistsoyjaks/00017-0.jpg +0 -0
- artistsoyjaks/00018-0.jpg +0 -0
- artistsoyjaks/00019-0.jpg +0 -0
- artistsoyjaks/00020-0.jpg +0 -0
- artistsoyjaks/00021-0.jpg +0 -0
- artistsoyjaks/00022-0.jpg +0 -0
- artistsoyjaks/00023-0.jpg +0 -0
- artistsoyjaks/00024-0.jpg +0 -0
- artistsoyjaks/00025-0.jpg +0 -0
- artistsoyjaks/00026-0.jpg +0 -0
- artistsoyjaks/00027-0.jpg +0 -0
- artistsoyjaks/00028-0.jpg +0 -0
- artistsoyjaks/00029-0.jpg +0 -0
- artistsoyjaks/00030-0.jpg +0 -0
- artistsoyjaks/00031-0.jpg +0 -0
- artistsoyjaks/00032-0.jpg +0 -0
- artistsoyjaks/00033-0.jpg +0 -0
- artistsoyjaks/00034-0.jpg +0 -0
- artistsoyjaks/00035-0.jpg +0 -0
- artistsoyjaks/00036-0.jpg +0 -0
- artistsoyjaks/00037-0.jpg +0 -0
- artistsoyjaks/00038-0.jpg +0 -0
- artistsoyjaks/00039-0.jpg +0 -0
- artistsoyjaks/00040-0.jpg +0 -0
- artistsoyjaks/00041-0.jpg +0 -0
- artistsoyjaks/00042-0.jpg +0 -0
- artistsoyjaks/00043-0.jpg +0 -0
- artistsoyjaks/00044-0.jpg +0 -0
- artistsoyjaks/00045-0.jpg +0 -0
- artistsoyjaks/00046-0.jpg +0 -0
- artistsoyjaks/00047-0.jpg +0 -0
- artistsoyjaks/00048-0.jpg +0 -0
- artistsoyjaks/00049-0.jpg +0 -0
- artistsoyjaks/00050-0.jpg +0 -0
- artistsoyjaks/00051-0.jpg +0 -0
- artistsoyjaks/00052-0.jpg +0 -0
- artistsoyjaks/00053-0.jpg +0 -0
- artistsoyjaks/00054-0.jpg +0 -0
- artistsoyjaks/00055-0.jpg +0 -0
- artistsoyjaks/00056-0.jpg +0 -0
- artistsoyjaks/00057-0.jpg +0 -0
- artistsoyjaks/00058-0.jpg +0 -0
- artistsoyjaks/00059-0.jpg +0 -0
- artistsoyjaks/00060-0.jpg +0 -0
- artistsoyjaks/00061-0.jpg +0 -0
- artistsoyjaks/00062-0.jpg +0 -0
- artistsoyjaks/00063-0.jpg +0 -0
- artistsoyjaks/00064-0.jpg +0 -0
app.py
CHANGED
@@ -13,7 +13,12 @@ from collections import OrderedDict
|
|
13 |
from lark import Lark
|
14 |
from lark import Token
|
15 |
from lark.exceptions import ParseError
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
|
@@ -178,6 +183,24 @@ with open("word_rating_probabilities.csv", 'r', newline='', encoding='utf-8') as
|
|
178 |
nsfw_tags.add(word)
|
179 |
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
def clean_tag(tag):
|
182 |
return ''.join(char for char in tag if ord(char) < 128)
|
183 |
|
@@ -412,27 +435,42 @@ def find_similar_artists(new_tags_string, top_n, similarity_weight, allow_nsfw_t
|
|
412 |
top_artists_str = "\n".join([f"{rank+1}. {artist[3:]} ({score:.4f})" for rank, (artist, score) in enumerate(top_artists)])
|
413 |
dynamic_prompts_formatted_artists = "{" + "|".join([artist for artist, _ in top_artists]) + "}"
|
414 |
|
415 |
-
|
|
|
|
|
416 |
except ParseError as e:
|
417 |
-
return [], "Parse Error: Check for mismatched parentheses or something", ""
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
gr.
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
)
|
437 |
-
|
438 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
from lark import Lark
|
14 |
from lark import Token
|
15 |
from lark.exceptions import ParseError
|
16 |
+
import json
|
17 |
+
import zipfile
|
18 |
+
from PIL import Image
|
19 |
+
import io
|
20 |
+
import os
|
21 |
+
|
22 |
|
23 |
|
24 |
|
|
|
183 |
nsfw_tags.add(word)
|
184 |
|
185 |
|
186 |
+
soyjak_directory_path = 'artistsoyjaks'
|
187 |
+
soyjak_json_file_path = os.path.join(soyjak_directory_path, 'artistsoyjaks.json')
|
188 |
+
with open(soyjak_json_file_path, 'r') as json_file:
|
189 |
+
soyjak_artist_to_file_map = json.load(json_file)
|
190 |
+
|
191 |
+
|
192 |
+
def generate_artist_image_tuples(top_artists, image_directory=soyjak_directory_path):
|
193 |
+
artist_image_tuples = []
|
194 |
+
for artist in top_artists:
|
195 |
+
filename = soyjak_artist_to_file_map.get(artist)
|
196 |
+
if filename:
|
197 |
+
image_path = os.path.join(image_directory, filename)
|
198 |
+
if os.path.exists(image_path):
|
199 |
+
artist_image_tuples.append((image_path, artist if artist else "No Artist"))
|
200 |
+
|
201 |
+
return artist_image_tuples
|
202 |
+
|
203 |
+
|
204 |
def clean_tag(tag):
|
205 |
return ''.join(char for char in tag if ord(char) < 128)
|
206 |
|
|
|
435 |
top_artists_str = "\n".join([f"{rank+1}. {artist[3:]} ({score:.4f})" for rank, (artist, score) in enumerate(top_artists)])
|
436 |
dynamic_prompts_formatted_artists = "{" + "|".join([artist for artist, _ in top_artists]) + "}"
|
437 |
|
438 |
+
image_gallery = generate_artist_image_tuples([''] + [name[3:] for name, _ in top_artists])
|
439 |
+
|
440 |
+
return unseen_tags_data, top_artists_str, dynamic_prompts_formatted_artists, image_gallery
|
441 |
except ParseError as e:
|
442 |
+
return [], "Parse Error: Check for mismatched parentheses or something", "", None
|
443 |
+
|
444 |
+
|
445 |
+
with gr.Blocks() as app:
|
446 |
+
with gr.Group():
|
447 |
+
with gr.Column(scale=2):
|
448 |
+
with gr.Row():
|
449 |
+
image_tags = gr.Textbox(label="Enter image tags", placeholder="e.g. fox, outside, detailed background, ...")
|
450 |
+
with gr.Row():
|
451 |
+
submit_button = gr.Button("Submit")
|
452 |
+
similarity_weight = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="Similarity weight")
|
453 |
+
allow_nsfw = gr.Checkbox(label="Allow NSFW Tags", value=False)
|
454 |
+
with gr.Column(scale=1):
|
455 |
+
unseen_tags = gr.HTML(label="Unseen Tags")
|
456 |
+
|
457 |
+
with gr.Row():
|
458 |
+
with gr.Column(scale=1):
|
459 |
+
num_artists = gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Number of artists")
|
460 |
+
top_artists = gr.Textbox(label="Top Artists", info="These are the artists most strongly associated with your tags. The number in parentheses is a similarity score between 0 and 1, with higher numbers indicating greater similarity.")
|
461 |
+
dynamic_prompts = 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.")
|
462 |
+
with gr.Column(scale=3):
|
463 |
+
styles = gr.Gallery(label="Styles", info="This is what Fluffyrock Unleashed, an e621 model present in many mixes, thinks the recommended artists' styles look like.", allow_preview=True, preview=True)
|
464 |
+
|
465 |
+
|
466 |
+
submit_button.click(
|
467 |
+
find_similar_artists,
|
468 |
+
inputs=[image_tags, num_artists, similarity_weight, allow_nsfw],
|
469 |
+
outputs=[unseen_tags, top_artists, dynamic_prompts, styles]
|
470 |
+
)
|
471 |
+
|
472 |
+
gr.Markdown(faq_content)
|
473 |
+
|
474 |
+
|
475 |
+
app.launch()
|
476 |
+
|
artistsoyjaks/00016-0.jpg
ADDED
artistsoyjaks/00017-0.jpg
ADDED
artistsoyjaks/00018-0.jpg
ADDED
artistsoyjaks/00019-0.jpg
ADDED
artistsoyjaks/00020-0.jpg
ADDED
artistsoyjaks/00021-0.jpg
ADDED
artistsoyjaks/00022-0.jpg
ADDED
artistsoyjaks/00023-0.jpg
ADDED
artistsoyjaks/00024-0.jpg
ADDED
artistsoyjaks/00025-0.jpg
ADDED
artistsoyjaks/00026-0.jpg
ADDED
artistsoyjaks/00027-0.jpg
ADDED
artistsoyjaks/00028-0.jpg
ADDED
artistsoyjaks/00029-0.jpg
ADDED
artistsoyjaks/00030-0.jpg
ADDED
artistsoyjaks/00031-0.jpg
ADDED
artistsoyjaks/00032-0.jpg
ADDED
artistsoyjaks/00033-0.jpg
ADDED
artistsoyjaks/00034-0.jpg
ADDED
artistsoyjaks/00035-0.jpg
ADDED
artistsoyjaks/00036-0.jpg
ADDED
artistsoyjaks/00037-0.jpg
ADDED
artistsoyjaks/00038-0.jpg
ADDED
artistsoyjaks/00039-0.jpg
ADDED
artistsoyjaks/00040-0.jpg
ADDED
artistsoyjaks/00041-0.jpg
ADDED
artistsoyjaks/00042-0.jpg
ADDED
artistsoyjaks/00043-0.jpg
ADDED
artistsoyjaks/00044-0.jpg
ADDED
artistsoyjaks/00045-0.jpg
ADDED
artistsoyjaks/00046-0.jpg
ADDED
artistsoyjaks/00047-0.jpg
ADDED
artistsoyjaks/00048-0.jpg
ADDED
artistsoyjaks/00049-0.jpg
ADDED
artistsoyjaks/00050-0.jpg
ADDED
artistsoyjaks/00051-0.jpg
ADDED
artistsoyjaks/00052-0.jpg
ADDED
artistsoyjaks/00053-0.jpg
ADDED
artistsoyjaks/00054-0.jpg
ADDED
artistsoyjaks/00055-0.jpg
ADDED
artistsoyjaks/00056-0.jpg
ADDED
artistsoyjaks/00057-0.jpg
ADDED
artistsoyjaks/00058-0.jpg
ADDED
artistsoyjaks/00059-0.jpg
ADDED
artistsoyjaks/00060-0.jpg
ADDED
artistsoyjaks/00061-0.jpg
ADDED
artistsoyjaks/00062-0.jpg
ADDED
artistsoyjaks/00063-0.jpg
ADDED
artistsoyjaks/00064-0.jpg
ADDED