elnasharomar2 commited on
Commit
335b9ea
·
verified ·
1 Parent(s): e235a79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -9,6 +9,10 @@ login(token = api_key)
9
 
10
 
11
  get_completion = pipeline("ner", model="elnasharomar2/PUNCERT_single_stages_50_epochs")
 
 
 
 
12
 
13
  def merge_tokens(tokens):
14
  merged_tokens = []
@@ -28,7 +32,17 @@ def merge_tokens(tokens):
28
  def ner(input):
29
  output = get_completion(input)
30
  merged_tokens = merge_tokens(output)
31
- return {"text": input, "entities": merged_tokens}
 
 
 
 
 
 
 
 
 
 
32
 
33
  gr.close_all()
34
  demo = gr.Interface(fn=ner,
 
9
 
10
 
11
  get_completion = pipeline("ner", model="elnasharomar2/PUNCERT_single_stages_50_epochs")
12
+ label_names = ["O","QE","EX","QM","DOT","COM","SEMICOL","COL"]
13
+ label_symbol = ["O",'؟!','!','؟','.','،','؛',':']
14
+
15
+ id2label = {i: label for i, label in zip(label_names,label_symbol)}
16
 
17
  def merge_tokens(tokens):
18
  merged_tokens = []
 
32
  def ner(input):
33
  output = get_completion(input)
34
  merged_tokens = merge_tokens(output)
35
+ ## modification
36
+ result =""
37
+ idx = 0
38
+ for i in output:
39
+ result += text[idx:i["start"]]
40
+ result += text[i["start"]:i["end"]] + f"{id2label[i["entity_group"]]}"
41
+ idx = i["end"]
42
+ result+=text[idx:]
43
+ print(result)
44
+ return {"text": result}
45
+ # return {"text": input, "entities": merged_tokens}
46
 
47
  gr.close_all()
48
  demo = gr.Interface(fn=ner,