Commit
·
436cc00
1
Parent(s):
3aa1bbd
Update app.py
Browse files
app.py
CHANGED
@@ -20,17 +20,34 @@ model = pipeline('token-classification',model='neural-net-rahul/bert-finetuned-n
|
|
20 |
|
21 |
def predict(text):
|
22 |
result = []
|
|
|
|
|
23 |
for dicti in model(text):
|
24 |
entity,word = dicti['entity'],dicti['word']
|
25 |
-
if entity
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return result
|
35 |
|
36 |
gr.Interface(
|
|
|
20 |
|
21 |
def predict(text):
|
22 |
result = []
|
23 |
+
word1 = None
|
24 |
+
entity_past = None
|
25 |
for dicti in model(text):
|
26 |
entity,word = dicti['entity'],dicti['word']
|
27 |
+
if entity[0]=='B':
|
28 |
+
if word1 is not None:
|
29 |
+
if entity_past =='B-PER':
|
30 |
+
entity_past = 'Person'
|
31 |
+
elif entity_past =='B-ORG':
|
32 |
+
entity_past = 'Organization'
|
33 |
+
elif entity_past =='B-MISC':
|
34 |
+
entity_past = 'Miscellaneous'
|
35 |
+
elif entity_past =='B-LOC':
|
36 |
+
entity_past = 'Location'
|
37 |
+
result.append([word1,entity_past])
|
38 |
+
word1 = word;
|
39 |
+
entity_past = entity;
|
40 |
+
else:
|
41 |
+
word1 = word1 + word.lstrip("#");
|
42 |
+
if entity_past =='B-PER':
|
43 |
+
entity_past = 'Person'
|
44 |
+
elif entity_past =='B-ORG':
|
45 |
+
entity_past = 'Organization'
|
46 |
+
elif entity_past =='B-MISC':
|
47 |
+
entity_past = 'Miscellaneous'
|
48 |
+
elif entity_past =='B-LOC':
|
49 |
+
entity_past = 'Location'
|
50 |
+
result.append([word1,entity_past])
|
51 |
return result
|
52 |
|
53 |
gr.Interface(
|