from modules.taggers.base import TaggerProcessor class CLTaggerProcessor(TaggerProcessor): def __init__(self, cl_tagger_instance_ref, replacement_file_path, synonym_file_path, addition_file_path): super().__init__(replacement_file_path, synonym_file_path, addition_file_path) self.cl_tagger_ref = cl_tagger_instance_ref def predict(self, image, gen_threshold, char_threshold, replacement_file_path, synonym_file_path, addition_file_path, sort_order="Alfabetik", device_pref: str = "Auto"): self.replacement_file = replacement_file_path self.synonym_file = synonym_file_path self.addition_file = addition_file_path if self.cl_tagger_ref is None or self.cl_tagger_ref.session is None: return "", "❌ CL Tagger modülü yüklenemedi.", [] if image is None: return "", "⚠️ Resim yüklenmedi.", [] try: ai_tags_string_raw, _, raw_predictions_dict = self.cl_tagger_ref.predict(image, gen_threshold, char_threshold) all_raw_tags_with_probs = [] for category_key in ["rating", "quality", "artist", "character", "copyright", "general", "meta", "model"]: all_raw_tags_with_probs.extend(raw_predictions_dict.get(category_key, [])) all_raw_tags_with_probs_sorted = sorted(all_raw_tags_with_probs, key=lambda x: x[1], reverse=True) original_order_for_cl = [tag_name.replace("_", " ") for tag_name, _ in all_raw_tags_with_probs_sorted] final_tags = self.process_tags(ai_tags_string_raw, sort_order, original_order_for_cl) return final_tags, "✅ CL Tagger işlemi tamamlandı!", original_order_for_cl except Exception as e: return f"Hata: {e}", f"❌ CL Tagger hata: {e}", []