faceplugin commited on
Commit
c00995a
1 Parent(s): 5143658
Files changed (1) hide show
  1. app.py +15 -46
app.py CHANGED
@@ -1,6 +1,4 @@
1
  import sys
2
- sys.path.append('.')
3
- sys.path.append('./face_recognition')
4
  import os
5
  import io
6
  import cv2
@@ -14,33 +12,26 @@ import configparser
14
  import numpy as np
15
  from PIL import Image
16
 
17
- # from face_recognition.match import match_1_1
18
- # from face_recognition1.run import match_image
19
-
20
 
21
  def face_recognition_on_file(file1, file2):
22
- img1 = cv2.imread(file1)
23
- img2 = cv2.imread(file2)
24
-
25
- response = match_1_1(img1, img2)
26
-
27
- return response
28
-
29
- def liveness_detection_on_file(file1, file2):
30
- img1 = cv2.imread(file1)
31
- img2 = cv2.imread(file2)
32
-
33
- response = match_1_1(img1, img2)
34
 
35
- return response
 
 
 
 
 
36
 
37
- def mrz_recognition_on_file(file1, file2):
38
- img1 = cv2.imread(file1)
39
- img2 = cv2.imread(file2)
 
 
 
40
 
41
- response = match_1_1(img1, img2)
42
-
43
- return response
44
 
45
  with gr.Blocks() as demo:
46
  gr.Markdown(
@@ -66,26 +57,4 @@ with gr.Blocks() as demo:
66
  app_output = [gr.JSON()]
67
 
68
  start_button.click(face_recognition_on_file, inputs=[first_input, second_input], outputs=app_output)
69
- with gr.TabItem("Face Liveness Detection"):
70
- with gr.Row():
71
- with gr.Column():
72
- app_input = gr.Image(type='filepath')
73
- gr.Examples(['images/4.jpg', 'images/1.png', 'images/2.png', 'images/3.png'],
74
- inputs=app_input)
75
- start_button = gr.Button("Run")
76
- with gr.Column():
77
- app_output = [gr.JSON()]
78
-
79
- start_button.click(liveness_detection_on_file, inputs=app_input, outputs=app_output)
80
- with gr.TabItem("ID Document Recognition"):
81
- with gr.Row():
82
- with gr.Column():
83
- app_input = gr.Image(type='pil')
84
- gr.Examples(['images/mrz_1.jpg', 'images/mrz_2.png', 'images/mrz_3.jpeg', 'images/mrz_4.jpg'],
85
- inputs=app_input)
86
- start_button = gr.Button("Run")
87
- with gr.Column():
88
- app_output = [gr.JSON()]
89
-
90
- start_button.click(mrz_recognition_on_file, inputs=app_input, outputs=app_output)
91
  demo.queue().launch(share=True)
 
1
  import sys
 
 
2
  import os
3
  import io
4
  import cv2
 
12
  import numpy as np
13
  from PIL import Image
14
 
 
 
 
15
 
16
  def face_recognition_on_file(file1, file2):
17
+ url = "http://93.127.215.33:8080/face_recognition"
18
+ try:
19
+ files = {'file1': open(file1, 'rb'), 'file2': open(file2, 'rb')}
 
 
 
 
 
 
 
 
 
20
 
21
+ r = requests.post(url=url, files=files)
22
+ r.raise_for_status() # Raise an exception for bad status codes
23
+ except requests.RequestException as e:
24
+ raise gr.Error(f"Error occurred: {str(e)}")
25
+ except IOError:
26
+ raise gr.Error("Please select valid image files!")
27
 
28
+ try:
29
+ response = r.json()
30
+ print(response)
31
+ return response
32
+ except json.JSONDecodeError:
33
+ raise gr.Error("Invalid response from server")
34
 
 
 
 
35
 
36
  with gr.Blocks() as demo:
37
  gr.Markdown(
 
57
  app_output = [gr.JSON()]
58
 
59
  start_button.click(face_recognition_on_file, inputs=[first_input, second_input], outputs=app_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  demo.queue().launch(share=True)