File size: 891 Bytes
bc5e1ec
05b02db
bc5e1ec
05b02db
 
bc5e1ec
05b02db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from deepface import DeepFace

def calculate_similarity(image1, image2):
    # Analyze the two images for facial similarity
    try:
        result = DeepFace.verify(image1, image2, enforce_detection=False)
        similarity_percentage = result['distance'] * 100  # Higher distance means less similarity
        return 100 - similarity_percentage  # Convert distance to similarity percentage
    except Exception as e:
        return str(e)

# Create a Gradio interface
iface = gr.Interface(
    fn=calculate_similarity,
    inputs=[
        gr.inputs.Image(type="filepath", label="Image 1"),
        gr.inputs.Image(type="filepath", label="Image 2")
    ],
    outputs=gr.outputs.Textbox(label="Similarity Percentage"),
    title="Face Similarity Checker",
    description="Upload two images of faces to check their similarity."
)

# Launch the interface
iface.launch()