jonathanjordan21 commited on
Commit
d661834
·
verified ·
1 Parent(s): e63081c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -435,6 +435,11 @@ def respond(
435
  scores = cos_sim(codes_emb, text_emb).mean(axis=-1)#[:,0]
436
 
437
  scores_argsort = scores.argsort(descending=True)
 
 
 
 
 
438
  #[::-1]
439
 
440
  if is_multiple:
@@ -443,17 +448,22 @@ def respond(
443
  request_scores = []
444
  # request_undetected = False
445
  # for i,score in enumerate(scores):
446
- for i in scores_argsort:
447
- if len(request_scores) >= n_num:
448
- break
449
- if scores[i] > threshold:
450
- request_details.append(codes[i][6:])
451
- request_numbers.append(codes[i][:3])
452
- request_scores.append(str( round(scores[i].tolist(), 3) ) )
453
-
454
- if not request_details:
455
  request_details.append(undetected[6:])
456
  request_numbers.append(undetected_code)
 
 
 
 
 
 
 
 
 
 
 
 
 
457
 
458
 
459
  request_numbers_copy = request_numbers
 
435
  scores = cos_sim(codes_emb, text_emb).mean(axis=-1)#[:,0]
436
 
437
  scores_argsort = scores.argsort(descending=True)
438
+
439
+ if n_num == 0:
440
+ std = scores.std()
441
+ else:
442
+ std = 0
443
  #[::-1]
444
 
445
  if is_multiple:
 
448
  request_scores = []
449
  # request_undetected = False
450
  # for i,score in enumerate(scores):
451
+ if scores[scores_argsort[0]] < threshold:
 
 
 
 
 
 
 
 
452
  request_details.append(undetected[6:])
453
  request_numbers.append(undetected_code)
454
+ else:
455
+ for i in scores_argsort:
456
+ if scores[scores_argsort[0]] <= scores[i] - std:
457
+ request_details.append(codes[i][6:])
458
+ request_numbers.append(codes[i][:3])
459
+ request_scores.append(str( round(scores[i].tolist(), 3) ) )
460
+ else:
461
+ if len(request_scores) >= n_num:
462
+ break
463
+ if scores[i] > threshold:
464
+ request_details.append(codes[i][6:])
465
+ request_numbers.append(codes[i][:3])
466
+ request_scores.append(str( round(scores[i].tolist(), 3) ) )
467
 
468
 
469
  request_numbers_copy = request_numbers