halimbahae commited on
Commit
8441f78
·
verified ·
1 Parent(s): 482d631

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import requests
 
4
  # Define array of file paths for each book
5
  book_files = {
6
  "Maliks_Muwataa": [
@@ -40,34 +41,43 @@ book_files = {
40
  "sunan_ibn-maja_ahadith_mushakkala_mufassala.utf8.csv"
41
  ]
42
  }
 
43
  # Main Streamlit app
44
  def main():
45
  st.title("Hadith Viewer")
 
46
  st.sidebar.title("Navigation")
47
  st.sidebar.subheader("Actions")
48
  if st.sidebar.button("Home"):
49
  display_home()
 
50
  st.sidebar.title("Books")
51
  selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
 
52
  selected_files = book_files[selected_book]
53
  selected_file = st.sidebar.selectbox("Select a File", selected_files)
 
54
  # Load CSV file immediately when selected from the list
55
  file_url = f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{selected_book}/{selected_file}"
56
  csv_df = pd.read_csv(file_url, header=None) # Assuming no header in CSV files
 
57
  if csv_df is not None:
58
  # Display dataframe with search
59
  display_table(csv_df)
 
60
  def display_home():
61
  st.title("Hadith Viewer")
62
  st.image("https://raw.githubusercontent.com/halimbahae/Hadith/main/Hadith_Books.jpg", caption="Hadith Books", use_column_width=True)
63
  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.")
 
64
  def display_table(csv_df):
65
  font_size = st.slider("Adjust Font Size", min_value=10, max_value=30, value=20)
66
  st.write("### Table View")
67
  search_query = st.sidebar.text_input("Search", "")
68
  filtered_df = csv_df[csv_df.apply(lambda row: row.astype(str).str.contains(search_query, case=False).any(), axis=1)]
69
  styled_df = filtered_df.style.set_properties(**{'font-size': f'{font_size}px'})
 
70
  st.dataframe(styled_df)
 
71
  if __name__ == "__main__":
72
  main()
73
-
 
1
  import streamlit as st
2
  import pandas as pd
3
  import requests
4
+
5
  # Define array of file paths for each book
6
  book_files = {
7
  "Maliks_Muwataa": [
 
41
  "sunan_ibn-maja_ahadith_mushakkala_mufassala.utf8.csv"
42
  ]
43
  }
44
+
45
  # Main Streamlit app
46
  def main():
47
  st.title("Hadith Viewer")
48
+
49
  st.sidebar.title("Navigation")
50
  st.sidebar.subheader("Actions")
51
  if st.sidebar.button("Home"):
52
  display_home()
53
+
54
  st.sidebar.title("Books")
55
  selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
56
+
57
  selected_files = book_files[selected_book]
58
  selected_file = st.sidebar.selectbox("Select a File", selected_files)
59
+
60
  # Load CSV file immediately when selected from the list
61
  file_url = f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{selected_book}/{selected_file}"
62
  csv_df = pd.read_csv(file_url, header=None) # Assuming no header in CSV files
63
+
64
  if csv_df is not None:
65
  # Display dataframe with search
66
  display_table(csv_df)
67
+
68
  def display_home():
69
  st.title("Hadith Viewer")
70
  st.image("https://raw.githubusercontent.com/halimbahae/Hadith/main/Hadith_Books.jpg", caption="Hadith Books", use_column_width=True)
71
  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.")
72
+
73
  def display_table(csv_df):
74
  font_size = st.slider("Adjust Font Size", min_value=10, max_value=30, value=20)
75
  st.write("### Table View")
76
  search_query = st.sidebar.text_input("Search", "")
77
  filtered_df = csv_df[csv_df.apply(lambda row: row.astype(str).str.contains(search_query, case=False).any(), axis=1)]
78
  styled_df = filtered_df.style.set_properties(**{'font-size': f'{font_size}px'})
79
+ styled_df = styled_df.set_table_styles([{'selector': 'tr', 'props': [('line-height', '30px')]}])
80
  st.dataframe(styled_df)
81
+
82
  if __name__ == "__main__":
83
  main()