Spaces:
Sleeping
Sleeping
Commit
·
2cdd7b2
1
Parent(s):
b305124
Update app.py
Browse files
app.py
CHANGED
@@ -60,24 +60,28 @@ embeds = co.embed(texts=list_of_titles,
|
|
60 |
model="small").embeddings
|
61 |
|
62 |
embeds_npy = np.array(embeds)
|
63 |
-
# Load and initialize BERTopic to use KMeans clustering with 8 clusters only.
|
64 |
-
cluster_model = KMeans(n_clusters=8)
|
65 |
-
topic_model = BERTopic(hdbscan_model=cluster_model)
|
66 |
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
app = Topically(os.environ["CO_API_KEY"])
|
71 |
-
|
72 |
-
df['topic_name'], topic_names = app.name_topics((df['content.title'], df['topic']), num_generations=5)
|
73 |
-
|
74 |
-
#st.write("Topics extracted are:", topic_names)
|
75 |
-
|
76 |
-
topic_model.set_topic_labels(topic_names)
|
77 |
-
fig = topic_model.visualize_documents(df['content.title'].values,
|
78 |
-
embeddings=embeds_npy,
|
79 |
-
topics = list(range(8)),
|
80 |
-
custom_labels=True)
|
81 |
-
|
82 |
-
st.plotly_chart(fig)
|
83 |
|
|
|
60 |
model="small").embeddings
|
61 |
|
62 |
embeds_npy = np.array(embeds)
|
|
|
|
|
|
|
63 |
|
64 |
+
def get_visualizations():
|
65 |
+
# Load and initialize BERTopic to use KMeans clustering with 8 clusters only.
|
66 |
+
cluster_model = KMeans(n_clusters=8)
|
67 |
+
topic_model = BERTopic(hdbscan_model=cluster_model)
|
68 |
+
|
69 |
+
# df is a dataframe. df['title'] is the column of text we're modeling
|
70 |
+
df['topic'], probabilities = topic_model.fit_transform(df['content.title'], embeds_npy)
|
71 |
+
|
72 |
+
app = Topically(os.environ["CO_API_KEY"])
|
73 |
+
|
74 |
+
df['topic_name'], topic_names = app.name_topics((df['content.title'], df['topic']), num_generations=5)
|
75 |
+
|
76 |
+
#st.write("Topics extracted are:", topic_names)
|
77 |
+
|
78 |
+
topic_model.set_topic_labels(topic_names)
|
79 |
+
fig1 = topic_model.visualize_documents(df['content.title'].values,
|
80 |
+
embeddings=embeds_npy,
|
81 |
+
topics = list(range(8)),
|
82 |
+
custom_labels=True)
|
83 |
+
fig2 = topic_model.visualize_barchart()
|
84 |
+
st.plotly_chart(fig1)
|
85 |
+
st.plotly_chart(fig2)
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|