File size: 811 Bytes
3a4f548
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07d380e
 
 
 
 
 
 
3a4f548
 
 
 
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
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()