Spaces:
Sleeping
Sleeping
halimbahae
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -52,8 +52,8 @@ def main():
|
|
52 |
st.sidebar.subheader("Actions")
|
53 |
if st.sidebar.button("Home"):
|
54 |
display_home()
|
55 |
-
if st.sidebar.button("Word
|
56 |
-
|
57 |
|
58 |
st.sidebar.title("Books")
|
59 |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
|
@@ -87,9 +87,9 @@ def display_table(csv_df):
|
|
87 |
)
|
88 |
st.dataframe(styled_df)
|
89 |
|
90 |
-
def
|
91 |
-
st.title("Word
|
92 |
-
st.write("Select the number of words to display.")
|
93 |
|
94 |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()), key="word_count_book_select")
|
95 |
selected_files = book_files[selected_book]
|
@@ -100,20 +100,24 @@ def display_word_count():
|
|
100 |
|
101 |
if csv_df is not None:
|
102 |
word_counts = {}
|
|
|
|
|
|
|
103 |
for row in csv_df.itertuples(index=False):
|
104 |
for word in str(row[1]).split():
|
105 |
-
if word in
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
109 |
|
110 |
num_words = st.slider("Select Number of Words", min_value=10, max_value=50, value=10, key="word_count_slider")
|
111 |
top_words = sorted(word_counts, key=word_counts.get, reverse=True)[:num_words]
|
112 |
|
113 |
-
|
114 |
-
|
115 |
|
116 |
-
fig = px.bar(
|
117 |
st.plotly_chart(fig)
|
118 |
|
119 |
if __name__ == "__main__":
|
|
|
52 |
st.sidebar.subheader("Actions")
|
53 |
if st.sidebar.button("Home"):
|
54 |
display_home()
|
55 |
+
if st.sidebar.button("Word Cloud"):
|
56 |
+
display_word_cloud()
|
57 |
|
58 |
st.sidebar.title("Books")
|
59 |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
|
|
|
87 |
)
|
88 |
st.dataframe(styled_df)
|
89 |
|
90 |
+
def display_word_cloud():
|
91 |
+
st.title("Word Cloud")
|
92 |
+
st.write("Select the number of words to display and exclude words.")
|
93 |
|
94 |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()), key="word_count_book_select")
|
95 |
selected_files = book_files[selected_book]
|
|
|
100 |
|
101 |
if csv_df is not None:
|
102 |
word_counts = {}
|
103 |
+
exclude_words = st.sidebar.text_input("Exclude Words (comma-separated)", "", key="exclude_words_input")
|
104 |
+
exclude_words = [word.strip() for word in exclude_words.split(",")]
|
105 |
+
|
106 |
for row in csv_df.itertuples(index=False):
|
107 |
for word in str(row[1]).split():
|
108 |
+
if word not in exclude_words:
|
109 |
+
if word in word_counts:
|
110 |
+
word_counts[word] += 1
|
111 |
+
else:
|
112 |
+
word_counts[word] = 1
|
113 |
|
114 |
num_words = st.slider("Select Number of Words", min_value=10, max_value=50, value=10, key="word_count_slider")
|
115 |
top_words = sorted(word_counts, key=word_counts.get, reverse=True)[:num_words]
|
116 |
|
117 |
+
wordcloud_data = {'word': top_words, 'count': [word_counts[word] for word in top_words]}
|
118 |
+
wordcloud_df = pd.DataFrame(wordcloud_data)
|
119 |
|
120 |
+
fig = px.bar(wordcloud_df, x='word', y='count', title="Word Cloud")
|
121 |
st.plotly_chart(fig)
|
122 |
|
123 |
if __name__ == "__main__":
|