Spaces:
Running
Running
Update pages/2 Topic Modeling.py
Browse files- pages/2 Topic Modeling.py +6 -60
pages/2 Topic Modeling.py
CHANGED
@@ -32,7 +32,6 @@ import sys
|
|
32 |
import spacy
|
33 |
import en_core_web_sm
|
34 |
import pipeline
|
35 |
-
import plotly.graph_objects as go
|
36 |
from html2image import Html2Image
|
37 |
|
38 |
|
@@ -319,13 +318,7 @@ if uploaded_file is not None:
|
|
319 |
topics_over_time = topic_model.topics_over_time(topic_abs, topic_time)
|
320 |
fig6 = topic_model.visualize_topics_over_time(topics_over_time)
|
321 |
return fig6
|
322 |
-
|
323 |
-
@st.cache_data(ttl=3600, show_spinner=False)
|
324 |
-
def img_bert(fig):
|
325 |
-
my_saved_image = "fig.png"
|
326 |
-
fig.write_image(my_saved_image)
|
327 |
-
return my_saved_image
|
328 |
-
|
329 |
tab1, tab2, tab3 = st.tabs(["π Generate visualization", "π Reference", "π Recommended Reading"])
|
330 |
with tab1:
|
331 |
try:
|
@@ -340,79 +333,32 @@ if uploaded_file is not None:
|
|
340 |
with st.spinner('Performing computations. Please wait ...'):
|
341 |
fig1 = Vis_Topics(extype)
|
342 |
st.write(fig1)
|
343 |
-
my_saved_image = img_bert(fig1)
|
344 |
-
with open(my_saved_image, "rb") as file:
|
345 |
-
btn = st.download_button(
|
346 |
-
label="Download image",
|
347 |
-
data=file,
|
348 |
-
file_name="Vis_Topics.png",
|
349 |
-
mime="image/png"
|
350 |
-
)
|
351 |
|
352 |
elif viz == 'Visualize Documents':
|
353 |
with st.spinner('Performing computations. Please wait ...'):
|
354 |
fig2 = Vis_Documents(extype)
|
355 |
st.write(fig2)
|
356 |
-
|
357 |
-
with open(my_saved_image, "rb") as file:
|
358 |
-
btn = st.download_button(
|
359 |
-
label="Download image",
|
360 |
-
data=file,
|
361 |
-
file_name="Vis_Documents.png",
|
362 |
-
mime="image/png"
|
363 |
-
)
|
364 |
-
|
365 |
elif viz == 'Visualize Document Hierarchy':
|
366 |
with st.spinner('Performing computations. Please wait ...'):
|
367 |
fig3 = Vis_Hierarchy(extype)
|
368 |
st.write(fig3)
|
369 |
-
|
370 |
-
with open(my_saved_image, "rb") as file:
|
371 |
-
btn = st.download_button(
|
372 |
-
label="Download image",
|
373 |
-
data=file,
|
374 |
-
file_name="Vis_Hierarchy.png",
|
375 |
-
mime="image/png"
|
376 |
-
)
|
377 |
-
|
378 |
elif viz == 'Visualize Topic Similarity':
|
379 |
with st.spinner('Performing computations. Please wait ...'):
|
380 |
fig4 = Vis_Heatmap(extype)
|
381 |
st.write(fig4)
|
382 |
-
|
383 |
-
with open(my_saved_image, "rb") as file:
|
384 |
-
btn = st.download_button(
|
385 |
-
label="Download image",
|
386 |
-
data=file,
|
387 |
-
file_name="Vis_Similarity.png",
|
388 |
-
mime="image/png"
|
389 |
-
)
|
390 |
-
|
391 |
elif viz == 'Visualize Terms':
|
392 |
with st.spinner('Performing computations. Please wait ...'):
|
393 |
fig5 = Vis_Barchart(extype)
|
394 |
st.write(fig5)
|
395 |
-
|
396 |
-
with open(my_saved_image, "rb") as file:
|
397 |
-
btn = st.download_button(
|
398 |
-
label="Download image",
|
399 |
-
data=file,
|
400 |
-
file_name="Vis_Terms.png",
|
401 |
-
mime="image/png"
|
402 |
-
)
|
403 |
-
|
404 |
elif viz == 'Visualize Topics over Time':
|
405 |
with st.spinner('Performing computations. Please wait ...'):
|
406 |
fig6 = Vis_ToT(extype)
|
407 |
st.write(fig6)
|
408 |
-
|
409 |
-
with open(my_saved_image, "rb") as file:
|
410 |
-
btn = st.download_button(
|
411 |
-
label="Download image",
|
412 |
-
data=file,
|
413 |
-
file_name="Vis_ToT.png",
|
414 |
-
mime="image/png"
|
415 |
-
)
|
416 |
|
417 |
except ValueError:
|
418 |
st.error('πββοΈ Please raise the number of topics and click submit')
|
|
|
32 |
import spacy
|
33 |
import en_core_web_sm
|
34 |
import pipeline
|
|
|
35 |
from html2image import Html2Image
|
36 |
|
37 |
|
|
|
318 |
topics_over_time = topic_model.topics_over_time(topic_abs, topic_time)
|
319 |
fig6 = topic_model.visualize_topics_over_time(topics_over_time)
|
320 |
return fig6
|
321 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
tab1, tab2, tab3 = st.tabs(["π Generate visualization", "π Reference", "π Recommended Reading"])
|
323 |
with tab1:
|
324 |
try:
|
|
|
333 |
with st.spinner('Performing computations. Please wait ...'):
|
334 |
fig1 = Vis_Topics(extype)
|
335 |
st.write(fig1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
|
337 |
elif viz == 'Visualize Documents':
|
338 |
with st.spinner('Performing computations. Please wait ...'):
|
339 |
fig2 = Vis_Documents(extype)
|
340 |
st.write(fig2)
|
341 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
elif viz == 'Visualize Document Hierarchy':
|
343 |
with st.spinner('Performing computations. Please wait ...'):
|
344 |
fig3 = Vis_Hierarchy(extype)
|
345 |
st.write(fig3)
|
346 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
elif viz == 'Visualize Topic Similarity':
|
348 |
with st.spinner('Performing computations. Please wait ...'):
|
349 |
fig4 = Vis_Heatmap(extype)
|
350 |
st.write(fig4)
|
351 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
elif viz == 'Visualize Terms':
|
353 |
with st.spinner('Performing computations. Please wait ...'):
|
354 |
fig5 = Vis_Barchart(extype)
|
355 |
st.write(fig5)
|
356 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
elif viz == 'Visualize Topics over Time':
|
358 |
with st.spinner('Performing computations. Please wait ...'):
|
359 |
fig6 = Vis_ToT(extype)
|
360 |
st.write(fig6)
|
361 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
except ValueError:
|
364 |
st.error('πββοΈ Please raise the number of topics and click submit')
|