Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,14 +42,6 @@ book_files = {
|
|
42 |
]
|
43 |
}
|
44 |
|
45 |
-
# Define function to read CSV file from GitHub
|
46 |
-
def read_csv_from_github(file_path):
|
47 |
-
response = requests.get(f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{file_path}")
|
48 |
-
if response.status_code == 200:
|
49 |
-
return pd.read_csv(response.text)
|
50 |
-
else:
|
51 |
-
return None
|
52 |
-
|
53 |
# Main Streamlit app
|
54 |
def main():
|
55 |
st.title("Hadith Viewer")
|
@@ -59,8 +51,6 @@ def main():
|
|
59 |
selected_files = book_files[selected_book]
|
60 |
selected_file = st.sidebar.selectbox("Select a File", selected_files)
|
61 |
|
62 |
-
csv_df = read_csv_from_github(selected_file)
|
63 |
-
|
64 |
st.sidebar.subheader("Files in Selected Book")
|
65 |
for file in selected_files:
|
66 |
st.sidebar.write(file)
|
@@ -68,20 +58,24 @@ def main():
|
|
68 |
st.sidebar.subheader("Description")
|
69 |
st.sidebar.write("This is a viewer for the Hadith collections. You can select a book from the dropdown menu on the left, and choose whether you want to view the 'Mufassala' version or not.")
|
70 |
|
71 |
-
if
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
main()
|
|
|
42 |
]
|
43 |
}
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# Main Streamlit app
|
46 |
def main():
|
47 |
st.title("Hadith Viewer")
|
|
|
51 |
selected_files = book_files[selected_book]
|
52 |
selected_file = st.sidebar.selectbox("Select a File", selected_files)
|
53 |
|
|
|
|
|
54 |
st.sidebar.subheader("Files in Selected Book")
|
55 |
for file in selected_files:
|
56 |
st.sidebar.write(file)
|
|
|
58 |
st.sidebar.subheader("Description")
|
59 |
st.sidebar.write("This is a viewer for the Hadith collections. You can select a book from the dropdown menu on the left, and choose whether you want to view the 'Mufassala' version or not.")
|
60 |
|
61 |
+
if st.button("View File"):
|
62 |
+
file_url = f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{selected_book}/{selected_file}"
|
63 |
+
csv_df = pd.read_csv(file_url)
|
64 |
+
|
65 |
+
if csv_df is not None:
|
66 |
+
# Display dataframe with search, filters, and pagination
|
67 |
+
st.dataframe(csv_df)
|
68 |
+
# Show rows per page selector
|
69 |
+
rows_per_page = st.number_input("Rows per Page", min_value=1, value=10)
|
70 |
+
# Show page number selector
|
71 |
+
page_number = st.number_input("Page Number", min_value=1, value=1)
|
72 |
+
# Slice dataframe based on page number and rows per page
|
73 |
+
start_idx = (page_number - 1) * rows_per_page
|
74 |
+
end_idx = start_idx + rows_per_page
|
75 |
+
paginated_df = csv_df.iloc[start_idx:end_idx]
|
76 |
+
st.write(paginated_df)
|
77 |
+
else:
|
78 |
+
st.error("Error loading CSV file")
|
79 |
|
80 |
if __name__ == "__main__":
|
81 |
main()
|