File size: 4,994 Bytes
a069add
 
 
 
4171868
a069add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b86c850
 
a069add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4171868
a069add
4171868
a069add
 
 
 
 
 
 
 
 
b86c850
 
 
4171868
a071dee
a069add
a071dee
a069add
 
 
 
 
 
b86c850
 
 
a069add
 
b86c850
 
 
 
 
a069add
a071dee
 
4171868
b86c850
 
a069add
b86c850
4171868
a069add
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import streamlit as st
import pandas as pd
import requests
from wordcloud import WordCloud
import plotly.express as px

# 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()
    if st.sidebar.button("Word Cloud"):
        display_word_cloud()

    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, key="font_size_slider")
    st.write("### Table View")
    search_query = st.sidebar.text_input("Search", "", key="search_input")
    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)

def display_word_cloud():
    st.title("Word Cloud")
    st.write("Select the number of words to display and exclude words.")

    selected_book = st.sidebar.selectbox("Select a Book", list(book_files.keys()), key="word_count_book_select")
    selected_files = book_files[selected_book]
    selected_file = st.sidebar.selectbox("Select a File", selected_files, key="word_count_file_select")
    
    file_url = f"https://raw.githubusercontent.com/halimbahae/Hadith/main/{selected_book}/{selected_file}"
    csv_df = pd.read_csv(file_url, header=None) 
    
    if csv_df is not None:
        word_counts = {}
        exclude_words = st.sidebar.text_input("Exclude Words (comma-separated)", "", key="exclude_words_input")
        exclude_words = [word.strip() for word in exclude_words.split(",")]
        
        for row in csv_df.itertuples(index=False):
            for word in str(row[1]).split():
                if word not in exclude_words:
                    if word in word_counts:
                        word_counts[word] += 1
                    else:
                        word_counts[word] = 1
        
        num_words = st.slider("Select Number of Words", min_value=10, max_value=50, value=10, key="word_count_slider")
        top_words = sorted(word_counts, key=word_counts.get, reverse=True)[:num_words]
        
        wordcloud_data = {'word': top_words, 'count': [word_counts[word] for word in top_words]}
        wordcloud_df = pd.DataFrame(wordcloud_data)
        
        fig = px.bar(wordcloud_df, x='word', y='count', title="Word Cloud")
        st.plotly_chart(fig)

if __name__ == "__main__":
    main()