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