|
|
|
import glob, os, sys; |
|
sys.path.append('../udfPreprocess') |
|
|
|
|
|
import udfPreprocess.docPreprocessing as pre |
|
import udfPreprocess.cleaning as clean |
|
|
|
|
|
import seaborn as sns |
|
from pandas import DataFrame |
|
from keybert import KeyBERT |
|
from transformers import pipeline |
|
import matplotlib.pyplot as plt |
|
import numpy as np |
|
import streamlit as st |
|
import pandas as pd |
|
import docx |
|
from docx.shared import Inches |
|
from docx.shared import Pt |
|
from docx.enum.style import WD_STYLE_TYPE |
|
from udfPreprocess.sdg import sdg_classification |
|
|
|
import tempfile |
|
import sqlite3 |
|
import logging |
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
@st.cache(allow_output_mutation=True) |
|
def load_keyBert(): |
|
return KeyBERT() |
|
|
|
@st.cache(allow_output_mutation=True) |
|
def load_sdgClassifier(): |
|
classifier = pipeline("text-classification", model= "jonas/sdg_classifier_osdg") |
|
return classifier |
|
|
|
|
|
|
|
def app(): |
|
|
|
with st.container(): |
|
st.markdown("<h1 style='text-align: center; color: black;'> SDSN x GIZ Policy Action Tracking v0.1</h1>", unsafe_allow_html=True) |
|
st.write(' ') |
|
st.write(' ') |
|
|
|
with st.expander("ℹ️ - About this app", expanded=False): |
|
|
|
st.write( |
|
""" |
|
The *Analyse Policy Document* app is an easy-to-use interface built in Streamlit for analyzing policy documents with respect to SDG Classification for the paragraphs/texts in the document - developed by GIZ Data and the Sustainable Development Solution Network. \n |
|
""") |
|
st.markdown("") |
|
|
|
|
|
with st.container(): |
|
|
|
|
|
|
|
if 'docs' in st.session_state: |
|
docs = st.session_state['docs'] |
|
docs_processed, df, all_text, par_list = clean.preprocessingForSDG(docs) |
|
with st.spinner("Running SDG"): |
|
|
|
df, x = sdg_classification(par_list) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plt.rcParams['font.size'] = 25 |
|
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(x))) |
|
|
|
fig, ax = plt.subplots() |
|
ax.pie(x, colors=colors, radius=2, center=(4, 4), |
|
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=False,labels =list(x.index)) |
|
|
|
st.markdown("#### Anything related to SDGs? ####") |
|
|
|
|
|
|
|
c4, c5, c6 = st.columns([2, 2, 2]) |
|
|
|
|
|
cmGreen = sns.light_palette("green", as_cmap=True) |
|
cmRed = sns.light_palette("red", as_cmap=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with c5: |
|
st.pyplot(fig) |
|
|
|
c7, c8, c9 = st.columns([1, 10, 1]) |
|
with c8: |
|
st.table(df) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|