KevSun commited on
Commit
59b41df
1 Parent(s): a9d0211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -45
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
- def main():
66
- st.title("Multilingual Text Analysis System")
67
- user_input = st.text_area("Enter your text here:")
68
-
69
- if st.button("Analyze"):
70
- if user_input:
71
- lang = detect_language(user_input)
72
- st.write(f"Detected language: {lang}")
73
-
74
- embedding_agent = WordEmbeddingAgent(multi_embedding_model)
75
- similarity_agent = SimilarityAgent(multi_embedding_model)
76
- topic_modeling_agent = TopicModelingAgent()
77
-
78
- words = user_input.split()
79
-
80
- with st.spinner("Generating word embeddings..."):
81
- embeddings = embedding_agent.get_embeddings(words)
82
- st.success("Word Embeddings Generated.")
83
-
84
- with st.spinner("Creating t-SNE visualization..."):
85
- tsne_df = tsne_visualization(embeddings, words)
86
- fig, ax = plt.subplots()
87
- ax.scatter(tsne_df['x'], tsne_df['y'])
88
- for i, word in enumerate(tsne_df['word']):
89
- ax.annotate(word, (tsne_df['x'][i], tsne_df['y'][i]))
90
- st.pyplot(fig)
91
-
92
- with st.spinner("Extracting topics..."):
93
- texts = [user_input, "Another text to improve topic modeling."]
94
- topic_distr, vectorizer = topic_modeling_agent.fit_transform(texts, lang)
95
- topics = topic_modeling_agent.get_topics(vectorizer)
96
- st.subheader("Topics Extracted:")
97
- for topic, words in topics.items():
98
- st.write(f"Topic {topic}: {', '.join(words)}")
99
-
100
- with st.spinner("Computing similarity..."):
101
- text2 = "Otro texto de ejemplo para comparación de similitud." if lang != 'en' else "Another example text for similarity comparison."
102
- similarity_score = similarity_agent.compute_similarity(user_input, text2)
103
- st.write(f"Similarity Score with example text: {similarity_score:.4f}")
104
-
105
- else:
106
- st.warning("Please enter some text to analyze.")
107
-
108
- if __name__ == "__main__":
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.")