CupidAI / app_2.py
suinY00N's picture
Rename app.py to app_2.py
cc631fc verified
import os
from deepface import DeepFace
def compare_faces():
results = []
# ๋‚จ์ž ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
male_image_paths = [f"images/{i}_M.jpeg" for i in range(1, 33)]
# ์—ฌ์ž ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
female_image_paths = [f"images/{i}_F.jpeg" for i in range(1, 23)]
for male_index in range(1, 33):
# ๋‚จ์ž ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ
male_image_path = f"images/{male_index}_M.jpeg"
max_similarity = -1
min_similarity = float('inf')
most_similar = None
least_similar = None
for female_image_path in female_image_paths:
result = DeepFace.verify(male_image_path, female_image_path, enforce_detection=False)
similarity = 1 - result["distance"]
if similarity > max_similarity:
max_similarity = similarity
most_similar = female_image_path
if similarity < min_similarity:
min_similarity = similarity
least_similar = female_image_path
most_similar_name = os.path.basename(most_similar)
least_similar_name = os.path.basename(least_similar)
results.append(
f"๋‚จ์ž M_{male_index}:\n"
f" ๊ฐ€์žฅ ์œ ์‚ฌ๋„๊ฐ€ ๋†’์€ ์‚ฌ๋žŒ: {most_similar_name} (์œ ์‚ฌ๋„: {max_similarity:.2f})\n"
f" ๊ฐ€์žฅ ์œ ์‚ฌ๋„๊ฐ€ ๋‚ฎ์€ ์‚ฌ๋žŒ: {least_similar_name} (์œ ์‚ฌ๋„: {min_similarity:.2f})"
)
return "\n\n".join(results)
def main():
results = compare_faces()
print(results)
if __name__ == "__main__":
main()