halimbahae commited on
Commit
94b0868
·
verified ·
1 Parent(s): 89ffa47

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+ from io import StringIO
5
+
6
+ # Define the base URL for the raw GitHub content
7
+ base_url = "https://raw.githubusercontent.com/halimbahae/Hadith/main"
8
+
9
+ # Define folder names and their corresponding book names
10
+ folders = {
11
+ "Maliks_Muwataa": "Maliks Muwataa",
12
+ "Musnad_Ahmad_Ibn-Hanbal": "Musnad Ahmad Ibn Hanbal",
13
+ "Sahih_Al-Bukhari": "Sahih Al-Bukhari",
14
+ "Sahih_Muslim": "Sahih Muslim",
15
+ "Sunan_Abu-Dawud": "Sunan Abu Dawud",
16
+ "Sunan_Al-Darimi": "Sunan Al-Darimi",
17
+ "Sunan_Al-Nasai": "Sunan Al-Nasai",
18
+ "Sunan_Al-Tirmidhi": "Sunan Al-Tirmidhi",
19
+ "Sunan_Ibn-Maja": "Sunan Ibn Maja"
20
+ }
21
+
22
+ # Define function to read CSV file from GitHub
23
+ def read_csv_from_github(file_path):
24
+ response = requests.get(f"{base_url}/{file_path}")
25
+ if response.status_code == 200:
26
+ return pd.read_csv(StringIO(response.text))
27
+ else:
28
+ return None
29
+
30
+ # Define function to filter and paginate data
31
+ def filter_and_paginate_data(data, rows_per_page):
32
+ start_idx = (st.session_state.page_number - 1) * rows_per_page
33
+ end_idx = start_idx + rows_per_page
34
+ return data.iloc[start_idx:end_idx]
35
+
36
+ # Main Streamlit app
37
+ def main():
38
+ st.sidebar.title("Books")
39
+ selected_folder = st.sidebar.selectbox("Select a Book", list(folders.values()))
40
+
41
+ folder_name = [k for k, v in folders.items() if v == selected_folder][0]
42
+ files = os.listdir(folder_name)
43
+ selected_file = st.sidebar.selectbox("Select a File", files)
44
+
45
+ file_path = os.path.join(folder_name, selected_file)
46
+ if st.button("View File"):
47
+ csv_df = read_csv_from_github(file_path)
48
+ if csv_df is not None:
49
+ st.dataframe(csv_df)
50
+ else:
51
+ st.error("Error loading CSV file")
52
+
53
+ if st.session_state.get("page_number") is None:
54
+ st.session_state.page_number = 1
55
+
56
+ rows_per_page = st.sidebar.number_input("Rows per Page", min_value=1, value=10)
57
+ st.session_state.page_number = st.sidebar.number_input("Page Number", min_value=1, value=st.session_state.page_number)
58
+
59
+ if st.button("Apply Filters"):
60
+ if csv_df is not None:
61
+ filtered_data = filter_and_paginate_data(csv_df, rows_per_page)
62
+ st.write(filtered_data)
63
+
64
+ if __name__ == "__main__":
65
+ main()