Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,8 +52,6 @@ def 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,38 +85,35 @@ def display_table(csv_df):
|
|
87 |
)
|
88 |
st.dataframe(styled_df)
|
89 |
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
92 |
st.write("Select the number of words to display and exclude words.")
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
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__":
|
124 |
main()
|
|
|
52 |
st.sidebar.subheader("Actions")
|
53 |
if st.sidebar.button("Home"):
|
54 |
display_home()
|
|
|
|
|
55 |
|
56 |
st.sidebar.title("Books")
|
57 |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
|
|
|
85 |
)
|
86 |
st.dataframe(styled_df)
|
87 |
|
88 |
+
if st.button("Word Count"):
|
89 |
+
display_word_count(filtered_df)
|
90 |
+
|
91 |
+
def display_word_count(df):
|
92 |
+
st.title("Word Count")
|
93 |
st.write("Select the number of words to display and exclude words.")
|
94 |
|
95 |
+
word_count = st.slider("Select Number of Words", min_value=10, max_value=50, value=10, key="word_count_slider")
|
96 |
+
|
97 |
+
words_to_exclude = st.text_input("Words to Exclude (comma-separated)", "", key="exclude_words_input")
|
98 |
+
words_to_exclude = [word.strip() for word in words_to_exclude.split(",")]
|
99 |
+
|
100 |
+
word_counts = {}
|
101 |
+
for row in df.itertuples(index=False):
|
102 |
+
for word in str(row[1]).split():
|
103 |
+
if word not in words_to_exclude:
|
104 |
+
if word in word_counts:
|
105 |
+
word_counts[word] += 1
|
106 |
+
else:
|
107 |
+
word_counts[word] = 1
|
108 |
+
|
109 |
+
sorted_word_counts = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)[:word_count]
|
110 |
+
words, counts = zip(*sorted_word_counts)
|
111 |
+
|
112 |
+
wordcloud_data = {'word': words, 'count': counts}
|
113 |
+
wordcloud_df = pd.DataFrame(wordcloud_data)
|
114 |
+
|
115 |
+
fig = px.bar(wordcloud_df, x='word', y='count', title="Word Cloud")
|
116 |
+
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
if __name__ == "__main__":
|
119 |
main()
|