khaerens commited on
Commit
456234e
1 Parent(s): 90a3148
__pycache__/app.cpython-38.pyc CHANGED
Binary files a/__pycache__/app.cpython-38.pyc and b/__pycache__/app.cpython-38.pyc differ
 
__pycache__/rebel.cpython-38.pyc CHANGED
Binary files a/__pycache__/rebel.cpython-38.pyc and b/__pycache__/rebel.cpython-38.pyc differ
 
app.py CHANGED
@@ -16,7 +16,8 @@ state_variables = {
16
  'has_run':False,
17
  'wiki_suggestions': [],
18
  'wiki_text' : [],
19
- 'nodes':[]
 
20
  }
21
 
22
  for k, v in state_variables.items():
@@ -35,8 +36,13 @@ def generate_graph():
35
  return
36
  with st.spinner(text="Generating graph..."):
37
  texts = st.session_state['wiki_text']
 
38
  nodes = rebel.generate_knowledge_graph(texts, network_filename)
39
- st.session_state['nodes'] = nodes
 
 
 
 
40
  st.session_state['has_run'] = True
41
  st.success('Done!')
42
 
@@ -55,6 +61,7 @@ def show_wiki_text(page_title):
55
  try:
56
  page = wikipedia.page(title=page_title, auto_suggest=False)
57
  st.session_state['wiki_text'].append(clip_text(page.summary))
 
58
  except wikipedia.DisambiguationError as e:
59
  with st.spinner(text="Woops, ambigious term, recalculating options..."):
60
  st.session_state['wiki_suggestions'].remove(page_title)
@@ -65,6 +72,7 @@ def add_text(term):
65
  try:
66
  extra_text = clip_text(wikipedia.page(title=term, auto_suggest=True).summary)
67
  st.session_state['wiki_text'].append(extra_text)
 
68
  except wikipedia.WikipediaException:
69
  st.error("Woops, no wikipedia page for this node")
70
  st.session_state["nodes"].remove(term)
@@ -104,12 +112,9 @@ else:
104
  st.button("Search", on_click=show_suggestion, key="show_suggestion_key")
105
 
106
  if len(st.session_state['wiki_suggestions']) != 0:
107
-
108
  num_buttons = len(st.session_state['wiki_suggestions'])
109
- num_cols = num_buttons if num_buttons < 7 else 7
110
- columns = st.columns([1] * num_cols + [1])
111
- print(st.session_state['wiki_suggestions'])
112
-
113
  for q in range(1 + num_buttons//num_cols):
114
  for i, (c, s) in enumerate(zip(columns, st.session_state['wiki_suggestions'][q*num_cols: (q+1)*num_cols])):
115
  with c:
@@ -141,14 +146,19 @@ if st.session_state['has_run']:
141
  """
142
  )
143
 
144
- cols = st.columns([5, 1])
145
- with cols[0]:
146
- HtmlFile = open(network_filename, 'r', encoding='utf-8')
147
- source_code = HtmlFile.read()
148
- components.html(source_code, height=2000,width=2000)
149
- with cols[1]:
150
- for i,s in enumerate(st.session_state["nodes"]):
151
- st.button(s, on_click=add_text, args=(s,), key=s+str(i))
 
 
 
 
 
152
 
153
 
154
 
 
16
  'has_run':False,
17
  'wiki_suggestions': [],
18
  'wiki_text' : [],
19
+ 'nodes':[],
20
+ "topics":[]
21
  }
22
 
23
  for k, v in state_variables.items():
 
36
  return
37
  with st.spinner(text="Generating graph..."):
38
  texts = st.session_state['wiki_text']
39
+ st.session_state['nodes'] = []
40
  nodes = rebel.generate_knowledge_graph(texts, network_filename)
41
+ print("gen_graph", nodes)
42
+ for n in nodes:
43
+ n = n.lower()
44
+ if n not in st.session_state['topics']:
45
+ st.session_state['nodes'].append(n)
46
  st.session_state['has_run'] = True
47
  st.success('Done!')
48
 
 
61
  try:
62
  page = wikipedia.page(title=page_title, auto_suggest=False)
63
  st.session_state['wiki_text'].append(clip_text(page.summary))
64
+ st.session_state['topics'].append(page_title.lower())
65
  except wikipedia.DisambiguationError as e:
66
  with st.spinner(text="Woops, ambigious term, recalculating options..."):
67
  st.session_state['wiki_suggestions'].remove(page_title)
 
72
  try:
73
  extra_text = clip_text(wikipedia.page(title=term, auto_suggest=True).summary)
74
  st.session_state['wiki_text'].append(extra_text)
75
+ st.session_state['topics'].append(term.lower())
76
  except wikipedia.WikipediaException:
77
  st.error("Woops, no wikipedia page for this node")
78
  st.session_state["nodes"].remove(term)
 
112
  st.button("Search", on_click=show_suggestion, key="show_suggestion_key")
113
 
114
  if len(st.session_state['wiki_suggestions']) != 0:
 
115
  num_buttons = len(st.session_state['wiki_suggestions'])
116
+ num_cols = num_buttons if num_buttons < 8 else 8
117
+ columns = st.columns([1] * num_cols )
 
 
118
  for q in range(1 + num_buttons//num_cols):
119
  for i, (c, s) in enumerate(zip(columns, st.session_state['wiki_suggestions'][q*num_cols: (q+1)*num_cols])):
120
  with c:
 
146
  """
147
  )
148
 
149
+ HtmlFile = open(network_filename, 'r', encoding='utf-8')
150
+ source_code = HtmlFile.read()
151
+ components.html(source_code, width=720, height=600)
152
+
153
+ num_buttons = len(st.session_state["nodes"])
154
+ num_cols = num_buttons if num_buttons < 7 else 7
155
+ columns = st.columns([1] * num_cols + [1])
156
+ print(st.session_state["nodes"])
157
+
158
+ for q in range(1 + num_buttons//num_cols):
159
+ for i, (c, s) in enumerate(zip(columns, st.session_state["nodes"][q*num_cols: (q+1)*num_cols])):
160
+ with c:
161
+ st.button(s, on_click=add_text, args=(s,), key=str(i)+s)
162
 
163
 
164
 
rebel.py CHANGED
@@ -43,14 +43,17 @@ def generate_knowledge_graph(texts: List[str], filename: str):
43
  heads = [ t["head"].lower() for t in triplets]
44
  tails = [ t["tail"].lower() for t in triplets]
45
 
46
- nodes = set(heads + tails)
47
- net = Network(directed=True)
48
 
49
  for n in nodes:
50
  if n in NERs:
51
  NER_type = NER_types[NERs.index(n)]
52
- color = DEFAULT_LABEL_COLORS[NER_type]
53
- net.add_node(n, title=NER_type, shape="circle", color=color)
 
 
 
54
  else:
55
  net.add_node(n, shape="circle")
56
 
 
43
  heads = [ t["head"].lower() for t in triplets]
44
  tails = [ t["tail"].lower() for t in triplets]
45
 
46
+ nodes = list(set(heads + tails))
47
+ net = Network(directed=True, width="700px", height="700px")
48
 
49
  for n in nodes:
50
  if n in NERs:
51
  NER_type = NER_types[NERs.index(n)]
52
+ if NER_type in NER_types:
53
+ color = DEFAULT_LABEL_COLORS[NER_type]
54
+ net.add_node(n, title=NER_type, shape="circle", color=color)
55
+ else:
56
+ net.add_node(n, shape="circle")
57
  else:
58
  net.add_node(n, shape="circle")
59