Spaces:
Sleeping
Sleeping
import gradio as gr | |
import cv2 | |
from insightface.app import FaceAnalysis | |
import torch | |
app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider']) | |
app.prepare(ctx_id=0, det_size=(640, 640)) | |
def calculate(photo): | |
image = cv2.imread(photo) | |
faces = app.get(image) | |
faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0) | |
return faceid_embeds | |
with gr.Blocks() as demo: | |
with gr.Row(): | |
with gr.Column(): | |
face_photo = gr.Image(label="Photo", type="filepath") | |
greet_btn = gr.Button("Calculate") | |
with gr.Column(): | |
output = gr.JSON() | |
greet_btn.click(fn=calculate, inputs=face_photo, outputs=output, api_name="calculate_face_embedding") | |
if __name__ == "__main__": | |
demo.launch() |