import gradio as gr | |
from deepface import DeepFace | |
def face_similarity(img1, img2): | |
result = DeepFace.verify(img1, img2) | |
# distance๋ฅผ ์ด์ฉํด ์ ์ฌ๋๋ฅผ 1์์ ๋นผ์ ๋์์๋ก ์ ์ฌํ๊ฒ ๋ณํ | |
similarity = (1 - result["distance"])*100 | |
# ์ ์ฌ๋์ ๋ฐ๋ฅธ ๋ฉ์์ง ์กฐ๊ฑด ๋ถ๊ธฐ | |
if similarity > 40: | |
message = "๋ ๋ถ์ ์ฒ์์ฐ๋ถ!" | |
elif 30 < similarity <= 40: | |
message = "๋ ๋ถ์ ๋ด๊บผ์ธ๋ฏ ๋ด๊บผ์๋ ๋ด๊บผ๊ฐ์...?" | |
else: | |
message = "์คํ๋ ค ์ข์! ์ ๋ฐ๋์ ์ฌ๋์ด ๋๋ฆด์ง๋ ๋ชฐ๋ผ์" | |
return f"์ ์ฌ๋: {similarity:.2f}\n{message}" | |
iface = gr.Interface( | |
fn=face_similarity, | |
inputs=[gr.Image(type="numpy"), gr.Image(type="numpy")], | |
outputs="text", | |
title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ", | |
description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์ ๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค." | |
) | |
iface.launch() | |
# import gradio as gr | |
# from deepface import DeepFace | |
# def face_similarity(img1, img2): | |
# result = DeepFace.verify(img1, img2) | |
# similarity = result["distance"] # ๋ฎ์์๋ก ๋ ์ ์ฌ | |
# verified = result["verified"] | |
# # ์ ์ฌ๋์ ๋ฐ๋ฅธ ๋ฉ์์ง ์กฐ๊ฑด ๋ถ๊ธฐ | |
# if similarity >= 0.5: | |
# message = "๋ ๋ถ์ ์ฒ์์ฐ๋ถ!" | |
# elif 0.3 <= similarity < 0.5: | |
# message = "๋ ๋ถ์ ๋ด๊บผ์ธ๋ฏ ๋ด๊บผ์๋ ๋ด๊บผ๊ฐ์...?" | |
# else: | |
# message = "์คํ๋ ค ์ข์! ์ ๋ฐ๋์ ์ฌ๋์ด ๋๋ฆด์ง๋ ๋ชฐ๋ผ์" | |
# return f"์ ์ฌ๋: {similarity}, ๋งค์นญ ๊ฒฐ๊ณผ: {verified}\n{message}" | |
# iface = gr.Interface(fn=face_similarity, | |
# inputs=[gr.inputs.Image(shape=(224, 224)), gr.inputs.Image(shape=(224, 224))], | |
# outputs="text", | |
# title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ", | |
# description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์ ๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค.") | |
# iface.launch() | |
# import gradio as gr | |
# from deepface import DeepFace | |
# def face_similarity(img1, img2): | |
# result = DeepFace.verify(img1, img2) | |
# similarity = result["distance"] # ๋ฎ์์๋ก ๋ ์ ์ฌ | |
# verified = result["verified"] | |
# return f"์ ์ฌ๋: {similarity}, ๋งค์นญ ๊ฒฐ๊ณผ: {verified}" | |
# iface = gr.Interface(fn=face_similarity, | |
# inputs=[gr.inputs.Image(shape=(224, 224)), gr.inputs.Image(shape=(224, 224))], | |
# outputs="text", | |
# title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ", | |
# description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์ ๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค.") | |
# iface.launch() | |
# import gradio as gr | |
# from deepface import DeepFace | |
# import pandas as pd | |
# from PIL import Image | |
# import numpy as np | |
# # ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ ๋ฆฌ์คํธ | |
# results = [] | |
# def save_results(img1_path, img2_path, similarity): | |
# # ๊ฒฐ๊ณผ๋ฅผ ๊ธ๋ก๋ฒ ๋ฆฌ์คํธ์ ์ถ๊ฐ | |
# results.append([img1_path, img2_path, similarity]) | |
# # ๊ฒฐ๊ณผ๋ฅผ pandas DataFrame์ผ๋ก ๋ณํ | |
# df = pd.DataFrame(results, columns=['Image 1', 'Image 2', 'Similarity']) | |
# # DataFrame์ CSV ํ์ผ๋ก ์ ์ฅ | |
# df.to_csv('similarity_results.csv', index=False) | |
# def face_similarity(img1, img2): | |
# result = DeepFace.verify(img1, img2) | |
# similarity = result["distance"] # ๋ฎ์์๋ก ๋ ์ ์ฌ | |
# verified = result["verified"] | |
# # ์ด๋ฏธ์ง ํ์ผ ์ ์ฅ | |
# img1_path = f"img1_{len(results)}.jpg" | |
# img2_path = f"img2_{len(results)}.jpg" | |
# # Convert img1 and img2 to PIL.Image objects and save them | |
# img1_pil = Image.fromarray(img1.astype(np.uint8)) | |
# img2_pil = Image.fromarray(img2.astype(np.uint8)) | |
# img1_pil.save(img1_path) | |
# img2_pil.save(img2_path) | |
# # ๊ฒฐ๊ณผ ์ ์ฅ | |
# save_results(img1_path, img2_path, similarity) | |
# return f"์ ์ฌ๋: {similarity}, ์ธ์ฆ ๊ฒฐ๊ณผ: {verified}" | |
# iface = gr.Interface(fn=face_similarity, | |
# inputs=[gr.inputs.Image(shape=(224, 224)), gr.inputs.Image(shape=(224, 224))], | |
# outputs="text", | |
# title="์ผ๊ตด ์ ์ฌ๋ ์ธก์ ", | |
# description="๋ ์ผ๊ตด ์ด๋ฏธ์ง๋ฅผ ์ ๋ก๋ํด์ ์ ์ฌ๋๋ฅผ ์ธก์ ํฉ๋๋ค.") | |
# iface.launch() | |