Johannes commited on
Commit
733a1a0
1 Parent(s): 701e0e6
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +50 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: Borrowing Detection Es
3
- emoji: 📈
4
- colorFrom: gray
5
  colorTo: purple
6
  sdk: gradio
7
  sdk_version: 3.19.1
 
1
  ---
2
  title: Borrowing Detection Es
3
+ emoji: 🔍
4
+ colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
7
  sdk_version: 3.19.1
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
2
+ import gradio as gr
3
+ from spacy import displacy
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("lirondos/anglicisms-spanish-mbert")
6
+ model = AutoModelForTokenClassification.from_pretrained(
7
+ "lirondos/anglicisms-spanish-mbert"
8
+ )
9
+ nlp = pipeline("ner", model=model, tokenizer=tokenizer)
10
+
11
+ diplacy_dict_template = {
12
+ "text": "But Google is starting from behind.",
13
+ "ents": [{"start": 4, "end": 10, "label": "ORG"}],
14
+ "title": None,
15
+ }
16
+
17
+
18
+ def infer(input_text):
19
+ displacy_ents = []
20
+ borrowings = nlp(input_text)
21
+ for borrowing in borrowings:
22
+ displacy_ent_dict = {
23
+ "start": borrowing["start"],
24
+ "end": borrowing["end"],
25
+ "label": borrowing["entity"],
26
+ }
27
+ displacy_ents.append(displacy_ent_dict)
28
+
29
+ displacy_dict_template = {"text": input_text, "ents": displacy_ents, "title": None}
30
+
31
+ html = displacy.render(displacy_dict_template, style="ent", page=True, manual=True)
32
+
33
+ html = (
34
+ ""
35
+ + html
36
+ + ""
37
+ )
38
+
39
+ return html
40
+
41
+
42
+ demo = gr.Interface(
43
+ title="Borrowing Detection Español",
44
+ fn=infer,
45
+ inputs=gr.Text(),
46
+ outputs=gr.HTML(),
47
+ examples=["Buscamos data scientist para proyecto de machine learning."],
48
+ )
49
+
50
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ spacy