Spaces:
Build error
Build error
update
Browse files
app.py
CHANGED
@@ -20,10 +20,13 @@ wiki_state_variables = {
|
|
20 |
'wiki_text' : [],
|
21 |
'nodes':[],
|
22 |
"topics":[],
|
|
|
23 |
}
|
24 |
|
25 |
free_text_state_variables = {
|
26 |
'has_run_free':False,
|
|
|
|
|
27 |
}
|
28 |
|
29 |
def wiki_init_state_variables():
|
@@ -35,6 +38,7 @@ def wiki_init_state_variables():
|
|
35 |
if k not in st.session_state:
|
36 |
st.session_state[k] = v
|
37 |
|
|
|
38 |
def wiki_generate_graph():
|
39 |
st.session_state["GRAPH_FILENAME"] = str(dt.now().timestamp()*1000) + ".html"
|
40 |
|
@@ -47,6 +51,10 @@ def wiki_generate_graph():
|
|
47 |
texts = st.session_state['wiki_text']
|
48 |
st.session_state['nodes'] = []
|
49 |
nodes = rebel.generate_knowledge_graph(texts, st.session_state["GRAPH_FILENAME"])
|
|
|
|
|
|
|
|
|
50 |
print("gen_graph", nodes)
|
51 |
for n in nodes:
|
52 |
n = n.lower()
|
@@ -100,6 +108,10 @@ def free_text_generate():
|
|
100 |
st.session_state["GRAPH_FILENAME"] = str(dt.now().timestamp()*1000) + ".html"
|
101 |
text = st.session_state['free_text'][0:500]
|
102 |
rebel.generate_knowledge_graph([text], st.session_state["GRAPH_FILENAME"])
|
|
|
|
|
|
|
|
|
103 |
st.session_state['has_run_free'] = True
|
104 |
|
105 |
def free_text_layout():
|
@@ -167,10 +179,8 @@ def show_wiki_hub_page():
|
|
167 |
print(st.session_state)
|
168 |
|
169 |
if st.session_state['has_run_wiki']:
|
170 |
-
|
171 |
-
|
172 |
-
components.html(source_code, width=720, height=600)
|
173 |
-
os.remove(st.session_state["GRAPH_FILENAME"])
|
174 |
num_buttons = len(st.session_state["nodes"])
|
175 |
num_cols = num_buttons if 0 < num_buttons < 7 else 7
|
176 |
columns = st.columns([1] * num_cols + [1])
|
|
|
20 |
'wiki_text' : [],
|
21 |
'nodes':[],
|
22 |
"topics":[],
|
23 |
+
"html":""
|
24 |
}
|
25 |
|
26 |
free_text_state_variables = {
|
27 |
'has_run_free':False,
|
28 |
+
"html":""
|
29 |
+
|
30 |
}
|
31 |
|
32 |
def wiki_init_state_variables():
|
|
|
38 |
if k not in st.session_state:
|
39 |
st.session_state[k] = v
|
40 |
|
41 |
+
|
42 |
def wiki_generate_graph():
|
43 |
st.session_state["GRAPH_FILENAME"] = str(dt.now().timestamp()*1000) + ".html"
|
44 |
|
|
|
51 |
texts = st.session_state['wiki_text']
|
52 |
st.session_state['nodes'] = []
|
53 |
nodes = rebel.generate_knowledge_graph(texts, st.session_state["GRAPH_FILENAME"])
|
54 |
+
HtmlFile = open(st.session_state["GRAPH_FILENAME"], 'r', encoding='utf-8')
|
55 |
+
source_code = HtmlFile.read()
|
56 |
+
st.session_state["html"] = source_code
|
57 |
+
os.remove(st.session_state["GRAPH_FILENAME"])
|
58 |
print("gen_graph", nodes)
|
59 |
for n in nodes:
|
60 |
n = n.lower()
|
|
|
108 |
st.session_state["GRAPH_FILENAME"] = str(dt.now().timestamp()*1000) + ".html"
|
109 |
text = st.session_state['free_text'][0:500]
|
110 |
rebel.generate_knowledge_graph([text], st.session_state["GRAPH_FILENAME"])
|
111 |
+
HtmlFile = open(st.session_state["GRAPH_FILENAME"], 'r', encoding='utf-8')
|
112 |
+
source_code = HtmlFile.read()
|
113 |
+
st.session_state["html"] = source_code
|
114 |
+
os.remove(st.session_state["GRAPH_FILENAME"])
|
115 |
st.session_state['has_run_free'] = True
|
116 |
|
117 |
def free_text_layout():
|
|
|
179 |
print(st.session_state)
|
180 |
|
181 |
if st.session_state['has_run_wiki']:
|
182 |
+
|
183 |
+
components.html(st.session_state("html"), width=720, height=600)
|
|
|
|
|
184 |
num_buttons = len(st.session_state["nodes"])
|
185 |
num_cols = num_buttons if 0 < num_buttons < 7 else 7
|
186 |
columns = st.columns([1] * num_cols + [1])
|