Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import json, os
|
4 |
-
import uuid
|
5 |
import numpy as np
|
|
|
|
|
6 |
|
7 |
from model import SiameseNetwork
|
8 |
from PIL import Image
|
@@ -72,7 +73,7 @@ def recognize(image_np):
|
|
72 |
results = []
|
73 |
for user in users:
|
74 |
db_emb = np.array(user["embedding"])
|
75 |
-
dist =
|
76 |
results.append((user["name"], user["matricule"], user["email"], round(dist, 4)))
|
77 |
|
78 |
if not results:
|
@@ -80,7 +81,7 @@ def recognize(image_np):
|
|
80 |
|
81 |
results.sort(key=lambda x: x[3]) # trie par distance
|
82 |
best = results[0]
|
83 |
-
if best[3] < 0.
|
84 |
return f"✅ Empreinte reconnue : {best[0]} (Matricule : {best[1]}, Email : {best[2]}) - Distance : {best[3]}"
|
85 |
else:
|
86 |
return f"❌ Aucune correspondance trouvée. Distance minimale : {best[3]}"
|
@@ -115,4 +116,4 @@ with gr.Blocks() as demo:
|
|
115 |
list_btn = gr.Button("Afficher")
|
116 |
list_btn.click(fn=list_users, outputs=user_list)
|
117 |
|
118 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import json, os
|
|
|
4 |
import numpy as np
|
5 |
+
import torch
|
6 |
+
import torch.nn.functional as F
|
7 |
|
8 |
from model import SiameseNetwork
|
9 |
from PIL import Image
|
|
|
73 |
results = []
|
74 |
for user in users:
|
75 |
db_emb = np.array(user["embedding"])
|
76 |
+
dist = F.pairwise_distance(torch.from_numpy(input_emb), torch.from_numpy(db_emb)).item()
|
77 |
results.append((user["name"], user["matricule"], user["email"], round(dist, 4)))
|
78 |
|
79 |
if not results:
|
|
|
81 |
|
82 |
results.sort(key=lambda x: x[3]) # trie par distance
|
83 |
best = results[0]
|
84 |
+
if best[3] < 0.7:
|
85 |
return f"✅ Empreinte reconnue : {best[0]} (Matricule : {best[1]}, Email : {best[2]}) - Distance : {best[3]}"
|
86 |
else:
|
87 |
return f"❌ Aucune correspondance trouvée. Distance minimale : {best[3]}"
|
|
|
116 |
list_btn = gr.Button("Afficher")
|
117 |
list_btn.click(fn=list_users, outputs=user_list)
|
118 |
|
119 |
+
demo.launch()
|