Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,9 +58,11 @@ def detect_language(text):
|
|
| 58 |
|
| 59 |
@st.cache_data
|
| 60 |
def tsne_visualization(embeddings, words):
|
| 61 |
-
if len(words) <
|
| 62 |
return pd.DataFrame({'word': words})
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
embeddings_2d = tsne.fit_transform(embeddings)
|
| 65 |
df = pd.DataFrame(embeddings_2d, columns=['x', 'y'])
|
| 66 |
df['word'] = words
|
|
@@ -96,18 +98,21 @@ if st.button("Analyze"):
|
|
| 96 |
st.write("Word list (not enough words for t-SNE visualization):")
|
| 97 |
st.write(", ".join(words))
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
else:
|
| 113 |
st.warning("Please enter some text to analyze.")
|
|
|
|
| 58 |
|
| 59 |
@st.cache_data
|
| 60 |
def tsne_visualization(embeddings, words):
|
| 61 |
+
if len(words) < 3: # Not enough words for t-SNE
|
| 62 |
return pd.DataFrame({'word': words})
|
| 63 |
+
|
| 64 |
+
perplexity = min(30, len(words) - 1)
|
| 65 |
+
tsne = TSNE(n_components=2, random_state=42, perplexity=perplexity)
|
| 66 |
embeddings_2d = tsne.fit_transform(embeddings)
|
| 67 |
df = pd.DataFrame(embeddings_2d, columns=['x', 'y'])
|
| 68 |
df['word'] = words
|
|
|
|
| 98 |
st.write("Word list (not enough words for t-SNE visualization):")
|
| 99 |
st.write(", ".join(words))
|
| 100 |
|
| 101 |
+
if len(words) > 1:
|
| 102 |
+
with st.spinner("Extracting topics..."):
|
| 103 |
+
texts = [user_input, "Another text to improve topic modeling."]
|
| 104 |
+
topic_distr, vectorizer = topic_modeling_agent.fit_transform(texts, lang)
|
| 105 |
+
topics = topic_modeling_agent.get_topics(vectorizer)
|
| 106 |
+
st.subheader("Topics Extracted:")
|
| 107 |
+
for topic, topic_words in topics.items():
|
| 108 |
+
st.write(f"Topic {topic}: {', '.join(topic_words)}")
|
| 109 |
+
|
| 110 |
+
with st.spinner("Computing similarity..."):
|
| 111 |
+
text2 = "Otro texto de ejemplo para comparaci贸n de similitud." if lang != 'en' else "Another example text for similarity comparison."
|
| 112 |
+
similarity_score = similarity_agent.compute_similarity(user_input, text2)
|
| 113 |
+
st.write(f"Similarity Score with example text: {similarity_score:.4f}")
|
| 114 |
+
else:
|
| 115 |
+
st.warning("Not enough words for topic modeling and similarity comparison.")
|
| 116 |
|
| 117 |
else:
|
| 118 |
st.warning("Please enter some text to analyze.")
|