faceplugin commited on
Commit
947d84d
1 Parent(s): 77fe87f

Add faceliveness detection

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -27,6 +27,23 @@ def face_recognition_on_file(file1, file2):
27
  raise gr.Error("Invalid response from server")
28
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  with gr.Blocks() as demo:
31
  gr.Markdown(
32
  """
@@ -75,6 +92,17 @@ with gr.Blocks() as demo:
75
  app_output = [gr.JSON()]
76
 
77
  start_button.click(face_recognition_on_file, inputs=[first_input, second_input], outputs=app_output)
 
 
 
 
 
 
 
 
 
 
 
78
 
79
 
80
  gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFacePlugin-Ltd%2FFacePlugin-Face-Recognition-SDK"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFacePlugin-Ltd%2FFacePlugin-Face-Recognition-SDK&labelColor=%23697689&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
 
27
  raise gr.Error("Invalid response from server")
28
 
29
 
30
+ def liveness_detection_on_file(file):
31
+ url = "http://93.127.215.33:8080/check_liveness"
32
+ try:
33
+ files = {'file': open(file, 'rb')}
34
+ r = requests.post(url=url, files=files)
35
+ r.raise_for_status() # Raise an exception for bad status codes
36
+ except requests.RequestException as e:
37
+ raise gr.Error(f"Error occurred: {str(e)}")
38
+
39
+ try:
40
+ response = r.json()
41
+ print(response)
42
+ return response
43
+ except json.JSONDecodeError:
44
+ raise gr.Error("Invalid response from server")
45
+
46
+
47
  with gr.Blocks() as demo:
48
  gr.Markdown(
49
  """
 
92
  app_output = [gr.JSON()]
93
 
94
  start_button.click(face_recognition_on_file, inputs=[first_input, second_input], outputs=app_output)
95
+ with gr.TabItem("Face Liveness Detection"):
96
+ with gr.Row():
97
+ with gr.Column():
98
+ app_input = gr.Image(type='filepath')
99
+ gr.Examples(['images/4.jpg', 'images/1.png', 'images/2.png', 'images/3.png'],
100
+ inputs=app_input)
101
+ start_button = gr.Button("Run")
102
+ with gr.Column():
103
+ app_output = [gr.JSON()]
104
+
105
+ start_button.click(liveness_detection_on_file, inputs=app_input, outputs=app_output)
106
 
107
 
108
  gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFacePlugin-Ltd%2FFacePlugin-Face-Recognition-SDK"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFacePlugin-Ltd%2FFacePlugin-Face-Recognition-SDK&labelColor=%23697689&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')