File size: 4,468 Bytes
e8dfdf0
 
 
 
 
85b6cb5
 
e8dfdf0
 
85b6cb5
a75a347
23df74f
a75a347
23df74f
 
 
 
85b6cb5
e8dfdf0
 
 
 
 
 
 
 
 
85b6cb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23df74f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ac5477
 
63e4913
 
 
 
 
 
 
 
 
 
 
 
 
 
6ac5477
 
 
 
 
 
63e4913
 
 
 
 
 
 
 
 
 
 
 
 
 
6ac5477
 
 
 
 
 
 
 
 
63e4913
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import gradio as gr
from deepface import DeepFace

def face_similarity(img1, img2):
    result = DeepFace.verify(img1, img2)
    # distance ๊ฐ’์„ 1์—์„œ ๋นผ์„œ similarity๋กœ ์‚ฌ์šฉ
    similarity = 1 - result["distance"]  # ์ด์ œ ๋†’์„์ˆ˜๋ก ๋” ์œ ์‚ฌ
    verified = result["verified"]
    
    # ์œ ์‚ฌ๋„์— ๋”ฐ๋ฅธ ๋ฉ”์‹œ์ง€ ์กฐ๊ฑด ๋ถ„๊ธฐ, ์ด์ œ similarity ๊ฐ’์ด ๋†’์„์ˆ˜๋ก ์œ ์‚ฌํ•œ ๊ฒƒ์œผ๋กœ ์ฒ˜๋ฆฌ
    if similarity > 0.5:
        message = "๋‘ ๋ถ„์€ ์ฒœ์ƒ์—ฐ๋ถ„!"
    elif 0.4 < similarity <= 0.5:
        message = "๋‘ ๋ถ„์€ ๋‚ด๊บผ์ธ๋“ฏ ๋‚ด๊บผ์•„๋‹Œ ๋‚ด๊บผ๊ฐ™์€...?"
    else:
        message = "์˜คํžˆ๋ ค ์ข‹์•„! ์ •๋ฐ˜๋Œ€์˜ ์‚ฌ๋žŒ์ด ๋Œ๋ฆด์ง€๋„ ๋ชฐ๋ผ์š”"
    
    return f"์œ ์‚ฌ๋„: {similarity:.2f}, ๋งค์นญ ๊ฒฐ๊ณผ: {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"]
    
#     # ์œ ์‚ฌ๋„์— ๋”ฐ๋ฅธ ๋ฉ”์‹œ์ง€ ์กฐ๊ฑด ๋ถ„๊ธฐ
#     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()