File size: 1,226 Bytes
beacc91
 
 
 
112b1af
beacc91
 
 
 
 
 
 
 
bad91ae
 
 
 
 
 
beacc91
52b0325
 
beacc91
 
 
 
4ccd918
beacc91
52b0325
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()