Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# Define array of file paths for each book
|
| 4 |
book_files = {
|
|
@@ -40,6 +42,14 @@ book_files = {
|
|
| 40 |
]
|
| 41 |
}
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Main Streamlit app
|
| 44 |
def main():
|
| 45 |
st.title("Hadith Viewer")
|
|
@@ -47,6 +57,9 @@ def main():
|
|
| 47 |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
|
| 48 |
|
| 49 |
selected_files = book_files[selected_book]
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
st.sidebar.subheader("Files in Selected Book")
|
| 52 |
for file in selected_files:
|
|
@@ -55,9 +68,20 @@ def main():
|
|
| 55 |
st.sidebar.subheader("Description")
|
| 56 |
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.")
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
main()
|
|
|
|
| 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 = {
|
|
|
|
| 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")
|
|
|
|
| 57 |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()))
|
| 58 |
|
| 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:
|
|
|
|
| 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 csv_df is not None:
|
| 72 |
+
# Display dataframe with search, filters, and pagination
|
| 73 |
+
st.dataframe(csv_df)
|
| 74 |
+
# Show rows per page selector
|
| 75 |
+
rows_per_page = st.number_input("Rows per Page", min_value=1, value=10)
|
| 76 |
+
# Show page number selector
|
| 77 |
+
page_number = st.number_input("Page Number", min_value=1, value=1)
|
| 78 |
+
# Slice dataframe based on page number and rows per page
|
| 79 |
+
start_idx = (page_number - 1) * rows_per_page
|
| 80 |
+
end_idx = start_idx + rows_per_page
|
| 81 |
+
paginated_df = csv_df.iloc[start_idx:end_idx]
|
| 82 |
+
st.write(paginated_df)
|
| 83 |
+
else:
|
| 84 |
+
st.error("Error loading CSV file")
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
main()
|