File size: 8,425 Bytes
a05511c 0c753c1 a05511c 0c753c1 a05511c 0c753c1 a05511c 0c753c1 a05511c 51b0e83 16f1995 a05511c 16f1995 a05511c 226ba40 a05511c 28cdb03 a05511c a72d2fc a05511c a72d2fc a05511c 0c753c1 a05511c 16f1995 a05511c a72d2fc a05511c 16f1995 30d525f a05511c |
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
import gradio as gr
import os
import requests
from PIL import Image
def face_compare(frame1, frame2):
url = "https://face.miniai.live/api/face_match"
files = {'image1': open(frame1, 'rb'), 'image2': open(frame2, 'rb')}
r = requests.post(url=url, files=files)
response = r.json()
detections = response.get("detections", [])
matches = response.get("match", [])
detection_rows = ""
match_rows = ""
# Process detections
for detection in detections:
face_image = detection.get("face", "")
face_img_tag = f"<img src='data:image/png;base64,{face_image}' width='100' />" if face_image else "N/A"
first_face_index = detection.get("firstFaceIndex", "N/A")
second_face_index = detection.get("secondFaceIndex", "N/A")
detection_rows += f"""
<tr>
<td>{first_face_index}</td>
<td>{second_face_index}</td>
<td>{face_img_tag}</td>
</tr>
"""
# Process matches
for match in matches:
first_face_index = match.get("firstFaceIndex", "N/A")
second_face_index = match.get("secondFaceIndex", "N/A")
similarity = match.get("similarity", "N/A")
match_rows += f"""
<tr>
<td>{first_face_index}</td>
<td>{second_face_index}</td>
<td>{similarity:.6f}</td>
</tr>
"""
# Create HTML tables
detections_table = f"""
<h3>Face Detection</h3>
<table border="1" style="border-collapse: collapse; width: 100%;">
<tr>
<th>First Face Index</th>
<th>Second Face Index</th>
<th>Face Image</th>
</tr>
{detection_rows}
</table>
"""
matches_table = f"""
<h3>Matching Results</h3>
<table border="1" style="border-collapse: collapse; width: 100%;">
<tr>
<th>First Face Index</th>
<th>Second Face Index</th>
<th>Similarity</th>
</tr>
{match_rows}
</table>
"""
return detections_table + matches_table
def check_liveness(frame):
url = "https://facelive.miniai.live/api/check_liveness"
files = {'image': open(frame, 'rb')}
r = requests.post(url=url, files=files)
html = None
table_value = ""
for key, value in r.json().items():
row_value = ("<tr>"
"<td>{key}</td>"
"<td>{value}</td>"
"</tr>".format(key=key, value=value))
table_value = table_value + row_value
html = ("<table>"
"<tr>"
"<th style=""width:30%"">Field</th>"
"<th style=""width:50%"">Value</th>"
"</tr>"
"{table_value}"
"</table>".format(table_value=table_value))
return html
# APP Interface
with gr.Blocks() as MiniAIdemo:
gr.Markdown(
"""
<a href="https://miniai.live" style="display: flex; align-items: center;">
<img src="https://miniai.live/wp-content/uploads/2024/02/logo_name-1-768x426-1.png" style="width: 18%; margin-right: 15px;"/>
<div>
<p style="font-size: 40px; font-weight: bold; margin-right: 20px;">FaceRecognition-LivenessDetection SDK Demo</p>
<p style="font-size: 20px; margin-right: 0;">Experience our NIST FRVT Top Ranked FaceRecognition, iBeta 2 Certified Face Liveness Detection Engine</p>
</div>
</a>
<br/>
<div style="display: flex; justify-content: center; align-items: center;">
<table style="text-align: center;">
<tr>
<td style="text-align: center; vertical-align: middle;"><a href="https://github.com/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_git-1-300x67.png" style="height: 50px; margin-right: 5px;" title="GITHUB"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://huggingface.co/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_hugging-1-300x67.png" style="height: 50px; margin-right: 5px;" title="HuggingFace"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://demo.miniai.live"><img src="https://miniai.live/wp-content/uploads/2024/10/new_gradio-300x67.png" style="height: 50px; margin-right: 5px;" title="Gradio"/></a></td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;"><a href="https://docs.miniai.live/"><img src="https://miniai.live/wp-content/uploads/2024/10/a-300x70.png" style="height: 50px; margin-right: 5px;" title="Documentation"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://www.youtube.com/@miniailive"><img src="https://miniai.live/wp-content/uploads/2024/10/Untitled-1-300x70.png" style="height: 50px; margin-right: 5px;" title="Youtube"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://play.google.com/store/apps/dev?id=5831076207730531667"><img src="https://miniai.live/wp-content/uploads/2024/10/googleplay-300x62.png" style="height: 50px; margin-right: 5px;" title="Google Play"/></a></td>
</tr>
</table>
</div>
<br/>
"""
)
with gr.Tabs():
with gr.Tab("Face Recognition"):
with gr.Row():
with gr.Column():
im_match_in1 = gr.Image(type='filepath', height=300)
gr.Examples(
[
"images/compare/demo-pic22.jpg",
"images/compare/demo-pic60.jpg",
"images/compare/demo-pic35.jpg",
"images/compare/demo-pic33.jpg",
"images/compare/demo-pic34.jpg",
],
inputs=im_match_in1
)
with gr.Column():
im_match_in2 = gr.Image(type='filepath', height=300)
gr.Examples(
[
"images/compare/demo-pic41.jpg",
"images/compare/demo-pic32.jpg",
"images/compare/demo-pic39.jpg",
"images/compare/demo-pic61.jpg",
"images/compare/demo-pic40.jpg",
],
inputs=im_match_in2
)
with gr.Column():
txt_compare_out = gr.HTML()
btn_f_match = gr.Button("Check Comparing!", variant='primary')
btn_f_match.click(face_compare, inputs=[im_match_in1, im_match_in2], outputs=txt_compare_out)
with gr.Tab("Face Liveness Detection"):
with gr.Row():
with gr.Column():
im_liveness_in = gr.Image(type='filepath', height=300)
gr.Examples(
[
"images/liveness/f_real_andr.jpg",
"images/liveness/f_fake_andr_mask3d.jpg",
"images/liveness/f_fake_andr_monitor.jpg",
"images/liveness/f_fake_andr_outline.jpg",
"images/liveness/f_fake_andr_outline3d.jpg",
"images/liveness/1.jpg",
"images/liveness/3.png",
"images/liveness/4.jpg",
],
inputs=im_liveness_in
)
btn_f_liveness = gr.Button("Check Liveness!", variant='primary')
with gr.Column():
livness_result_output = gr.HTML()
btn_f_liveness.click(check_liveness, inputs=im_liveness_in, outputs=livness_result_output)
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiniAiLive%2FFaceRecognition-LivenessDetection-Demo"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiniAiLive%2FFaceRecognition-LivenessDetection-Demo&label=VISITORS&labelColor=%2337d67a&countColor=%23ff8a65&style=plastic&labelStyle=none" /></a>')
if __name__ == "__main__":
MiniAIdemo.launch() |