awacke1 commited on
Commit
1112873
·
1 Parent(s): 3a2fc8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -52,14 +52,17 @@ if button and (uploaded_file is not None or input_text != ""):
52
 
53
  # Display top N most representative topics and their documents
54
  num_topics = st.sidebar.slider("Select number of topics to display", 1, 20, 5, 1)
55
- topic_words, topic_docs = model.get_topics(with_documents=True)
56
- for i, topic in enumerate(topic_words.items()):
57
- if i >= num_topics:
58
- break
59
- st.write(f"## Topic {topic[0]}")
60
- st.write("Keywords:", ", ".join(topic[1]))
 
 
61
  st.write("Documents:")
62
- for doc in topic_docs[topic[0]][:5]:
 
63
  st.write("-", texts[doc])
64
 
65
  # Display topic clusters
 
52
 
53
  # Display top N most representative topics and their documents
54
  num_topics = st.sidebar.slider("Select number of topics to display", 1, 20, 5, 1)
55
+ topic_words = model.get_topics()
56
+ topic_freq = model.get_topic_freq().head(num_topics + 1) # Add 1 to exclude -1 (outliers topic)
57
+ for _, row in topic_freq.iterrows():
58
+ topic_id = row["Topic"]
59
+ if topic_id == -1:
60
+ continue # Skip the outliers topic
61
+ st.write(f"## Topic {topic_id}")
62
+ st.write("Keywords:", ", ".join(topic_words[topic_id]))
63
  st.write("Documents:")
64
+ doc_ids = [idx for idx, topic in enumerate(topics) if topic == topic_id][:5]
65
+ for doc in doc_ids:
66
  st.write("-", texts[doc])
67
 
68
  # Display topic clusters