Duy-NM commited on
Commit
f54cab2
·
1 Parent(s): 0babc62

add gr load

Browse files
Files changed (1) hide show
  1. app.py +0 -72
app.py CHANGED
@@ -4,79 +4,7 @@ import gradio as gr
4
  from numpy.linalg import norm
5
  from gradio_client import Client
6
 
7
- os.environ['CUDA_LAUNCH_BLOCKING'] = '0'
8
- G = ['Female', 'Male']
9
-
10
  token = os.environ['token']
11
- client = Client("https://vtechai-face-demo.hf.space/", token)
12
-
13
- def analyze(im, conf=0.65, area="Asia", f_age=False, f_gender=False, f_emotion=False):
14
- im_path, jj = client.predict(im, conf, area, f_age, f_gender, f_emotion, fn_index=1)
15
- with open(jj) as f:
16
- jss = json.load(f)
17
- return im_path, jss
18
-
19
- def face_search(im1,im2, threshold):
20
- im3, im4, te = client.predict(im1, im2, threshold, fn_index=3)
21
- return im3, im4, te
22
-
23
-
24
- with gr.Blocks() as face_compare:
25
- with gr.Row():
26
- im1 = gr.Image(value="example/ronaldo.jpg", label='Register', type='filepath', height=300) #.style(full_width=True, height=300)
27
- im2 = gr.Image(value="example/face2.jpg", label='Image for Search', type='filepath', height=300) #.style(full_width=True, height=300)
28
-
29
- with gr.Row():
30
- im3 = gr.Image(label='Output', height=300) #.style(height=300, full_width=True, full_height=True)
31
- im4 = gr.Image(label='Output', height=300) #.style(height=300, full_width=True, full_height=True)
32
-
33
- sl = gr.Slider(0.3, 1, step=0.05, value=0.5, label='Face Matching Threshold')
34
- text = gr.Text(label="Output", interactive=False)
35
- with gr.Row():
36
- btn = gr.Button(value="Run")
37
- btn_clean = gr.ClearButton([im1, im2, im3, im4])
38
- btn.click(fn=face_search, inputs=[im1, im2, sl], outputs=[im3, im4, text])
39
- # btn2 = gr.Button(value="Check", link="https://manhduy160396.wixsite.com/vtech")
40
-
41
- # example
42
- gr.Examples(
43
- examples=[[
44
- os.path.join(os.path.dirname(__file__), "example/ronaldo.jpg"),
45
- os.path.join(os.path.dirname(__file__), "example/face2.jpg")
46
- ]],
47
- inputs=[im1, im2]
48
-
49
- )
50
-
51
- with gr.Blocks() as face_analyze:
52
- with gr.Row():
53
- im1 = gr.Image(shape=(300, 300), type='filepath', height=300, container=True)
54
- im2 = gr.Image(shape=(300, 300), height=300, container=True)
55
-
56
- with gr.Row():
57
- with gr.Column():
58
- area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
59
- cb_age = gr.Checkbox(label="Age", value=True)
60
- cb_gender = gr.Checkbox(label="Gender", value=True)
61
- cb_emotion = gr.Checkbox(label="Emotion", value=True)
62
- sl = gr.Slider(0, 1, step=0.05, value=0.65, label='Confidence Threshold')
63
-
64
- with gr.Column():
65
- js = gr.JSON(label="json")
66
-
67
- with gr.Row():
68
- btn = gr.Button(value="Run")
69
- btn_clean = gr.ClearButton([im1, im2])
70
-
71
- btn.click(fn=analyze, inputs=[im1, sl, area, cb_age, cb_gender, cb_emotion], outputs=[im2, js])
72
- # btn2 = gr.Button(value="Check", link="https://manhduy160396.wixsite.com/vtech")
73
-
74
-
75
- with gr.Blocks() as demo:
76
- gr.Markdown('<h1 style="text-align: center;">V-FaceSDK</h1>')
77
- gr.Markdown("*Chọn chức năng bạn muốn trải nghiệm")
78
- gr.TabbedInterface([face_analyze, face_compare], ["Face Analyze", "Face Compare"])
79
-
80
 
81
  if __name__ == "__main__":
82
  demo = gr.load("VTechAI/Face_demo", src="spaces", hf_token=token)
 
4
  from numpy.linalg import norm
5
  from gradio_client import Client
6
 
 
 
 
7
  token = os.environ['token']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  if __name__ == "__main__":
10
  demo = gr.load("VTechAI/Face_demo", src="spaces", hf_token=token)