Spaces:
Sleeping
Sleeping
Commit
Β·
1d969fa
1
Parent(s):
394ad15
major updates on al-quran
Browse filesSigned-off-by: Shoaib <[email protected]>
This view is limited to 50 files because it contains too many changes. Β
See raw diff
- plots/Al-Kahf (The Cave) word cloud.png +0 -0
- plots/Al-Takasur (The piling up) word cloud.png +0 -0
- plots/Ar-Rahman (the Most Gracious) word cloud.png +0 -0
- plots/Descriptive Statistics of Ayah Count per Surah.png +0 -0
- plots/Frequency of prophet names in Quran.png +0 -0
- plots/Quran Word Cloud.png +0 -0
- Word Count per Surah.png +0 -0
- plots/Some Important things which Quran has emphasized.png +0 -0
- warned.png +0 -0
- plots/Word Count per Surah.png +0 -0
- plots/number of verses 1-39.png +0 -0
- plots/number of verses 40-79.png +0 -0
- plots/number of verses 80-114.png +0 -0
- readme.md +0 -2
- src/al-quran-english-exploratory-data-analysis.ipynb +0 -0
- src/al_quran.txt +0 -0
- src/al_quran_gradio.py +83 -0
- src/components/search_tab.py +101 -0
- src/components/statistics_tab.py +79 -0
- src/components/surah_tab.py +90 -0
- src/components/utils.py +31 -0
- src/gradio_app.py +39 -0
- src/styles/styles.css +83 -0
- word_cloud/surah_100_Al-/342/200/230Adiyah (the Runners).png +0 -0
- word_cloud/surah_101_Al-Qari/342/200/231ah (the Striking Hour).png +0 -0
- word_cloud/surah_102_At-Takathur (the Piling Up).png +0 -0
- word_cloud/surah_103_Al-/342/200/230Asr (the Time).png +0 -0
- word_cloud/surah_104_Al-Humazah (the Slanderer).png +0 -0
- word_cloud/surah_105_Al-Fil (the Elephant).png +0 -0
- word_cloud/surah_106_Quraish (Quraish).png +0 -0
- word_cloud/surah_107_Al-Ma/342/200/231un (the Assistance).png +0 -0
- word_cloud/surah_108_Al-Kauthar (the River of Abundance).png +0 -0
- word_cloud/surah_109_Al-Kafirun (the Disbelievers).png +0 -0
- word_cloud/surah_10_Yunus (Yunus).png +0 -0
- word_cloud/surah_110_An-Nasr (the Help).png +0 -0
- word_cloud/surah_111_Al-Masad (the Palm Fiber).png +0 -0
- word_cloud/surah_112_Al-Ikhlas (the Sincerity).png +0 -0
- word_cloud/surah_113_Al-Falaq (the Daybreak).png +0 -0
- word_cloud/surah_114_An-Nas (Mankind).png +0 -0
- word_cloud/surah_11_Hud (Hud).png +0 -0
- word_cloud/surah_12_Yusuf (Yusuf).png +0 -0
- word_cloud/surah_13_Ar-Ra/342/200/231d (the Thunder).png +0 -0
- word_cloud/surah_14_Ibrahim (Ibrahim).png +0 -0
- word_cloud/surah_15_Al-Hijr (the Rocky Tract).png +0 -0
- word_cloud/surah_16_An-Nahl (the Bees).png +0 -0
- word_cloud/surah_17_Al-Isra/342/200/231 (the Night Journey).png +0 -0
- word_cloud/surah_18_Al-Kahf (the Cave).png +0 -0
- word_cloud/surah_19_Maryam (Maryam).png +0 -0
- word_cloud/surah_1_Al-Fatihah (the Opening).png +0 -0
- word_cloud/surah_20_Ta-Ha (Ta-Ha).png +0 -0
plots/Al-Kahf (The Cave) word cloud.png
ADDED
![]() |
plots/Al-Takasur (The piling up) word cloud.png
ADDED
![]() |
plots/Ar-Rahman (the Most Gracious) word cloud.png
ADDED
![]() |
plots/Descriptive Statistics of Ayah Count per Surah.png
ADDED
![]() |
plots/Frequency of prophet names in Quran.png
ADDED
![]() |
plots/Quran Word Cloud.png
ADDED
![]() |
Word Count per Surah.png
RENAMED
File without changes
|
plots/Some Important things which Quran has emphasized.png
ADDED
![]() |
warned.png
RENAMED
File without changes
|
plots/Word Count per Surah.png
ADDED
![]() |
plots/number of verses 1-39.png
ADDED
![]() |
plots/number of verses 40-79.png
ADDED
![]() |
plots/number of verses 80-114.png
ADDED
![]() |
readme.md
CHANGED
@@ -105,5 +105,3 @@ Open source under MIT License
|
|
105 |
|
106 |
- Quran translation: Yusuf Ali
|
107 |
- Application development: [email protected]
|
108 |
-
|
109 |
-
|
|
|
105 |
|
106 |
- Quran translation: Yusuf Ali
|
107 |
- Application development: [email protected]
|
|
|
|
src/al-quran-english-exploratory-data-analysis.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
src/al_quran.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
src/al_quran_gradio.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import re
|
3 |
+
import gradio as gr
|
4 |
+
from collections import defaultdict
|
5 |
+
|
6 |
+
# Load the dataset
|
7 |
+
quran_english_with_surah = pd.read_csv('/Users/salam9/Desktop/quran/en.yusufali.csv')
|
8 |
+
surah_names = pd.read_csv('/Users/salam9/Desktop/quran/surah_names_english.csv', names=['Surah', 'Surah Name'])
|
9 |
+
surah_names["Surah Name"] = surah_names["Surah Name"].str[1:]
|
10 |
+
quran_english_with_surah = quran_english_with_surah.merge(surah_names, on='Surah')
|
11 |
+
quran_english_with_surah.index = pd.RangeIndex(start=1, stop=len(quran_english_with_surah) + 1)
|
12 |
+
|
13 |
+
# Create the inverted index
|
14 |
+
def create_inverted_index(dataframe):
|
15 |
+
inverted_index = defaultdict(list)
|
16 |
+
for index, row in dataframe.iterrows():
|
17 |
+
words = row['Text'].split()
|
18 |
+
for word in words:
|
19 |
+
word = re.sub(r'\W+', '', word).lower()
|
20 |
+
if word:
|
21 |
+
inverted_index[word].append((row['Surah'], row['Ayah']))
|
22 |
+
return inverted_index
|
23 |
+
|
24 |
+
inverted_index = create_inverted_index(quran_english_with_surah)
|
25 |
+
|
26 |
+
# Define the search function
|
27 |
+
def search_quran(keyword):
|
28 |
+
results = []
|
29 |
+
if keyword.lower() not in inverted_index:
|
30 |
+
return f"No occurrences found for '{keyword}'"
|
31 |
+
|
32 |
+
verse_ids = inverted_index[keyword.lower()]
|
33 |
+
for verse_id in verse_ids:
|
34 |
+
surah_num, verse_num = verse_id
|
35 |
+
verse_data = quran_english_with_surah[(quran_english_with_surah['Surah'] == surah_num) &
|
36 |
+
(quran_english_with_surah['Ayah'] == verse_num)]
|
37 |
+
surah_name = verse_data['Surah Name'].iloc[0]
|
38 |
+
verse_text = verse_data['Text'].iloc[0]
|
39 |
+
highlighted_text = re.sub(f"(?i)({keyword})", r'<mark style="background-color: yellow; color: black;">\1</mark>', verse_text)
|
40 |
+
results.append(f"<div style='padding: 10px; border-bottom: 1px solid #ccc;'>"
|
41 |
+
f"<strong>Surah:</strong> {surah_name}<br>"
|
42 |
+
f"<strong>Reference:</strong> {surah_num}:{verse_num}<br>"
|
43 |
+
f"<strong>Occurrences in verse:</strong> {verse_text.lower().count(keyword.lower())}<br>"
|
44 |
+
f"<strong>Text:</strong> {highlighted_text}</div>")
|
45 |
+
return '<div style="max-height: 500px; overflow-y: auto; width: 100%; font-size: 18px;">' + ''.join(results) + '</div>'
|
46 |
+
|
47 |
+
# Create the Gradio interface with a modern theme
|
48 |
+
css = """
|
49 |
+
body {
|
50 |
+
font-family: 'Arial', sans-serif;
|
51 |
+
background-color: #f4f4f9;
|
52 |
+
color: #333;
|
53 |
+
margin: 0;
|
54 |
+
padding: 0;
|
55 |
+
}
|
56 |
+
.gradio-container {
|
57 |
+
max-width: 100%;
|
58 |
+
margin: 0 auto;
|
59 |
+
padding: 20px;
|
60 |
+
}
|
61 |
+
.gradio-input, .gradio-output {
|
62 |
+
width: 100%;
|
63 |
+
}
|
64 |
+
.gradio-title {
|
65 |
+
font-size: 2em;
|
66 |
+
font-weight: bold;
|
67 |
+
margin-bottom: 20px;
|
68 |
+
}
|
69 |
+
.gradio-description {
|
70 |
+
font-size: 1.2em;
|
71 |
+
margin-bottom: 20px;
|
72 |
+
}
|
73 |
+
"""
|
74 |
+
|
75 |
+
iface = gr.Interface(
|
76 |
+
fn=search_quran,
|
77 |
+
inputs=gr.Textbox(label="Enter a keyword"),
|
78 |
+
outputs=gr.HTML(label="Search Results"),
|
79 |
+
title='Quran Keyword Search',
|
80 |
+
description='Enter a keyword to search in the Quran',
|
81 |
+
css=css
|
82 |
+
)
|
83 |
+
iface.launch(share=True)
|
src/components/search_tab.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import re
|
3 |
+
from collections import defaultdict
|
4 |
+
|
5 |
+
def create_inverted_index(dataframe):
|
6 |
+
"""
|
7 |
+
Create an inverted index from the Quran dataset for efficient word searching.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
dataframe (pd.DataFrame): The Quran dataset with Text column
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
defaultdict: A dictionary mapping words to their locations (surah, ayah)
|
14 |
+
"""
|
15 |
+
inverted_index = defaultdict(list)
|
16 |
+
for index, row in dataframe.iterrows():
|
17 |
+
words = row['Text'].split()
|
18 |
+
for word in words:
|
19 |
+
word = re.sub(r'\W+', '', word).lower()
|
20 |
+
if word:
|
21 |
+
inverted_index[word].append((row['Surah'], row['Ayah']))
|
22 |
+
return inverted_index
|
23 |
+
|
24 |
+
def search_quran(keyword, quran_data, inverted_index):
|
25 |
+
"""
|
26 |
+
Search for a keyword in the Quran and return formatted results.
|
27 |
+
|
28 |
+
Args:
|
29 |
+
keyword (str): The word to search for
|
30 |
+
quran_data (pd.DataFrame): The Quran dataset
|
31 |
+
inverted_index (defaultdict): The inverted index for word searching
|
32 |
+
|
33 |
+
Returns:
|
34 |
+
str: HTML formatted search results
|
35 |
+
"""
|
36 |
+
results = []
|
37 |
+
if not keyword or keyword.lower() not in inverted_index:
|
38 |
+
return f"No occurrences found for '{keyword}'"
|
39 |
+
|
40 |
+
verse_ids = inverted_index[keyword.lower()]
|
41 |
+
for verse_id in verse_ids:
|
42 |
+
surah_num, verse_num = verse_id
|
43 |
+
verse_data = quran_data[(quran_data['Surah'] == surah_num) &
|
44 |
+
(quran_data['Ayah'] == verse_num)]
|
45 |
+
surah_name = verse_data['Surah Name'].iloc[0]
|
46 |
+
verse_text = verse_data['Text'].iloc[0]
|
47 |
+
highlighted_text = re.sub(
|
48 |
+
f"(?i)({keyword})",
|
49 |
+
r'<mark style="background-color: yellow; color: black;">\1</mark>',
|
50 |
+
verse_text
|
51 |
+
)
|
52 |
+
results.append(
|
53 |
+
f"<div style='padding: 10px; border-bottom: 1px solid #ccc;'>"
|
54 |
+
f"<strong>Surah:</strong> {surah_name}<br>"
|
55 |
+
f"<strong>Reference:</strong> {surah_num}:{verse_num}<br>"
|
56 |
+
f"<strong>Occurrences in verse:</strong> {verse_text.lower().count(keyword.lower())}<br>"
|
57 |
+
f"<strong>Text:</strong> {highlighted_text}</div>"
|
58 |
+
)
|
59 |
+
return '<div style="max-height: 500px; overflow-y: auto; width: 100%; font-size: 18px;">' + ''.join(results) + '</div>'
|
60 |
+
|
61 |
+
def create_search_tab(quran_data):
|
62 |
+
"""
|
63 |
+
Create the search tab interface with description and functionality.
|
64 |
+
|
65 |
+
Args:
|
66 |
+
quran_data (pd.DataFrame): The Quran dataset
|
67 |
+
|
68 |
+
Returns:
|
69 |
+
gr.Tab: The configured search tab
|
70 |
+
"""
|
71 |
+
inverted_index = create_inverted_index(quran_data)
|
72 |
+
|
73 |
+
with gr.Tab("Search") as tab:
|
74 |
+
gr.Markdown("# Quran Keyword Search")
|
75 |
+
gr.Markdown("""
|
76 |
+
<div class='tab-description'>
|
77 |
+
Welcome to the Quran Search tool! This feature allows you to:
|
78 |
+
- Search for any word or phrase in the English translation
|
79 |
+
- See highlighted matches in their original context
|
80 |
+
- View Surah name and verse references for each result
|
81 |
+
- Track the number of occurrences in each verse
|
82 |
+
</div>
|
83 |
+
""")
|
84 |
+
|
85 |
+
keyword_input = gr.Textbox(
|
86 |
+
label="Enter a keyword",
|
87 |
+
placeholder="Type a word to search in the Quran"
|
88 |
+
)
|
89 |
+
search_results = gr.HTML(label="Search Results")
|
90 |
+
search_button = gr.Button("Search")
|
91 |
+
|
92 |
+
def search_wrapper(keyword):
|
93 |
+
return search_quran(keyword, quran_data, inverted_index)
|
94 |
+
|
95 |
+
search_button.click(
|
96 |
+
search_wrapper,
|
97 |
+
inputs=keyword_input,
|
98 |
+
outputs=search_results
|
99 |
+
)
|
100 |
+
|
101 |
+
return tab
|
src/components/statistics_tab.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import seaborn as sns
|
4 |
+
from .utils import plt_to_html
|
5 |
+
|
6 |
+
def generate_plots_and_tables(quran_data):
|
7 |
+
"""
|
8 |
+
Generate visualization plots and statistics tables for the Quran data.
|
9 |
+
|
10 |
+
Args:
|
11 |
+
quran_data (pd.DataFrame): The Quran dataset
|
12 |
+
|
13 |
+
Returns:
|
14 |
+
str: HTML formatted plots and tables
|
15 |
+
"""
|
16 |
+
# Plot 1: Number of verses in each chapter
|
17 |
+
plt.figure(figsize=(30, 10))
|
18 |
+
sns.set_style('whitegrid')
|
19 |
+
value_counts = quran_data['Surah Name'].value_counts()
|
20 |
+
ax = sns.barplot(
|
21 |
+
x=value_counts.index,
|
22 |
+
y=value_counts.values,
|
23 |
+
hue=value_counts.index,
|
24 |
+
palette='viridis',
|
25 |
+
legend=False
|
26 |
+
)
|
27 |
+
|
28 |
+
# Add value labels on bars
|
29 |
+
for container in ax.containers:
|
30 |
+
ax.bar_label(container, size=10, padding=2)
|
31 |
+
|
32 |
+
# Customize plot
|
33 |
+
ax.set_title('Number of Verses in Each Chapter', fontweight='bold', fontsize=14)
|
34 |
+
ax.set_ylabel('Number of Verses', fontweight='bold')
|
35 |
+
ax.set_xlabel('Surah Name', fontweight='bold')
|
36 |
+
plt.xticks(rotation=90)
|
37 |
+
plt.tight_layout()
|
38 |
+
|
39 |
+
# Convert plot to HTML
|
40 |
+
plot1_html = plt_to_html(plt)
|
41 |
+
|
42 |
+
# Generate statistics table
|
43 |
+
surah_counts = quran_data['Surah Name'].value_counts().reset_index()
|
44 |
+
surah_counts.columns = ['Surah Name', 'Ayah Count']
|
45 |
+
table_html = surah_counts.to_html(
|
46 |
+
index=False,
|
47 |
+
classes='table table-striped table-hover'
|
48 |
+
)
|
49 |
+
table_html = f'<div style="max-height: 300px; overflow-y: auto;">{table_html}</div>'
|
50 |
+
|
51 |
+
return plot1_html + table_html
|
52 |
+
|
53 |
+
def create_statistics_tab(quran_data):
|
54 |
+
"""
|
55 |
+
Create the statistics tab interface with description and visualizations.
|
56 |
+
|
57 |
+
Args:
|
58 |
+
quran_data (pd.DataFrame): The Quran dataset
|
59 |
+
|
60 |
+
Returns:
|
61 |
+
gr.Tab: The configured statistics tab
|
62 |
+
"""
|
63 |
+
with gr.Tab("Statistics") as tab:
|
64 |
+
gr.Markdown("# Quran Statistics")
|
65 |
+
gr.Markdown("""
|
66 |
+
<div class='tab-description'>
|
67 |
+
This section provides statistical insights about the Quran:
|
68 |
+
- Visual representation of verses distribution across chapters
|
69 |
+
- Interactive bar chart showing the number of verses in each Surah
|
70 |
+
- Detailed table with verse counts for each chapter
|
71 |
+
- Color-coded visualization for easy comparison
|
72 |
+
|
73 |
+
The statistics help understand the structure and composition of the Quran.
|
74 |
+
</div>
|
75 |
+
""")
|
76 |
+
|
77 |
+
stats_output = gr.HTML(value=generate_plots_and_tables(quran_data))
|
78 |
+
|
79 |
+
return tab
|
src/components/surah_tab.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
def load_surah(surah_name_with_number, quran_data):
|
5 |
+
"""
|
6 |
+
Load verses and word cloud for a specific Surah.
|
7 |
+
|
8 |
+
Args:
|
9 |
+
surah_name_with_number (str): Format: "number. Surah Name"
|
10 |
+
quran_data (pd.DataFrame): The Quran dataset
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
tuple: (list of verses, word cloud image path)
|
14 |
+
"""
|
15 |
+
surah_number = int(surah_name_with_number.split('.')[0])
|
16 |
+
surah_name = surah_name_with_number.split('. ')[1]
|
17 |
+
surah_verses = quran_data[quran_data['Surah'] == surah_number]['Text'].tolist()
|
18 |
+
word_cloud_path = f"word_cloud/surah_{surah_number}_{surah_name}.png"
|
19 |
+
return surah_verses, word_cloud_path
|
20 |
+
|
21 |
+
def display_surah(surah_name_with_number, quran_data):
|
22 |
+
"""
|
23 |
+
Get the verses text and word cloud for display.
|
24 |
+
|
25 |
+
Args:
|
26 |
+
surah_name_with_number (str): Format: "number. Surah Name"
|
27 |
+
quran_data (pd.DataFrame): The Quran dataset
|
28 |
+
|
29 |
+
Returns:
|
30 |
+
tuple: (verses text, word cloud image path)
|
31 |
+
"""
|
32 |
+
verses, word_cloud_path = load_surah(surah_name_with_number, quran_data)
|
33 |
+
verses_text = "\n".join(verses)
|
34 |
+
return verses_text, word_cloud_path
|
35 |
+
|
36 |
+
def create_surah_tab(quran_data, surah_names_list):
|
37 |
+
"""
|
38 |
+
Create the Surah tab interface with description and display components.
|
39 |
+
|
40 |
+
Args:
|
41 |
+
quran_data (pd.DataFrame): The Quran dataset
|
42 |
+
surah_names_list (list): List of formatted Surah names
|
43 |
+
|
44 |
+
Returns:
|
45 |
+
gr.Tab: The configured Surah tab
|
46 |
+
"""
|
47 |
+
with gr.Tab("Surah") as tab:
|
48 |
+
gr.Markdown("# Surah Explorer")
|
49 |
+
gr.Markdown("""
|
50 |
+
<div class='tab-description'>
|
51 |
+
Welcome to the Surah Explorer! This tool allows you to:
|
52 |
+
- Select and read any Surah from the Quran
|
53 |
+
- View the complete English translation
|
54 |
+
- See a visual word cloud representation of the Surah
|
55 |
+
- Understand the most frequently used terms in each chapter
|
56 |
+
|
57 |
+
Select a Surah from the dropdown menu to begin exploring.
|
58 |
+
</div>
|
59 |
+
""")
|
60 |
+
|
61 |
+
surah_name_with_number = gr.Dropdown(
|
62 |
+
label="Select a Surah",
|
63 |
+
choices=surah_names_list,
|
64 |
+
info="Choose a Surah to view its verses and word cloud"
|
65 |
+
)
|
66 |
+
|
67 |
+
with gr.Row():
|
68 |
+
verses_output = gr.Textbox(
|
69 |
+
label="Verses",
|
70 |
+
lines=18,
|
71 |
+
visible=False,
|
72 |
+
elem_classes="verses-output"
|
73 |
+
)
|
74 |
+
word_cloud_output = gr.Image(
|
75 |
+
label="Word Cloud Visualization",
|
76 |
+
visible=False,
|
77 |
+
elem_classes="word-cloud-output"
|
78 |
+
)
|
79 |
+
|
80 |
+
def update_visibility_and_load_surah(surah_name):
|
81 |
+
verses_text, word_cloud_path = display_surah(surah_name, quran_data)
|
82 |
+
return gr.update(visible=True, value=verses_text), gr.update(visible=True, value=word_cloud_path)
|
83 |
+
|
84 |
+
surah_name_with_number.change(
|
85 |
+
update_visibility_and_load_surah,
|
86 |
+
inputs=[surah_name_with_number],
|
87 |
+
outputs=[verses_output, word_cloud_output]
|
88 |
+
)
|
89 |
+
|
90 |
+
return tab
|
src/components/utils.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
from base64 import b64encode
|
4 |
+
import io
|
5 |
+
|
6 |
+
def load_data():
|
7 |
+
"""Load and preprocess Quran dataset with surah names"""
|
8 |
+
quran_english_with_surah = pd.read_csv('datasets/en.yusufali.csv')
|
9 |
+
surah_names = pd.read_csv('datasets/surah_names_english.csv', names=['Surah', 'Surah Name'])
|
10 |
+
surah_names["Surah Name"] = surah_names["Surah Name"].str[1:]
|
11 |
+
quran_english_with_surah = quran_english_with_surah.merge(surah_names, on='Surah')
|
12 |
+
quran_english_with_surah.index = pd.RangeIndex(start=1, stop=len(quran_english_with_surah) + 1)
|
13 |
+
return quran_english_with_surah, surah_names
|
14 |
+
|
15 |
+
def plt_to_html(plt):
|
16 |
+
"""Convert matplotlib plot to HTML img tag"""
|
17 |
+
buf = io.BytesIO()
|
18 |
+
plt.savefig(buf, format='png')
|
19 |
+
buf.seek(0)
|
20 |
+
img_str = b64encode(buf.read()).decode('utf-8')
|
21 |
+
plt.close()
|
22 |
+
return f'<img src="data:image/png;base64,{img_str}"/>'
|
23 |
+
|
24 |
+
def get_surah_names_list(surah_names):
|
25 |
+
"""Create a formatted list of surah names with numbers"""
|
26 |
+
return [f"{row['Surah']}. {row['Surah Name']}" for _, row in surah_names.iterrows()]
|
27 |
+
|
28 |
+
def load_css():
|
29 |
+
"""Load CSS styles from file"""
|
30 |
+
with open('src/styles/styles.css', 'r') as f:
|
31 |
+
return f.read()
|
src/gradio_app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from components.utils import load_data, load_css, get_surah_names_list
|
3 |
+
from components.search_tab import create_search_tab
|
4 |
+
from components.statistics_tab import create_statistics_tab
|
5 |
+
from components.surah_tab import create_surah_tab
|
6 |
+
|
7 |
+
def main():
|
8 |
+
"""
|
9 |
+
Main function to create and launch the Quran Explorer application.
|
10 |
+
The app provides three main features:
|
11 |
+
1. Keyword search across the Quran
|
12 |
+
2. Statistical analysis and visualizations
|
13 |
+
3. Surah-wise exploration with word clouds
|
14 |
+
"""
|
15 |
+
# Load data
|
16 |
+
quran_data, surah_names = load_data()
|
17 |
+
surah_names_list = get_surah_names_list(surah_names)
|
18 |
+
|
19 |
+
# Create the Gradio interface
|
20 |
+
with gr.Blocks(css=load_css()) as iface:
|
21 |
+
gr.Markdown("""
|
22 |
+
# Quran Explorer
|
23 |
+
Welcome to the Quran Explorer application. This tool provides multiple ways to explore
|
24 |
+
and understand the Holy Quran through its English translation. Use the tabs below to:
|
25 |
+
- Search for specific words or phrases
|
26 |
+
- View statistical insights and visualizations
|
27 |
+
- Read complete Surahs with word cloud visualizations
|
28 |
+
""")
|
29 |
+
|
30 |
+
# Create tabs
|
31 |
+
search_tab = create_search_tab(quran_data)
|
32 |
+
statistics_tab = create_statistics_tab(quran_data)
|
33 |
+
surah_tab = create_surah_tab(quran_data, surah_names_list)
|
34 |
+
|
35 |
+
# Launch the interface
|
36 |
+
iface.launch(share=True)
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
main()
|
src/styles/styles.css
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
font-family: 'Arial', sans-serif;
|
3 |
+
background-color: #FFF2F2;
|
4 |
+
color: #2D336B;
|
5 |
+
margin: 0;
|
6 |
+
padding: 0;
|
7 |
+
}
|
8 |
+
|
9 |
+
.gradio-container {
|
10 |
+
max-width: 100%;
|
11 |
+
margin: 0 auto;
|
12 |
+
padding: 20px;
|
13 |
+
}
|
14 |
+
|
15 |
+
.gradio-input, .gradio-output {
|
16 |
+
width: 100%;
|
17 |
+
}
|
18 |
+
|
19 |
+
.gradio-title {
|
20 |
+
font-size: 2em;
|
21 |
+
font-weight: bold;
|
22 |
+
margin-bottom: 20px;
|
23 |
+
color: #2D336B;
|
24 |
+
}
|
25 |
+
|
26 |
+
.gradio-description {
|
27 |
+
font-size: 1.2em;
|
28 |
+
margin-bottom: 20px;
|
29 |
+
color: #2D336B;
|
30 |
+
}
|
31 |
+
|
32 |
+
.table {
|
33 |
+
width: 100%;
|
34 |
+
border-collapse: collapse;
|
35 |
+
background-color: #A9B5DF;
|
36 |
+
}
|
37 |
+
|
38 |
+
.table th, .table td {
|
39 |
+
padding: 8px 12px;
|
40 |
+
border: 1px solid #2D336B;
|
41 |
+
}
|
42 |
+
|
43 |
+
.table th {
|
44 |
+
background-color: #7886C7;
|
45 |
+
font-weight: bold;
|
46 |
+
color: #FFF2F2;
|
47 |
+
}
|
48 |
+
|
49 |
+
.table-striped tbody tr:nth-of-type(odd) {
|
50 |
+
background-color: #A9B5DF;
|
51 |
+
}
|
52 |
+
|
53 |
+
.table-hover tbody tr:hover {
|
54 |
+
background-color: #7886C7;
|
55 |
+
color: #FFF2F2;
|
56 |
+
}
|
57 |
+
|
58 |
+
.verses-output textarea {
|
59 |
+
font-size: 18px !important;
|
60 |
+
line-height: 1.3 !important;
|
61 |
+
height: 600px !important;
|
62 |
+
width: 100% !important;
|
63 |
+
}
|
64 |
+
|
65 |
+
.word-cloud-output {
|
66 |
+
height: 600px !important;
|
67 |
+
width: 100% !important;
|
68 |
+
}
|
69 |
+
|
70 |
+
.word-cloud-output img {
|
71 |
+
height: 100% !important;
|
72 |
+
width: 100% !important;
|
73 |
+
object-fit: contain !important;
|
74 |
+
}
|
75 |
+
|
76 |
+
/* Tab Descriptions */
|
77 |
+
.tab-description {
|
78 |
+
padding: 15px;
|
79 |
+
margin-bottom: 20px;
|
80 |
+
background-color: #A9B5DF;
|
81 |
+
border-radius: 5px;
|
82 |
+
color: #2D336B;
|
83 |
+
}
|
word_cloud/surah_100_Al-/342/200/230Adiyah (the Runners).png
ADDED
![]() |
word_cloud/surah_101_Al-Qari/342/200/231ah (the Striking Hour).png
ADDED
![]() |
word_cloud/surah_102_At-Takathur (the Piling Up).png
ADDED
![]() |
word_cloud/surah_103_Al-/342/200/230Asr (the Time).png
ADDED
![]() |
word_cloud/surah_104_Al-Humazah (the Slanderer).png
ADDED
![]() |
word_cloud/surah_105_Al-Fil (the Elephant).png
ADDED
![]() |
word_cloud/surah_106_Quraish (Quraish).png
ADDED
![]() |
word_cloud/surah_107_Al-Ma/342/200/231un (the Assistance).png
ADDED
![]() |
word_cloud/surah_108_Al-Kauthar (the River of Abundance).png
ADDED
![]() |
word_cloud/surah_109_Al-Kafirun (the Disbelievers).png
ADDED
![]() |
word_cloud/surah_10_Yunus (Yunus).png
ADDED
![]() |
word_cloud/surah_110_An-Nasr (the Help).png
ADDED
![]() |
word_cloud/surah_111_Al-Masad (the Palm Fiber).png
ADDED
![]() |
word_cloud/surah_112_Al-Ikhlas (the Sincerity).png
ADDED
![]() |
word_cloud/surah_113_Al-Falaq (the Daybreak).png
ADDED
![]() |
word_cloud/surah_114_An-Nas (Mankind).png
ADDED
![]() |
word_cloud/surah_11_Hud (Hud).png
ADDED
![]() |
word_cloud/surah_12_Yusuf (Yusuf).png
ADDED
![]() |
word_cloud/surah_13_Ar-Ra/342/200/231d (the Thunder).png
ADDED
![]() |
word_cloud/surah_14_Ibrahim (Ibrahim).png
ADDED
![]() |
word_cloud/surah_15_Al-Hijr (the Rocky Tract).png
ADDED
![]() |
word_cloud/surah_16_An-Nahl (the Bees).png
ADDED
![]() |
word_cloud/surah_17_Al-Isra/342/200/231 (the Night Journey).png
ADDED
![]() |
word_cloud/surah_18_Al-Kahf (the Cave).png
ADDED
![]() |
word_cloud/surah_19_Maryam (Maryam).png
ADDED
![]() |
word_cloud/surah_1_Al-Fatihah (the Opening).png
ADDED
![]() |
word_cloud/surah_20_Ta-Ha (Ta-Ha).png
ADDED
![]() |