multimodalart HF staff commited on
Commit
3a4f548
1 Parent(s): 6cf0712

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ from insightface.app import FaceAnalysis
4
+ import torch
5
+
6
+ app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
7
+ app.prepare(ctx_id=0, det_size=(640, 640))
8
+
9
+ def calculate(photo):
10
+ image = cv2.imread(photo)
11
+ faces = app.get(image)
12
+ faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
13
+ return faceid_embeds
14
+
15
+ with gr.Blocks() as demo:
16
+ face_photo = gr.Image(label="Photo", type="filepath")
17
+ output = gr.JSON()
18
+ greet_btn = gr.Button("Calculate")
19
+ greet_btn.click(fn=calculate, inputs=face_photo, outputs=output, api_name="calculate_face_embedding")
20
+
21
+ if __name__ == "__main__":
22
+ demo.launch()