emanuelaboros commited on
Commit
49dd9a6
·
1 Parent(s): c126670

update app

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -25,6 +25,23 @@ def print_nicely(entities):
25
  return "\n".join(entity_details)
26
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  # Function to process the sentence and extract entities
29
  def extract_entities(sentence):
30
  results = ner_pipeline(sentence)
@@ -36,7 +53,7 @@ def extract_entities(sentence):
36
 
37
  print(results)
38
  print(entity_results)
39
- return results
40
 
41
 
42
  # Create Gradio interface
 
25
  return "\n".join(entity_details)
26
 
27
 
28
+ # Helper function to flatten entities and prepare them for HighlightedText
29
+ def prepare_entities_for_highlight(text, results):
30
+ entities = []
31
+ for category, entity_list in results.items():
32
+ for entity in entity_list:
33
+ # Appending each entity's word, start and end for highlighting, including the entity label and score
34
+ entities.append(
35
+ (
36
+ entity["start"],
37
+ entity["end"],
38
+ f"{entity['entity']} ({entity['score']:.2f}%)",
39
+ )
40
+ )
41
+
42
+ return {"text": text, "entities": entities}
43
+
44
+
45
  # Function to process the sentence and extract entities
46
  def extract_entities(sentence):
47
  results = ner_pipeline(sentence)
 
53
 
54
  print(results)
55
  print(entity_results)
56
+ return prepare_entities_for_highlight(sentence, results)
57
 
58
 
59
  # Create Gradio interface