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

update app

Browse files
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -16,15 +16,6 @@ ner_pipeline = pipeline(
16
  )
17
 
18
 
19
- # Helper function to print entities nicely
20
- def print_nicely(entities):
21
- entity_details = []
22
- for entity in entities:
23
- entity_info = f"Entity: {entity['entity']} | Confidence: {entity['score']:.2f}% | Text: {entity['word'].strip()} | Start: {entity['start']} | End: {entity['end']}"
24
- entity_details.append(entity_info)
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 = []
@@ -45,14 +36,8 @@ def prepare_entities_for_highlight(text, results):
45
  # Function to process the sentence and extract entities
46
  def extract_entities(sentence):
47
  results = ner_pipeline(sentence)
48
- entity_results = []
49
-
50
- # Extract and format the entities
51
- for key in results.keys():
52
- entity_results.append(print_nicely(results[key]))
53
 
54
- print(results)
55
- print(entity_results)
56
  return prepare_entities_for_highlight(sentence, results)
57
 
58
 
@@ -70,6 +55,11 @@ def ner_app_interface():
70
  outputs=output_entities,
71
  title="Named Entity Recognition",
72
  description="Enter a sentence to extract named entities using the NER model from the Impresso project.",
 
 
 
 
 
73
  )
74
 
75
  interface.launch()
 
16
  )
17
 
18
 
 
 
 
 
 
 
 
 
 
19
  # Helper function to flatten entities and prepare them for HighlightedText
20
  def prepare_entities_for_highlight(text, results):
21
  entities = []
 
36
  # Function to process the sentence and extract entities
37
  def extract_entities(sentence):
38
  results = ner_pipeline(sentence)
 
 
 
 
 
39
 
40
+ # Format the results for HighlightedText
 
41
  return prepare_entities_for_highlight(sentence, results)
42
 
43
 
 
55
  outputs=output_entities,
56
  title="Named Entity Recognition",
57
  description="Enter a sentence to extract named entities using the NER model from the Impresso project.",
58
+ examples=[
59
+ [
60
+ "In the year 1789, King Louis XVI, ruler of France, convened the Estates-General at the Palace of Versailles."
61
+ ]
62
+ ],
63
  )
64
 
65
  interface.launch()