arunavsk1 commited on
Commit
8bf6f92
1 Parent(s): 18fbe0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -42,7 +42,7 @@ model_checkpoint = st.sidebar.radio("", model_list)
42
  # aggregation = st.sidebar.radio("", ('first', 'simple', 'average', 'max', 'none'))
43
 
44
  # st.sidebar.write("Please refer 'https://huggingface.co/transformers/_modules/transformers/pipelines/token_classification.html' for entity grouping with aggregation_strategy parameter.")
45
- aggregation = 'first'
46
  st.subheader("Select Text Input Method")
47
  input_method = st.radio("", ('Select from Examples', 'Write or Paste New Text'))
48
  if input_method == 'Select from Examples':
@@ -89,12 +89,24 @@ if Run_Button == True:
89
 
90
  for entity in output:
91
  if aggregation != "none":
92
- spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity["entity_group"]})
93
  else:
94
- spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity["entity"]})
95
-
96
- entity_list = ["PER", "LOC", "ORG", "MISC"]
97
- colors = {'PER': '#85DCDF', 'LOC': '#DF85DC', 'ORG': '#DCDF85', 'MISC': '#85ABDF',}
 
 
 
 
 
 
 
 
 
 
 
 
98
  html = spacy.displacy.render(spacy_display, style="ent", minify=True, manual=True, options={"ents": entity_list, "colors": colors})
99
  style = "<style>mark.entity { display: inline-block }</style>"
100
  st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)
 
42
  # aggregation = st.sidebar.radio("", ('first', 'simple', 'average', 'max', 'none'))
43
 
44
  # st.sidebar.write("Please refer 'https://huggingface.co/transformers/_modules/transformers/pipelines/token_classification.html' for entity grouping with aggregation_strategy parameter.")
45
+ aggregation = 'none'
46
  st.subheader("Select Text Input Method")
47
  input_method = st.radio("", ('Select from Examples', 'Write or Paste New Text'))
48
  if input_method == 'Select from Examples':
 
89
 
90
  for entity in output:
91
  if aggregation != "none":
92
+ spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity_map[entity["entity_group"]]})
93
  else:
94
+ spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity_map[entity["entity"]]})
95
+
96
+ entity_map = {'LABEL_0': 'O',
97
+ 'LABEL_1': 'B-Intervention',
98
+ 'LABEL_2': 'I-Intervention',
99
+ 'LABEL_3': 'B-Outcome',
100
+ 'LABEL_4': 'I-Outcome',
101
+ 'LABEL_5': 'B-Values',
102
+ 'LABEL_6': 'I-Value'}
103
+
104
+ colors = {'B-Intervention': '#85DCDF',
105
+ 'I-Intervention': '#85DCDF',
106
+ 'B-Outcome': '#DF85DC',
107
+ 'I-Outcome': '#DF85DC',
108
+ 'B-Value': '#DCDF85',
109
+ 'I-Value': '#DCDF85'}
110
  html = spacy.displacy.render(spacy_display, style="ent", minify=True, manual=True, options={"ents": entity_list, "colors": colors})
111
  style = "<style>mark.entity { display: inline-block }</style>"
112
  st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)