Keyurjotaniya007 commited on
Commit
b0050c0
·
verified ·
1 Parent(s): f75ccf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -6
app.py CHANGED
@@ -1,19 +1,17 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- ner = pipeline('ner')
5
 
6
  def merge_tokens(tokens):
7
  merged_tokens = []
8
  for token in tokens:
9
  if merged_tokens and token['entity'].startswith('I-') and merged_tokens[-1]['entity'].endswith(token['entity'][2:]):
10
- # If current token continues the entity of the last one, merge them
11
  last_token = merged_tokens[-1]
12
  last_token['word'] += token['word'].replace('##', '')
13
  last_token['end'] = token['end']
14
  last_token['score'] = (last_token['score'] + token['score']) / 2
15
  else:
16
- # Otherwise, add the token to the list
17
  merged_tokens.append(token)
18
 
19
  return merged_tokens
@@ -26,6 +24,5 @@ def named(input):
26
  a = gr.Interface(fn=named,
27
  inputs=[gr.Textbox(label="Text input", lines= 2)],
28
  outputs=[gr.HighlightedText(label='Text with entities')],
29
- title='Named Entity Recognition', examples=["My name is Andrew, I'm building DeeplearningAI and I live in California", "My name is Poli, I live in Vienna and work at HuggingFace"])
30
- a.launch()
31
-
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ ner = pipeline('ner', model = "Keyurjotaniya007/xlm-roberta-base-xtreme-multilingual-ner-2.0")
5
 
6
  def merge_tokens(tokens):
7
  merged_tokens = []
8
  for token in tokens:
9
  if merged_tokens and token['entity'].startswith('I-') and merged_tokens[-1]['entity'].endswith(token['entity'][2:]):
 
10
  last_token = merged_tokens[-1]
11
  last_token['word'] += token['word'].replace('##', '')
12
  last_token['end'] = token['end']
13
  last_token['score'] = (last_token['score'] + token['score']) / 2
14
  else:
 
15
  merged_tokens.append(token)
16
 
17
  return merged_tokens
 
24
  a = gr.Interface(fn=named,
25
  inputs=[gr.Textbox(label="Text input", lines= 2)],
26
  outputs=[gr.HighlightedText(label='Text with entities')],
27
+ title='Multilingual NER', examples=["My name is Keyur Jotaniya, and I live in Rajkot."])
28
+ a.launch()