Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
st.write("Documents:")
|
62 |
-
for
|
|
|
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
|