KevanSoon
commited on
Commit
·
c96690b
1
Parent(s):
9a92bef
integrated with frontend and springboot
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +26 -13
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -1,26 +1,39 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
from gradio_client import Client, handle_file
|
| 4 |
|
| 5 |
app = FastAPI()
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
result = client.predict(
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
sliced_str = str_[start_index:] if start_index != -1 else ""
|
| 22 |
import re
|
| 23 |
decimal_match = re.search(r"<td>(0?\.\d+)<\/td>", sliced_str)
|
| 24 |
decimal_number = float(decimal_match.group(1)) if decimal_match else None
|
| 25 |
print("Similarity decimal:", decimal_number)
|
| 26 |
-
|
|
|
|
|
|
| 1 |
+
import tempfile
|
| 2 |
+
from fastapi import FastAPI, File, UploadFile
|
| 3 |
from gradio_client import Client, handle_file
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
+
client = Client("kevansoon/FaceRecognition-LivenessDetection-Demo")
|
| 7 |
|
| 8 |
+
@app.post("/face-recognition")
|
| 9 |
+
async def face_recognition_post(image: UploadFile = File(...)):
|
| 10 |
+
# Save uploaded image to temp file
|
| 11 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
| 12 |
+
content = await image.read()
|
| 13 |
+
temp_file.write(content)
|
| 14 |
+
temp_filepath = temp_file.name
|
| 15 |
|
| 16 |
+
# Hardcoded second image URL
|
| 17 |
+
image2_url = "https://qvnhhditkzzeudppuezf.supabase.co/storage/v1/object/public/post-images/post-images/1752289670997-kevan.jpg"
|
| 18 |
+
|
| 19 |
+
# Call Gradio client with temp file path and URL wrapped in handle_file
|
| 20 |
result = client.predict(
|
| 21 |
+
frame1=handle_file(temp_filepath), # Pass local file path wrapped with handle_file
|
| 22 |
+
frame2=handle_file(image2_url), # Pass URL wrapped with handle_file
|
| 23 |
+
api_name="/face_compare"
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# Optional: remove temp file after use if desired
|
| 27 |
+
# import os
|
| 28 |
+
# os.unlink(temp_filepath)
|
| 29 |
+
|
| 30 |
+
# Parse the result string as before
|
| 31 |
+
str_ = result
|
| 32 |
+
start_index = str_.find("Similarity")
|
| 33 |
sliced_str = str_[start_index:] if start_index != -1 else ""
|
| 34 |
import re
|
| 35 |
decimal_match = re.search(r"<td>(0?\.\d+)<\/td>", sliced_str)
|
| 36 |
decimal_number = float(decimal_match.group(1)) if decimal_match else None
|
| 37 |
print("Similarity decimal:", decimal_number)
|
| 38 |
+
|
| 39 |
+
return {"result":str(decimal_number)}
|