nithinraok commited on
Commit
9876bf6
1 Parent(s): 5869c85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -14,6 +14,9 @@ OUTPUT_OK = (
14
  <div class="container">
15
  <div class="row"><h1 style="text-align: center">The provided samples are</h1></div>
16
  <div class="row"><h1 class="text-success" style="text-align: center">Same Speakers!!!</h1></div>
 
 
 
17
  </div>
18
  """
19
  )
@@ -23,6 +26,8 @@ OUTPUT_FAIL = (
23
  <div class="container">
24
  <div class="row"><h1 style="text-align: center">The provided samples are from </h1></div>
25
  <div class="row"><h1 class="text-danger" style="text-align: center">Different Speakers!!!</h1></div>
 
 
26
  </div>
27
  """
28
  )
@@ -37,9 +42,22 @@ def compare_samples(path1, path2):
37
  if not (path1 and path2):
38
  return '<b style="color:red">ERROR: Please record audio for *both* speakers!</b>'
39
 
40
- output = model.verify_speakers(path1,path2,THRESHOLD)
41
-
42
- return OUTPUT_OK if output else OUTPUT_FAIL
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
 
45
  inputs = [
 
14
  <div class="container">
15
  <div class="row"><h1 style="text-align: center">The provided samples are</h1></div>
16
  <div class="row"><h1 class="text-success" style="text-align: center">Same Speakers!!!</h1></div>
17
+ <div class="row"><h1 class="display-1 text-success" style="text-align: center">similarity score: {:.1f}%</h1></div>
18
+ <div class="row"><tiny style="text-align: center">(Similarity score must be atleast 80% to be considered as same speaker)</small><div class="row">
19
+
20
  </div>
21
  """
22
  )
 
26
  <div class="container">
27
  <div class="row"><h1 style="text-align: center">The provided samples are from </h1></div>
28
  <div class="row"><h1 class="text-danger" style="text-align: center">Different Speakers!!!</h1></div>
29
+ <div class="row"><h1 class="display-1 text-danger" style="text-align: center">similarity score: {:.1f}%</h1></div>
30
+ <div class="row"><tiny style="text-align: center">(Similarity score must be atleast 80% to be considered as same speaker)</small><div class="row">
31
  </div>
32
  """
33
  )
 
42
  if not (path1 and path2):
43
  return '<b style="color:red">ERROR: Please record audio for *both* speakers!</b>'
44
 
45
+ embs1 = model.get_embedding(path1).squeeze()
46
+ embs2 = model.get_embedding(path2).squeeze()
47
+
48
+ #Length Normalize
49
+ X = embs1 / torch.linalg.norm(embs1)
50
+ Y = embs2 / torch.linalg.norm(embs2)
51
+
52
+ # Score
53
+ similarity_score = torch.dot(X, Y) / ((torch.dot(X, X) * torch.dot(Y, Y)) ** 0.5)
54
+ similarity_score = (similarity_score + 1) / 2
55
+
56
+ # Decision
57
+ if similarity_score >= THRESHOLD:
58
+ return OUTPUT_OK.format(similarity_score * 100)
59
+ else:
60
+ return OUTPUT_FAIL.format(similarity_score * 100)
61
 
62
 
63
  inputs = [