Mike commited on
Commit
0509158
1 Parent(s): d8a5533

add files to spaces.

Browse files
Files changed (2) hide show
  1. app.py +57 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ token_skill_classifier = pipeline(model="jjzha/escoxlmr_skill_extraction", aggregation_strategy="first")
5
+ token_knowledge_classifier = pipeline(model="jjzha/escoxlmr_knowledge_extraction", aggregation_strategy="first")
6
+
7
+
8
+ examples = [
9
+ "Knowing Python is a plus",
10
+ "Recommend changes, develop and implement processes to ensure compliance with IFRS standards"
11
+ ]
12
+
13
+
14
+ def aggregate_span(results):
15
+ new_results = []
16
+ current_result = results[0]
17
+
18
+ for result in results[1:]:
19
+ if result["start"] == current_result["end"] + 1:
20
+ current_result["word"] += " " + result["word"]
21
+ current_result["end"] = result["end"]
22
+ else:
23
+ new_results.append(current_result)
24
+ current_result = result
25
+
26
+ new_results.append(current_result)
27
+
28
+ return new_results
29
+
30
+
31
+ def ner(text):
32
+ output_skills = token_skill_classifier(text)
33
+ for result in output_skills:
34
+ if result.get("entity_group"):
35
+ result["entity"] = "Skill"
36
+ del result["entity_group"]
37
+
38
+ output_knowledge = token_knowledge_classifier(text)
39
+ for result in output_knowledge:
40
+ if result.get("entity_group"):
41
+ result["entity"] = "Knowledge"
42
+ del result["entity_group"]
43
+
44
+ if len(output_skills) > 0:
45
+ output_skills = aggregate_span(output_skills)
46
+ if len(output_knowledge) > 0:
47
+ output_knowledge = aggregate_span(output_knowledge)
48
+
49
+ return {"text": text, "entities": output_skills}, {"text": text, "entities": output_knowledge}
50
+
51
+
52
+ demo = gr.Interface(fn=ner,
53
+ inputs=gr.Textbox(placeholder="Enter sentence here..."),
54
+ outputs=["highlight", "highlight"],
55
+ examples=examples)
56
+
57
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ gradio
3
+ torch