Spaces:
Build error
Build error
Update product_update_validator.py
Browse files- product_update_validator.py +20 -20
product_update_validator.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
-
from model_factory.description_validator import Description_Validator
|
| 2 |
-
from model_factory.image_validator import Image_Validator
|
| 3 |
-
|
| 4 |
-
class Update_Validator:
|
| 5 |
-
def __init__(self, text_model=None, image_model=None, threshold=0.7):
|
| 6 |
-
self.description_validator = Description_Validator(model_name=text_model)
|
| 7 |
-
self.image_validator = Image_Validator(model_name=image_model)
|
| 8 |
-
self.threshold = threshold
|
| 9 |
-
|
| 10 |
-
def validate(self, text1,
|
| 11 |
-
description_similarity = self.description_validator.similarity_score(text1, text2)
|
| 12 |
-
image_similarity = self.image_validator.similarity_score(image_path_1, image_path_2)
|
| 13 |
-
similarity_score = 0.75 * description_similarity + 0.25 * image_similarity
|
| 14 |
-
|
| 15 |
-
if threshold is None: threshold=self.threshold
|
| 16 |
-
label = True if similarity_score >= threshold else False
|
| 17 |
-
|
| 18 |
-
if return_score:
|
| 19 |
-
return {'score':similarity_score, 'label':label}
|
| 20 |
-
else:
|
| 21 |
return {'label':label}
|
|
|
|
| 1 |
+
from model_factory.description_validator import Description_Validator
|
| 2 |
+
from model_factory.image_validator import Image_Validator
|
| 3 |
+
|
| 4 |
+
class Update_Validator:
|
| 5 |
+
def __init__(self, text_model=None, image_model=None, threshold=0.7):
|
| 6 |
+
self.description_validator = Description_Validator(model_name=text_model)
|
| 7 |
+
self.image_validator = Image_Validator(model_name=image_model)
|
| 8 |
+
self.threshold = threshold
|
| 9 |
+
|
| 10 |
+
def validate(self, text1, image1, text2, image_2, threshold=None, return_score=False):
|
| 11 |
+
description_similarity = self.description_validator.similarity_score(text1, text2)
|
| 12 |
+
image_similarity = self.image_validator.similarity_score(image_path_1, image_path_2)
|
| 13 |
+
similarity_score = 0.75 * description_similarity + 0.25 * image_similarity
|
| 14 |
+
|
| 15 |
+
if threshold is None: threshold=self.threshold
|
| 16 |
+
label = True if similarity_score >= threshold else False
|
| 17 |
+
|
| 18 |
+
if return_score:
|
| 19 |
+
return {'score':similarity_score, 'label':label}
|
| 20 |
+
else:
|
| 21 |
return {'label':label}
|