neural-net-rahul commited on
Commit
436cc00
·
1 Parent(s): 3aa1bbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
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 == "B-PER" or entity=='I-PER':
26
- entity = "Person"
27
- elif entity == "B-LOC" or entity=='I-LOC':
28
- entity = "Location"
29
- elif entity == "B-ORG" or entity=='I-ORG':
30
- entity = "Organization"
31
- elif entity == "B-MISC" or entity=='I-MISC':
32
- entity = "Miscellaneous"
33
- result.append({entity,word})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(