halimbahae commited on
Commit
4171868
·
verified ·
1 Parent(s): a069add

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import pandas as pd
3
  import requests
4
  from wordcloud import WordCloud
5
- import matplotlib.pyplot as plt
6
 
7
  # Define array of file paths for each book
8
  book_files = {
@@ -75,9 +75,9 @@ def display_home():
75
  st.write("Welcome to the Hadith Viewer! This is a viewer for the Hadith collections. You can select a book from the dropdown menu on the left to view its contents.")
76
 
77
  def display_table(csv_df):
78
- font_size = st.slider("Adjust Font Size", min_value=10, max_value=30, value=20)
79
  st.write("### Table View")
80
- search_query = st.sidebar.text_input("Search", "")
81
  filtered_df = csv_df[csv_df.apply(lambda row: row.astype(str).str.contains(search_query, case=False).any(), axis=1)]
82
  styled_df = (
83
  filtered_df.style
@@ -89,11 +89,11 @@ def display_table(csv_df):
89
 
90
  def display_word_cloud():
91
  st.title("Word Cloud")
92
- st.write("Displaying the top 10 words from the selected CSV file.")
93
-
94
- selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
95
  selected_files = book_files[selected_book]
96
- selected_file = st.sidebar.selectbox("Select a File", selected_files)
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,13 +107,13 @@ def display_word_cloud():
107
  else:
108
  word_counts[word] = 1
109
 
110
- top_words = sorted(word_counts, key=word_counts.get, reverse=True)[:10]
 
 
 
111
 
112
- wordcloud = WordCloud(width=800, height=400, background_color='white').generate(' '.join(top_words))
113
- plt.figure(figsize=(10, 5))
114
- plt.imshow(wordcloud, interpolation='bilinear')
115
- plt.axis('off')
116
- st.pyplot()
117
 
118
  if __name__ == "__main__":
119
  main()
 
2
  import pandas as pd
3
  import requests
4
  from wordcloud import WordCloud
5
+ import plotly.express as px
6
 
7
  # Define array of file paths for each book
8
  book_files = {
 
75
  st.write("Welcome to the Hadith Viewer! This is a viewer for the Hadith collections. You can select a book from the dropdown menu on the left to view its contents.")
76
 
77
  def display_table(csv_df):
78
+ font_size = st.slider("Adjust Font Size", min_value=10, max_value=30, value=20, key="font_size_slider")
79
  st.write("### Table View")
80
+ search_query = st.sidebar.text_input("Search", "", key="search_input")
81
  filtered_df = csv_df[csv_df.apply(lambda row: row.astype(str).str.contains(search_query, case=False).any(), axis=1)]
82
  styled_df = (
83
  filtered_df.style
 
89
 
90
  def display_word_cloud():
91
  st.title("Word Cloud")
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_cloud_book_select")
95
  selected_files = book_files[selected_book]
96
+ selected_file = st.sidebar.selectbox("Select a File", selected_files, key="word_cloud_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
+ top_words = sorted(word_counts, key=word_counts.get, reverse=True)[:st.slider("Select Number of Words", min_value=10, max_value=50, value=10, key="word_slider")]
111
+
112
+ wordcloud_data = {'word': top_words, 'count': [word_counts[word] for word in top_words]}
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()