Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from wordcloud import WordCloud
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from sklearn.feature_extraction.text import CountVectorizer
|
| 5 |
from sklearn.decomposition import LatentDirichletAllocation
|
|
@@ -42,12 +41,16 @@ def topic_modeling(texts, n_components):
|
|
| 42 |
topics[f"Topic {topic_idx + 1}"] = [features[i] for i in topic.argsort()[:-21:-1]]
|
| 43 |
return topics
|
| 44 |
|
| 45 |
-
def
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
ax.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
return fig
|
| 52 |
|
| 53 |
def get_top_trigrams(text, n=10):
|
|
@@ -103,9 +106,9 @@ if uploaded_file is not None:
|
|
| 103 |
for trigram, count in top_trigrams:
|
| 104 |
st.write(f"{trigram}: {count}")
|
| 105 |
|
| 106 |
-
st.subheader("
|
| 107 |
-
color = st.color_picker("
|
| 108 |
-
fig =
|
| 109 |
st.pyplot(fig)
|
| 110 |
|
| 111 |
except Exception as e:
|
|
@@ -117,5 +120,5 @@ st.sidebar.markdown("""
|
|
| 117 |
2. 텍스트 파일(.txt)을 업로드하세요.
|
| 118 |
3. 토픽 모델링의 토픽 수를 선택하세요.
|
| 119 |
4. 상위 10개 Trigram을 확인하세요.
|
| 120 |
-
5.
|
| 121 |
""")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
from sklearn.feature_extraction.text import CountVectorizer
|
| 4 |
from sklearn.decomposition import LatentDirichletAllocation
|
|
|
|
| 41 |
topics[f"Topic {topic_idx + 1}"] = [features[i] for i in topic.argsort()[:-21:-1]]
|
| 42 |
return topics
|
| 43 |
|
| 44 |
+
def generate_word_frequency_chart(text, color, n=20):
|
| 45 |
+
words = text.split()
|
| 46 |
+
word_freq = Counter(words)
|
| 47 |
+
top_words = dict(word_freq.most_common(n))
|
| 48 |
+
|
| 49 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
| 50 |
+
ax.barh(list(top_words.keys()), list(top_words.values()), color=color)
|
| 51 |
+
ax.invert_yaxis() # 가장 빈도가 높은 단어를 위쪽에 표시
|
| 52 |
+
ax.set_title("Top {} Words".format(n))
|
| 53 |
+
plt.tight_layout()
|
| 54 |
return fig
|
| 55 |
|
| 56 |
def get_top_trigrams(text, n=10):
|
|
|
|
| 106 |
for trigram, count in top_trigrams:
|
| 107 |
st.write(f"{trigram}: {count}")
|
| 108 |
|
| 109 |
+
st.subheader("단어 빈도 차트")
|
| 110 |
+
color = st.color_picker("막대 색상 선택", "#1f77b4")
|
| 111 |
+
fig = generate_word_frequency_chart(preprocessed_text, color)
|
| 112 |
st.pyplot(fig)
|
| 113 |
|
| 114 |
except Exception as e:
|
|
|
|
| 120 |
2. 텍스트 파일(.txt)을 업로드하세요.
|
| 121 |
3. 토픽 모델링의 토픽 수를 선택하세요.
|
| 122 |
4. 상위 10개 Trigram을 확인하세요.
|
| 123 |
+
5. 단어 빈도 차트의 막대 색상을 선택할 수 있습니다.
|
| 124 |
""")
|