NickKolok's picture
Update app.py
05b02db verified
raw
history blame
891 Bytes
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()