NCTCMumbai commited on
Commit
4a3bf6e
·
verified ·
1 Parent(s): eececca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -451,15 +451,19 @@ def classify_with_bart(text, candidate_labels):
451
  result = classifier(text, candidate_labels=candidate_labels, multi_label=True)
452
  top_scores = list(zip(result['labels'][:3], result['scores'][:3]))
453
  return {lbl: round(score * 100, 2) for lbl, score in top_scores}
454
-
 
 
 
 
455
  def classify_with_phi(text, label_info):
456
  prompt = f'Classify the below text of document: {text} Given Document types: {label_info}'
457
  response: RunResponse = phi_agent.run(prompt)
458
  result = response.content
459
  return {
460
- result.doc_type_1: round(result.confidence_1 , 2),
461
- result.doc_type_2: round(result.confidence_2 , 2),
462
- result.doc_type_3: round(result.confidence_3 , 2)
463
  }
464
 
465
  def process_file(input_file, classifier_choice):
 
451
  result = classifier(text, candidate_labels=candidate_labels, multi_label=True)
452
  top_scores = list(zip(result['labels'][:3], result['scores'][:3]))
453
  return {lbl: round(score * 100, 2) for lbl, score in top_scores}
454
+ def safe_round(value, digits=2):
455
+ try:
456
+ return round(float(value), digits)
457
+ except (TypeError, ValueError):
458
+ return 0.0
459
  def classify_with_phi(text, label_info):
460
  prompt = f'Classify the below text of document: {text} Given Document types: {label_info}'
461
  response: RunResponse = phi_agent.run(prompt)
462
  result = response.content
463
  return {
464
+ result.doc_type_1: safe_round(result.confidence_1),
465
+ result.doc_type_2: safe_round(result.confidence_2),
466
+ result.doc_type_3: safe_round(result.confidence_3),
467
  }
468
 
469
  def process_file(input_file, classifier_choice):