kandysh commited on
Commit
221305c
1 Parent(s): e513330

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -49
app.py CHANGED
@@ -4,55 +4,43 @@ import json
4
  from normalizer import process_df
5
  from process_tags import list_ents, no_of_tags, color_creator, scatter_document
6
 
7
- tags_data = {
8
- "_dtags_": [],
9
- "DEP": [],
10
- "dep_explain": {},
11
- "_ptags_": [],
12
- "POS": [],
13
- "pos_explain": {},
14
- "_ntags_": ["concept", "tool", "framework", "crew", "position", "measurement", "artifact", "datasheet", "briefing", "standard", "insight", "client", "output", "output_component", "system", "challenge", "environment", "process", "process_component", "activity", "business_need", "third_party", "agreement", "raw_data", "authority", "resource_pool", "field_of_study", "geo_loc", "TBD"],
15
- "NER": ["concept", "#e3648a", "tool", "#d56b2e", "framework", "#ff0000", "crew", "#ffafcc", "position", "#a2cd5a", "measurement", "#779be7", "artifact", "#bee1e6", "datasheet", "#7e7d61", "briefing", "#4b8d76", "standard", "#9381ff", "insight", "#ffc125", "client", "#ffc6ff", "output", "#ffcfd2", "output_component", "#fde4cf", "system", "#656e1b", "challenge", "#ff5400", "environment", "#affc41", "process", "#adc178", "process_component", "#dde5b6", "activity", "#cfbaf0", "business_need", "#ced4da", "third_party", "#ee00ee", "agreement", "#484676", "raw_data", "#cdad00", "authority", "#d689c4", "resource_pool", "#8ea44c", "field_of_study", "#c39fe9", "geo_loc", "#c0ff3e", "TBD", "#ccdbfd"],
16
- "ner_explain": {},
17
- "_ctags_": [],
18
- "CAT": [],
19
- "cat_explain": {}
20
- }
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
 
24
- st.set_page_config(layout='wide')
25
- st.title("My Tag Visualizer")
26
- with st.sidebar:
27
- uploaded_file = st.file_uploader("Upload the sentence Json", type="json")
28
- # uploaded_color = st.file_uploader("Upload the tag Json", type="json")
29
- if uploaded_file is not None:
30
- raw_data = json.load(uploaded_file)
31
- # tags_data = json.load(uploaded_color)
32
- df_list = []
33
- key = 0
34
- for data in raw_data:
35
- df_list.append(process_df(data))
36
- st.plotly_chart(scatter_document(df_list, tags_data), use_container_width=True)
37
- tags = []
38
- ent = []
39
- for df in df_list:
40
- ent = list_ents(df)
41
- tags = list(no_of_tags(df).keys())
42
- doc = [{
43
- "text": ' '.join(df['words']),
44
- "ents": ent,
45
- "title": None
46
- }]
47
- spacy_streamlit.visualize_ner(
48
- doc,
49
- labels=tags,
50
- show_table=False,
51
- title=None,
52
- manual=True,
53
- displacy_options={
54
- "colors": color_creator(tags_data["NER"])
55
- },
56
- key=f"{key}"
57
- )
58
- key += 1
 
4
  from normalizer import process_df
5
  from process_tags import list_ents, no_of_tags, color_creator, scatter_document
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ def main():
9
+ st.set_page_config(layout='wide')
10
+ st.write(
11
+ "Tags Json is the file we get from exporting tags from d555 tag editor. You may need to format it to be in proper json format. For the demo, use this Tag json file https://github.com/kandysh/odin_json_sheets/blob/main/tag_color.json")
12
+ with st.sidebar:
13
+ uploaded_file = st.file_uploader("Upload the SENTENCE Json", type="json")
14
+ uploaded_color = st.file_uploader("Upload the TAG Json", type="json")
15
+ if uploaded_file and uploaded_color is not None:
16
+ raw_data = json.load(uploaded_file)
17
+ tags_data = json.load(uploaded_color)
18
+ st.title(f'{uploaded_file.name.split(".")[0].upper()}')
19
+ df_list = [process_df(data) for data in raw_data]
20
+ st.plotly_chart(scatter_document(df_list, tags_data), use_container_width=True)
21
+ key = 0
22
+ for df in df_list:
23
+ ents = list_ents(df)
24
+ tags = list(no_of_tags(df).keys())
25
+ doc = [{
26
+ "text": ' '.join(df['words']),
27
+ "ents": ents,
28
+ "title": None
29
+ }]
30
+ st.text(f"Sentence {key}")
31
+ spacy_streamlit.visualize_ner(
32
+ doc,
33
+ labels=tags,
34
+ show_table=False,
35
+ title=None,
36
+ manual=True,
37
+ displacy_options={
38
+ "colors": color_creator(tags_data["NER"])
39
+ },
40
+ key=f"{key}"
41
+ )
42
+ key += 1
43
 
44
 
45
+ if __name__ == "__main__":
46
+ main()