Spaces:
Sleeping
Sleeping
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,13 +87,13 @@ 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="
|
95 |
selected_files = book_files[selected_book]
|
96 |
-
selected_file = st.sidebar.selectbox("Select a File", selected_files, key="
|
97 |
|
98 |
file_url = f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{selected_book}/{selected_file}"
|
99 |
csv_df = pd.read_csv(file_url, header=None)
|
@@ -107,12 +107,13 @@ def display_word_cloud():
|
|
107 |
else:
|
108 |
word_counts[word] = 1
|
109 |
|
110 |
-
|
|
|
111 |
|
112 |
-
|
113 |
-
|
114 |
|
115 |
-
fig = px.bar(
|
116 |
st.plotly_chart(fig)
|
117 |
|
118 |
if __name__ == "__main__":
|
|
|
52 |
st.sidebar.subheader("Actions")
|
53 |
if st.sidebar.button("Home"):
|
54 |
display_home()
|
55 |
+
if st.sidebar.button("Word Count"):
|
56 |
+
display_word_count()
|
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_count():
|
91 |
+
st.title("Word count")
|
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]
|
96 |
+
selected_file = st.sidebar.selectbox("Select a File", selected_files, key="word_count_file_select")
|
97 |
|
98 |
file_url = f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{selected_book}/{selected_file}"
|
99 |
csv_df = pd.read_csv(file_url, header=None)
|
|
|
107 |
else:
|
108 |
word_counts[word] = 1
|
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 |
+
wordcount_data = {'word': top_words, 'count': [word_counts[word] for word in top_words]}
|
114 |
+
wordcount_df = pd.DataFrame(wordcount_data)
|
115 |
|
116 |
+
fig = px.bar(wordcount_df, x='word', y='count', title="Word count")
|
117 |
st.plotly_chart(fig)
|
118 |
|
119 |
if __name__ == "__main__":
|