Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import requests | |
# Define array of file paths for each book | |
book_files = { | |
"Maliks_Muwataa": [ | |
"maliks_muwataa_ahadith.utf8.csv", | |
"maliks_muwataa_ahadith_mushakkala_mufassala.utf8.csv" | |
], | |
"Musnad_Ahmad_Ibn-Hanbal": [ | |
"musnad_ahmad_ibn-hanbal_ahadith.utf8.csv", | |
"musnad_ahmad_ibn-hanbal_ahadith_mushakkala.utf8.csv" | |
], | |
"Sahih_Al-Bukhari": [ | |
"sahih_al-bukhari_ahadith.utf8.csv", | |
"sahih_al-bukhari_ahadith_mushakkala_mufassala.utf8.csv" | |
], | |
"Sahih_Muslim": [ | |
"sahih_muslim_ahadith.utf8.csv", | |
"sahih_muslim_ahadith_mushakkala_mufassala.utf8.csv" | |
], | |
"Sunan_Abu-Dawud": [ | |
"sunan_abu-dawud_ahadith.utf8.csv", | |
"sunan_abu-dawud_ahadith_mushakkala_mufassala.utf8.csv" | |
], | |
"Sunan_Al-Darimi": [ | |
"sunan_al-darimi_ahadith.utf8.csv", | |
"sunan_al-darimi_ahadith_mushakkala_mufassala.utf8.csv" | |
], | |
"Sunan_Al-Nasai": [ | |
"sunan_al-nasai_ahadith.utf8.csv", | |
"sunan_al-nasai_ahadith_mushakkala_mufassala.utf8.csv" | |
], | |
"Sunan_Al-Tirmidhi": [ | |
"sunan_al-tirmidhi_ahadith.utf8.csv", | |
"sunan_al-tirmidhi_ahadith_mushakkala_mufassala.utf8.csv" | |
], | |
"Sunan_Ibn-Maja": [ | |
"sunan_ibn-maja_ahadith.utf8.csv", | |
"sunan_ibn-maja_ahadith_mushakkala_mufassala.utf8.csv" | |
] | |
} | |
# Main Streamlit app | |
def main(): | |
st.title("Hadith Viewer") | |
st.sidebar.title("Navigation") | |
st.sidebar.subheader("Actions") | |
if st.sidebar.button("Home"): | |
display_home() | |
st.sidebar.title("Books") | |
selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys())) | |
selected_files = book_files[selected_book] | |
selected_file = st.sidebar.selectbox("Select a File", selected_files) | |
# Load CSV file immediately when selected from the list | |
file_url = f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{selected_book}/{selected_file}" | |
csv_df = pd.read_csv(file_url, header=None) # Assuming no header in CSV files | |
if csv_df is not None: | |
# Display dataframe with search | |
display_table(csv_df) | |
def display_home(): | |
st.title("Hadith Viewer") | |
st.image("https://raw.githubusercontent.com/halimbahae/Hadith/main/Hadith_Books.jpg", caption="Hadith Books", use_column_width=True) | |
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.") | |
# def display_table(csv_df): | |
# font_size = st.slider("Adjust Font Size", min_value=10, max_value=30, value=20) | |
# st.write("### Table View") | |
# search_query = st.sidebar.text_input("Search", "") | |
# filtered_df = csv_df[csv_df.apply(lambda row: row.astype(str).str.contains(search_query, case=False).any(), axis=1)] | |
# styled_df = filtered_df.style.set_properties(**{'font-size': f'{font_size}px'}) | |
# styled_df = styled_df.set_table_styles([{'selector': 'tr', 'props': [('line-height', '30px')]}]) | |
# st.dataframe(styled_df) | |
def display_table(csv_df): | |
font_size = st.slider("Adjust Font Size", min_value=10, max_value=30, value=20) | |
st.write("### Table View") | |
search_query = st.sidebar.text_input("Search", "") | |
filtered_df = csv_df[csv_df.apply(lambda row: row.astype(str).str.contains(search_query, case=False).any(), axis=1)] | |
styled_df = ( | |
filtered_df.style | |
.set_properties(**{'font-size': f'{font_size}px'}) | |
.set_table_styles([{'selector': 'th', 'props': [('font-size', f'{font_size}px')]}, | |
{'selector': 'td', 'props': [('font-size', f'{font_size}px'), ('line-height', '1.5')]}]) | |
) | |
st.dataframe(styled_df) | |
if __name__ == "__main__": | |
main() | |