emanuelaboros commited on
Commit
06e9286
Β·
1 Parent(s): b251121

first version of the app

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. x +0 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("impresso-project/nel-hipe-multilingual")
5
+ model = AutoModelForSeq2SeqLM.from_pretrained(
6
+ "impresso-project/nel-hipe-multilingual"
7
+ ).eval()
8
+
9
+
10
+ def disambiguate_sentences(sentences):
11
+ results = []
12
+ for sentence in sentences:
13
+ outputs = model.generate(
14
+ **tokenizer([sentence], return_tensors="pt"),
15
+ num_beams=5,
16
+ num_return_sequences=5
17
+ )
18
+ decoded = tokenizer.batch_decode(outputs, skip_special_tokens=True)
19
+ results.append(decoded)
20
+ return results
21
+
22
+
23
+ input_sentences = gr.inputs.Textbox(
24
+ lines=5,
25
+ label="Input Sentences",
26
+ placeholder="Enter your sentence here in the following format: \\ `It is reported in [START] Paris [END], "
27
+ "that the opening of the chambers will take place on the 27th January.' \\ "
28
+ "This format ensures that the model knows which entities to disambiguate, more exactly the entity should "
29
+ "be surrounded by `[START]` and `[END]`.",
30
+ )
31
+ output_predictions = gr.outputs.Textbox(label="Predictions")
32
+
33
+ gr.Interface(
34
+ fn=disambiguate_sentences,
35
+ inputs=input_sentences,
36
+ outputs=output_predictions,
37
+ title="NEL Disambiguation",
38
+ ).launch()
x DELETED
File without changes