CupidAI / app.py
suinY00N's picture
Update app.py
bad91ae verified
raw
history blame
1.23 kB
import gradio as gr
import face_recognition
import numpy as np
from PIL import Image
def match_faces(image1, image2):
# ์ด๋ฏธ์ง€์—์„œ ์–ผ๊ตด ์ธ์‹ ๋ฐ ํŠน์ง• ์ถ”์ถœ
face_encoding1 = face_recognition.face_encodings(image1)[0]
face_encoding2 = face_recognition.face_encodings(image2)[0]
# ๋‘ ์–ผ๊ตด ๊ฐ„์˜ ์œ ์‚ฌ๋„ ์ธก์ • (์œ ํด๋ฆฌ๋””์•ˆ ๊ฑฐ๋ฆฌ)
distance = np.linalg.norm(face_encoding1 - face_encoding2)
# ์œ ํด๋ฆฌ๋””์•ˆ ๊ฑฐ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์œ ์‚ฌ๋„ ๊ณ„์‚ฐ (0์— ๊ฐ€๊นŒ์šธ์ˆ˜๋ก ๋น„์Šทํ•จ)
# ์œ ์‚ฌ๋„๋ฅผ ๋ฐฑ๋ถ„์œจ๋กœ ๋ณ€ํ™˜ (์ด ๋ฐฉ์‹์€ ์˜ˆ์ œ๋กœ, ์‹ค์ œ ์‘์šฉ์—์„œ ๋” ์ •๊ตํ•œ ๋ฐฉ๋ฒ•์ด ํ•„์š”ํ•  ์ˆ˜ ์žˆ์Œ)
# ์ฐธ๊ณ : 0.6์€ ๊ฒฝํ—˜์ ์œผ๋กœ ์–ผ๊ตด์ด ๋งค์šฐ ๋น„์Šทํ•˜๋‹ค๊ณ  ํŒ๋‹จ๋˜๋Š” ์ž„๊ณ„๊ฐ’์ž…๋‹ˆ๋‹ค. ์ด ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์œ ์‚ฌ๋„๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
similarity = max(0, 100 - (distance / 0.6) * 100)
return f"๋‘ ์–ผ๊ตด์˜ ์œ ์‚ฌ๋„๋Š” {similarity:.2f}% ์ž…๋‹ˆ๋‹ค."
return f"์œ ์‚ฌ๋„: {similarity:.2f}%"
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
iface = gr.Interface(fn=match_faces,
inputs=[gr.inputs.Image(shape=(224, 224)), gr.inputs.Image(shape=(224, 224))],
outputs="text")
iface.launch()