prashant
commited on
Commit
•
fb4cce0
1
Parent(s):
685552c
sdg update
Browse files- appStore/sdg_analysis.py +35 -29
- utils/sdg_classifier.py +2 -2
appStore/sdg_analysis.py
CHANGED
@@ -38,38 +38,44 @@ def app():
|
|
38 |
|
39 |
|
40 |
with st.container():
|
|
|
41 |
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
else:
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
df, x = sdg_classification(allDocuments['documents'])
|
54 |
-
|
55 |
-
plt.rcParams['font.size'] = 25
|
56 |
-
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(x)))
|
57 |
-
# plot
|
58 |
-
fig, ax = plt.subplots()
|
59 |
-
ax.pie(x, colors=colors, radius=2, center=(4, 4),
|
60 |
-
wedgeprops={"linewidth": 1, "edgecolor": "white"},
|
61 |
-
frame=False,labels =list(x.index))
|
62 |
-
# fig.savefig('temp.png', bbox_inches='tight',dpi= 100)
|
63 |
-
st.markdown("#### Anything related to SDGs? ####")
|
64 |
-
|
65 |
-
c4, c5, c6 = st.columns([2, 2, 2])
|
66 |
-
|
67 |
-
with c5:
|
68 |
-
st.pyplot(fig)
|
69 |
-
|
70 |
-
c7, c8, c9 = st.columns([1, 10, 1])
|
71 |
-
with c8:
|
72 |
-
st.table(df)
|
73 |
|
74 |
|
75 |
# 1. Keyword heatmap \n
|
|
|
38 |
|
39 |
|
40 |
with st.container():
|
41 |
+
if st.button("RUN SDG Analysis"):
|
42 |
|
43 |
|
44 |
+
if 'filepath' in st.session_state:
|
45 |
+
allDocuments = runSDGPreprocessingPipeline(st.session_state['filepath'],
|
46 |
+
st.session_state['filename'])
|
47 |
+
if len(allDocuments['documents']) > 100:
|
48 |
+
warning_msg = ": This might take sometime, please sit back and relax."
|
49 |
+
else:
|
50 |
+
warning_msg = ""
|
51 |
+
|
52 |
+
with st.spinner("Running SDG Classification{}".format(warning_msg)):
|
53 |
+
|
54 |
+
df, x = sdg_classification(allDocuments['documents'])
|
55 |
+
|
56 |
+
plt.rcParams['font.size'] = 25
|
57 |
+
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(x)))
|
58 |
+
# plot
|
59 |
+
fig, ax = plt.subplots()
|
60 |
+
ax.pie(x, colors=colors, radius=2, center=(4, 4),
|
61 |
+
wedgeprops={"linewidth": 1, "edgecolor": "white"},
|
62 |
+
frame=False,labels =list(x.index))
|
63 |
+
# fig.savefig('temp.png', bbox_inches='tight',dpi= 100)
|
64 |
+
st.markdown("#### Anything related to SDGs? ####")
|
65 |
+
|
66 |
+
c4, c5, c6 = st.columns([2, 2, 2])
|
67 |
+
|
68 |
+
with c5:
|
69 |
+
st.pyplot(fig)
|
70 |
+
|
71 |
+
c7, c8, c9 = st.columns([1, 10, 1])
|
72 |
+
with c8:
|
73 |
+
st.table(df)
|
74 |
else:
|
75 |
+
st.info("🤔 No document found, please try to upload it at the sidebar!")
|
76 |
+
logging.warning("Terminated as no document provided")
|
77 |
+
|
78 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
|
81 |
# 1. Keyword heatmap \n
|
utils/sdg_classifier.py
CHANGED
@@ -17,7 +17,7 @@ except Exception:
|
|
17 |
st.info("Please place the paramconfig file in the same directory as app.py")
|
18 |
|
19 |
|
20 |
-
@st.cache
|
21 |
def load_sdgClassifier():
|
22 |
"""
|
23 |
loads the document classifier using haystack, where the name/path of model
|
@@ -36,7 +36,7 @@ def load_sdgClassifier():
|
|
36 |
|
37 |
|
38 |
|
39 |
-
@st.cache
|
40 |
def sdg_classification(haystackdoc:List[Document])->Tuple[DataFrame,Series]:
|
41 |
"""
|
42 |
Text-Classification on the list of texts provided. Classifier provides the
|
|
|
17 |
st.info("Please place the paramconfig file in the same directory as app.py")
|
18 |
|
19 |
|
20 |
+
@st.cache(allow_output_mutation=True)
|
21 |
def load_sdgClassifier():
|
22 |
"""
|
23 |
loads the document classifier using haystack, where the name/path of model
|
|
|
36 |
|
37 |
|
38 |
|
39 |
+
@st.cache(allow_output_mutation=True)
|
40 |
def sdg_classification(haystackdoc:List[Document])->Tuple[DataFrame,Series]:
|
41 |
"""
|
42 |
Text-Classification on the list of texts provided. Classifier provides the
|