Skip to content

Commit

Permalink
[AI Tagger] Prepare stash plugin to support new model tags (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
skier233 authored Jul 30, 2024
1 parent 8280454 commit 2f5caf4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
10 changes: 5 additions & 5 deletions plugins/AITagger/ai_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ async def __tag_images(images):
log.error(f"Error processing image: {result['error']}")
media_handler.add_error_images([id])
else:
actions = result['actions']
action_stashtag_ids = media_handler.get_tag_ids(actions)
action_stashtag_ids.append(media_handler.ai_tagged_tag_id)
media_handler.add_tags_to_image(id, action_stashtag_ids)
tags = media_handler.get_all_tags_from_server_result(result)
stashtag_ids = media_handler.get_tag_ids(tags)
stashtag_ids.append(media_handler.ai_tagged_tag_id)
media_handler.add_tags_to_image(id, stashtag_ids)

log.info(f"Tagged {len(imageIds)} images")
media_handler.remove_tagme_tags_from_images(imageIds)
Expand All @@ -166,7 +166,7 @@ async def __tag_images(images):
except asyncio.TimeoutError as a:
log.error(f"Timeout processing images: {a}")
except Exception as e:
log.error(f"Failed to process images: {e}")
log.error(f"Failed to process images: {e}Stack trace: {traceback.format_exc()}")
media_handler.add_error_images(imageIds)
media_handler.remove_tagme_tags_from_images(imageIds)
finally:
Expand Down
2 changes: 1 addition & 1 deletion plugins/AITagger/ai_tagger.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: AI Tagger
description: Tag videos and Images with Locally hosted AI using Skier's Patreon AI models
version: 1.6
version: 1.7
url: https://github.com/stashapp/CommunityScripts/tree/main/plugins/AITagger
exec:
- python
Expand Down
4 changes: 2 additions & 2 deletions plugins/AITagger/ai_video_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def __mutate_server_result_tags(cls, server_result, model_name, frame_interval):
tags = {}
for result in server_result:
frame_index = result["frame_index"]
actions = result["actions"]
for action in actions:
alltags = media_handler.get_all_tags_from_server_result(result)
for action in alltags:
tag_name, confidence = action
if tag_name not in tags:
tags[tag_name] = TagData(ai_model_name=model_name, time_frames=[TagTimeFrame(start=frame_index, end=None, confidence=confidence)])
Expand Down
9 changes: 9 additions & 0 deletions plugins/AITagger/media_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def initialize(connection):

# ----------------- Tag Methods -----------------


tag_categories = ["actions", "bodyparts"]

def get_all_tags_from_server_result(result):
alltags = []
for category in tag_categories:
alltags.extend(result.get(category, []))
return alltags

def get_tag_ids(tag_names):
return [get_tag_id(tag_name) for tag_name in tag_names]

Expand Down
19 changes: 19 additions & 0 deletions plugins/AITagger/tag_mappings.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,22 @@ Undressing,Undressing_AI,15,6,20s,0.5
Vaginal Penetration,Vaginal Penetration_AI,15,6,20s,0.5
Vaginal Fucking,Vaginal Fucking_AI,15,6,20s,0.5
Vibrating,Vibrating_AI,10,6,20s,0.5
Ass,Ass_AI,-1,6,20s,0.5
Asshole,Asshole_AI,-1,6,20s,0.5
Anal Gape,Anal Gape_AI,10,6,20s,0.5
Boobs,Boobs_AI,-1,6,20s,0.5
Cum,Cum_AI,10,6,20s,0.5
Dick,Dick_AI,-1,6,20s,0.5
Face,Face_AI,-1,6,20s,0.5
Feet,Feet_AI,-1,6,20s,0.5
Fingers,Fingers_AI,-1,6,20s,0.5
Belly Button,Belly Button_AI,-1,6,20s,0.5
Nipples,Nipples_AI,-1,6,20s,0.5
Thighs,Thighs_AI,-1,6,20s,0.5
Lower Legs,Lower Legs_AI,-1,6,20s,0.5
Tongue,Tongue_AI,10,6,20s,0.5
Pussy,Pussy_AI,-1,6,20s,0.5
Pussy Gape,Pussy Gape_AI,10,6,20s,0.5
Spit,Spit_AI,10,6,20s,0.5
Oiled,Oiled_AI,10,6,20s,0.5
Wet (Water),Wet (Water)_AI,10,6,20s,0.5

0 comments on commit 2f5caf4

Please sign in to comment.