Update app.py
Browse files
app.py
CHANGED
@@ -65,6 +65,24 @@ def prepare_image(image, target_size):
|
|
65 |
|
66 |
return np.expand_dims(image_array, axis=0) # Add batch dimension
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
class LabelData:
|
69 |
def __init__(self, names, rating, general, character):
|
70 |
self.names = names
|
|
|
65 |
|
66 |
return np.expand_dims(image_array, axis=0) # Add batch dimension
|
67 |
|
68 |
+
# Function to process predictions with thresholds
|
69 |
+
def process_predictions_with_thresholds(preds, tag_data, character_thresh, general_thresh, hide_rating_tags, character_tags_first):
|
70 |
+
# Extract prediction scores
|
71 |
+
scores = preds.flatten()
|
72 |
+
|
73 |
+
# Filter and sort character and general tags based on thresholds
|
74 |
+
character_tags = [tag_data.names[i] for i in tag_data.character if scores[i] >= character_thresh]
|
75 |
+
general_tags = [tag_data.names[i] for i in tag_data.general if scores[i] >= general_thresh]
|
76 |
+
|
77 |
+
# Optionally filter rating tags
|
78 |
+
rating_tags = [] if hide_rating_tags else [tag_data.names[i] for i in tag_data.rating]
|
79 |
+
|
80 |
+
# Sort tags based on user preference
|
81 |
+
final_tags = character_tags + general_tags if character_tags_first else general_tags + character_tags
|
82 |
+
final_tags += rating_tags # Add rating tags at the end if not hidden
|
83 |
+
|
84 |
+
return final_tags
|
85 |
+
|
86 |
class LabelData:
|
87 |
def __init__(self, names, rating, general, character):
|
88 |
self.names = names
|