Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ import numpy as np
|
|
8 |
import matplotlib.pyplot as plt
|
9 |
import pandas as pd
|
10 |
|
|
|
|
|
11 |
@st.cache_resource
|
12 |
def load_model():
|
13 |
return SentenceTransformer('distiluse-base-multilingual-cased-v1')
|
@@ -62,48 +64,47 @@ def tsne_visualization(embeddings, words):
|
|
62 |
df['word'] = words
|
63 |
return df
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
if
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
main()
|
|
|
8 |
import matplotlib.pyplot as plt
|
9 |
import pandas as pd
|
10 |
|
11 |
+
st.set_page_config(page_title="Multilingual Text Analysis System", layout="wide")
|
12 |
+
|
13 |
@st.cache_resource
|
14 |
def load_model():
|
15 |
return SentenceTransformer('distiluse-base-multilingual-cased-v1')
|
|
|
64 |
df['word'] = words
|
65 |
return df
|
66 |
|
67 |
+
st.title("Multilingual Text Analysis System")
|
68 |
+
user_input = st.text_area("Enter your text here:")
|
69 |
+
|
70 |
+
if st.button("Analyze") or user_input:
|
71 |
+
if user_input:
|
72 |
+
lang = detect_language(user_input)
|
73 |
+
st.write(f"Detected language: {lang}")
|
74 |
+
|
75 |
+
embedding_agent = WordEmbeddingAgent(multi_embedding_model)
|
76 |
+
similarity_agent = SimilarityAgent(multi_embedding_model)
|
77 |
+
topic_modeling_agent = TopicModelingAgent()
|
78 |
+
|
79 |
+
words = user_input.split()
|
80 |
+
|
81 |
+
with st.spinner("Generating word embeddings..."):
|
82 |
+
embeddings = embedding_agent.get_embeddings(words)
|
83 |
+
st.success("Word Embeddings Generated.")
|
84 |
+
|
85 |
+
with st.spinner("Creating t-SNE visualization..."):
|
86 |
+
tsne_df = tsne_visualization(embeddings, words)
|
87 |
+
fig, ax = plt.subplots()
|
88 |
+
ax.scatter(tsne_df['x'], tsne_df['y'])
|
89 |
+
for i, word in enumerate(tsne_df['word']):
|
90 |
+
ax.annotate(word, (tsne_df['x'][i], tsne_df['y'][i]))
|
91 |
+
st.pyplot(fig)
|
92 |
+
|
93 |
+
with st.spinner("Extracting topics..."):
|
94 |
+
texts = [user_input, "Another text to improve topic modeling."]
|
95 |
+
topic_distr, vectorizer = topic_modeling_agent.fit_transform(texts, lang)
|
96 |
+
topics = topic_modeling_agent.get_topics(vectorizer)
|
97 |
+
st.subheader("Topics Extracted:")
|
98 |
+
for topic, words in topics.items():
|
99 |
+
st.write(f"Topic {topic}: {', '.join(words)}")
|
100 |
+
|
101 |
+
with st.spinner("Computing similarity..."):
|
102 |
+
text2 = "Otro texto de ejemplo para comparación de similitud." if lang != 'en' else "Another example text for similarity comparison."
|
103 |
+
similarity_score = similarity_agent.compute_similarity(user_input, text2)
|
104 |
+
st.write(f"Similarity Score with example text: {similarity_score:.4f}")
|
105 |
+
|
106 |
+
else:
|
107 |
+
st.warning("Please enter some text to analyze.")
|
108 |
+
|
109 |
+
st.sidebar.title("About")
|
110 |
+
st.sidebar.info("This app performs multilingual text analysis using various NLP techniques.")
|
|