Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
Compact Printouts
Browse files Browse the repository at this point in the history
  • Loading branch information
georgetayqy committed Feb 2, 2022
1 parent 86ff752 commit 530d86f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 47 deletions.
151 changes: 107 additions & 44 deletions pyfiles/pages/toolkit_nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,23 +1154,44 @@ def score2subject(score: int or float):
st.markdown('---')
st.markdown('### Save Data\n'
'#### Topics')
collda, collda2 = st.columns(2)
for index, data in enumerate(toolkit['TOPIC_TEXT']):
if toolkit['OVERRIDE_FORMAT'] is not None:
st.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lda_topics_{index}.{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
if (index + 1) % 2 != 0:
collda.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lda_topics_{index + 1}.'
f'{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
else:
collda2.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lda_topics_{index + 1}.'
f'{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
else:
st.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lda_topics_{index}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)
if (index + 1) % 2 != 0:
collda.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lda_topics_{index + 1}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)
else:
collda2.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lda_topics_{index + 1}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)

st.markdown('#### Topic/Word List')
if toolkit['OVERRIDE_FORMAT'] is not None:
Expand Down Expand Up @@ -1215,7 +1236,7 @@ def score2subject(score: int or float):
l1_ratio=toolkit['L1_RATIO']).fit(toolkit['TFIDF_VECTORISED'])

if toolkit['VERBOSE']:
st.markdown('### Model Data')
st.markdown('## Model Data')
toolkit['TOPIC_TEXT'] = modelIterator(toolkit['NMF_MODEL'], toolkit['TFIDF_MODEL'],
top_n=toolkit['NUM_TOPICS'])
else:
Expand All @@ -1240,23 +1261,44 @@ def score2subject(score: int or float):
st.markdown('---')
st.markdown('### Save Data\n'
'#### Topics')
colnmf, colnmf2 = st.columns(2)
for index, data in enumerate(toolkit['TOPIC_TEXT']):
if toolkit['OVERRIDE_FORMAT'] is not None:
st.markdown(prettyDownload(
object_to_download=data,
download_filename=f'nmf_topics_{index}.{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
if (index + 1) % 2 != 0:
colnmf.markdown(prettyDownload(
object_to_download=data,
download_filename=f'nmf_topics_{index + 1}.'
f'{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
else:
colnmf2.markdown(prettyDownload(
object_to_download=data,
download_filename=f'nmf_topics_{index + 1}.'
f'{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
else:
st.markdown(prettyDownload(
object_to_download=data,
download_filename=f'nmf_topics_{index}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)
if (index + 1) % 2 != 0:
colnmf.markdown(prettyDownload(
object_to_download=data,
download_filename=f'nmf_topics_{index + 1}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)
else:
colnmf2.markdown(prettyDownload(
object_to_download=data,
download_filename=f'nmf_topics_{index + 1}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html = True)

st.markdown('#### Topic/Word List')
if toolkit['OVERRIDE_FORMAT'] is not None:
Expand All @@ -1283,7 +1325,7 @@ def score2subject(score: int or float):
toolkit['LSI_DATA'] = toolkit['LSI_MODEL'].fit_transform(toolkit['VECTORISED'])

if toolkit['VERBOSE']:
st.markdown('### Model Data')
st.markdown('## Model Data')
toolkit['TOPIC_TEXT'] = modelIterator(toolkit['LSI_MODEL'], toolkit['CV'],
top_n=toolkit['NUM_TOPICS'])
else:
Expand Down Expand Up @@ -1354,23 +1396,44 @@ def score2subject(score: int or float):
st.markdown('---')
st.markdown('### Save Data\n'
'#### Topics')
collis, collis2 = st.columns(2)
for index, data in enumerate(toolkit['TOPIC_TEXT']):
if toolkit['OVERRIDE_FORMAT'] is not None:
st.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lsi_topics_{index}.{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
if (index + 1) % 2 != 0:
collis.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lsi_topics_{index + 1}.'
f'{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
else:
collis2.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lsi_topics_{index + 1}.'
f'{toolkit["OVERRIDE_FORMAT"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['OVERRIDE_FORMAT']),
unsafe_allow_html=True)
else:
st.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lsi_topics_{index}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)
if (index + 1) % 2 != 0:
collis.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lsi_topics_{index + 1}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)
else:
collis2.markdown(prettyDownload(
object_to_download=data,
download_filename=f'lsi_topics_{index + 1}.{toolkit["MODE"].lower()}',
button_text=f'Download Topic List Data Entry {index + 1}',
override_index=False,
format_=toolkit['MODE']),
unsafe_allow_html=True)

st.markdown('#### Topic/Word List')
if toolkit['OVERRIDE_FORMAT'] is not None:
Expand Down
16 changes: 13 additions & 3 deletions utils/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,22 @@ def modelIterator(model, vectoriser, top_n, vb=True):
index=range(len(lister)),
columns=['word', 'weight'])

if vb:
st.markdown(f'### Topic {id_}')
st.dataframe(df)
# if vb:
# st.markdown(f'### Topic {id_}')
# st.dataframe(df)

frame_list.append(df)

if vb:
colx, coly = st.columns(2)
for order, data in enumerate(frame_list):
if (order + 1) % 2 != 0:
colx.markdown(f'### Topic {order + 1}')
colx.dataframe(data)
else:
coly.markdown(f'### Topic {order + 1}')
coly.dataframe(data)

return frame_list


Expand Down

0 comments on commit 530d86f

Please sign in to comment.