emanuelaboros commited on
Commit
94113a9
·
1 Parent(s): aeeec0d

update app

Browse files
Files changed (1) hide show
  1. app.py +46 -38
app.py CHANGED
@@ -9,9 +9,9 @@ model = AutoModelForSeq2SeqLM.from_pretrained(
9
  print("Model loaded successfully!")
10
 
11
 
12
- def disambiguate_sentences(sentences):
13
  results = []
14
- for sentence in sentences:
15
  outputs = model.generate(
16
  **tokenizer([sentence], return_tensors="pt"),
17
  num_beams=5,
@@ -22,39 +22,47 @@ def disambiguate_sentences(sentences):
22
  return results
23
 
24
 
25
- demo = gr.Interface(
26
- fn=disambiguate_sentences,
27
- inputs=[
28
- gr.Textbox(
29
- label="Input Sentences:",
30
- lines=5,
31
- placeholder="Enter your sentence here in the following format: // << We are going to [START] Paris [END]. >>"
32
- " // This format ensures that the model knows which entities to disambiguate, more exactly the "
33
- "entity should be surrounded by `[START]` and `[END]`. // "
34
- "!Only one entity per sentence is supported at the moment!",
35
- )
36
- ],
37
- outputs=[gr.Textbox(label="Predictions")],
38
- title="Entity Linking with impresso-project/nel-hipe-multilingual",
39
- description="Link entities using the `impresso-project/nel-hipe-multilingual` model under the hood!",
40
- allow_flagging="never",
41
- # Here we introduce a new tag, examples, easy to use examples for your application
42
- examples=[
43
- "Des chercheurs de l' [START] Université de Cambridge [END] ont développé une nouvelle technique de calcul "
44
- "quantique qui promet d'augmenter exponentiellement les vitesses de calcul.",
45
- "Le rapport complet sur ces découvertes a été publié dans la prestigieuse revue 'Nature Physics'. ([START] "
46
- "Reuters [END])",
47
- "In the [START] year 1789 [END], the Estates-General was convened in France.",
48
- "[START] King Louis XVI, ruler of France [END], called for the meeting.",
49
- "The event was held at the [START] Palace of Versailles [END], a symbol of French monarchy.",
50
- "At Versailles, Marie Antoinette, the Queen of France, was involved in discussions.",
51
- "Maximilien Robespierre, a leading member of the National Assembly, also participated.",
52
- "[START] Jean-Jacques Rousseau, the famous philosopher [END], was a significant figure in the debate.",
53
- "Another important participant was [START] Charles de Talleyrand, the Bishop of Autun [END].",
54
- "Meanwhile, across the Atlantic, [START] George Washington, the first President of the United States [END], "
55
- "was shaping policies.",
56
- "[START] Thomas Jefferson, the nation's Secretary of State [END], played a key role in drafting policies for "
57
- "the new American government.",
58
- ],
59
- )
60
- demo.launch()
 
 
 
 
 
 
 
 
 
9
  print("Model loaded successfully!")
10
 
11
 
12
+ def disambiguate_sentence(sentence):
13
  results = []
14
+ for sentence in [sentence]:
15
  outputs = model.generate(
16
  **tokenizer([sentence], return_tensors="pt"),
17
  num_beams=5,
 
22
  return results
23
 
24
 
25
+ def nel_app_interface():
26
+ input_sentence = gr.Textbox(
27
+ lines=5,
28
+ label="Input Sentence",
29
+ placeholder="Enter your sentence here in the following format: // << We are going to [START] Paris [END]. >>"
30
+ " // This format ensures that the model knows which entities to disambiguate, more exactly the "
31
+ "entity should be surrounded by `[START]` and `[END]`. // "
32
+ "!Only one entity per sentence is supported at the moment!",
33
+ )
34
+ output_entities = gr.HighlightedText(label="Extracted Entities")
35
+
36
+ # Interface definition
37
+ interface = gr.Interface(
38
+ fn=disambiguate_sentence,
39
+ inputs=input_sentence,
40
+ outputs=output_entities,
41
+ title="Entity Linking with impresso-project/nel-hipe-multilingual",
42
+ description="Link entities using the `impresso-project/nel-hipe-multilingual` model under the hood!",
43
+ examples=[
44
+ [
45
+ "Des chercheurs de l' [START] Université de Cambridge [END] ont développé une nouvelle technique de calcul "
46
+ "quantique qui promet d'augmenter exponentiellement les vitesses de calcul.",
47
+ "Le rapport complet sur ces découvertes a été publié dans la prestigieuse revue 'Nature Physics'. ([START] "
48
+ "Reuters [END])",
49
+ "In the [START] year 1789 [END], the Estates-General was convened in France.",
50
+ "[START] King Louis XVI, ruler of France [END], called for the meeting.",
51
+ "The event was held at the [START] Palace of Versailles [END], a symbol of French monarchy.",
52
+ "At Versailles, Marie Antoinette, the Queen of France, was involved in discussions.",
53
+ "Maximilien Robespierre, a leading member of the National Assembly, also participated.",
54
+ "[START] Jean-Jacques Rousseau, the famous philosopher [END], was a significant figure in the debate.",
55
+ "Another important participant was [START] Charles de Talleyrand, the Bishop of Autun [END].",
56
+ "Meanwhile, across the Atlantic, [START] George Washington, the first President of the United States [END], "
57
+ "was shaping policies.",
58
+ "[START] Thomas Jefferson, the nation's Secretary of State [END], played a key role in drafting policies for "
59
+ "the new American government.",
60
+ ]
61
+ ],
62
+ )
63
+
64
+ interface.launch()
65
+
66
+
67
+ if __name__ == "__main__":
68
+ nel_app_interface()