-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
159 lines (121 loc) · 5.09 KB
/
app.py
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import streamlit as st
import streamlit.components.v1 as stc
import pandas as pd
import neattext.functions as nfx
import random
import matplotlib
matplotlib.use("Agg")
import altair as alt
@st.cache
def load_bible(data):
df = pd.read_csv(data)
return df
from utils import (
HTML_BANNER,
HTML_RANDOM_TEMPLATE,
render_entities,
get_tags,
mytag_visualizer,
plot_word_freq_with_altair,
get_most_common_tokens,
)
def main():
stc.html(HTML_BANNER)
menu = ["Home", "MultiVerse", "About"]
df = load_bible("data/KJV_Bible.csv")
choice = st.sidebar.selectbox("Menu", menu)
if choice == "Home":
st.subheader("Single Verse Search")
book_list = df["book"].unique().tolist()
book_name = st.sidebar.selectbox("Book", book_list)
chapter = st.sidebar.number_input("Chapter", 1)
verse = st.sidebar.number_input("Verse", 1)
bible_df = df[df["book"] == book_name]
# Layout
c1, c2 = st.beta_columns([2, 1])
# Single Verse Layout
with c1:
try:
selected_passage = bible_df[
(bible_df["chapter"] == chapter) & (bible_df["verse"] == verse)
]
passage_details = "{} Chapter::{} Verse::{}".format(
book_name, chapter, verse
)
st.info(passage_details)
passage = "{}".format(selected_passage["text"].values[0])
st.write(passage)
except:
st.warning("Book out of Range")
with c2:
chapter_list = range(10)
verse_list = range(20)
ch_choice = random.choice(chapter_list)
vs_choice = random.choice(verse_list)
random_book_name = random.choice(book_list)
rand_bible_df = df[df["book"] == random_book_name]
try:
randomly_selected_passage = rand_bible_df[
(rand_bible_df["chapter"] == ch_choice)
& (rand_bible_df["verse"] == vs_choice)
]
mytext = randomly_selected_passage["text"].values[0]
except:
mytext = rand_bible_df[
(rand_bible_df["chapter"] == 1) & (rand_bible_df["verse"] == 1)
]["text"].values[0]
stc.html(HTML_RANDOM_TEMPLATE.format(mytext), height=300)
# Search Topic/Term
search_term = st.text_input("Term/Topic")
with st.beta_expander("View Results"):
retrieved_df = df[df["text"].str.contains(search_term)]
st.dataframe(retrieved_df[["book", "chapter", "verse", "text"]])
elif choice == "MultiVerse":
st.subheader("MultiVerse Retrieval")
book_list = df["book"].unique().tolist()
book_name = st.sidebar.selectbox("Book", book_list)
chapter = st.sidebar.number_input("Chapter", 1)
bible_df = df[df["book"] == book_name]
all_verse = bible_df["verse"].unique().tolist()
verse = st.sidebar.multiselect("Verse", all_verse, default=1)
selected_passage = bible_df.iloc[verse]
st.dataframe(selected_passage)
passage_details = "{} Chapter::{} Verse::{}".format(book_name, chapter, verse)
st.info(passage_details)
# Layout
col1, col2 = st.beta_columns(2)
# Join all text as a sentence
docx = " ".join(selected_passage["text"].tolist())
with col1:
st.info("Details")
for i, row in selected_passage.iterrows():
st.write(row["text"])
with col2:
st.success("Bible Text analysis")
with st.beta_expander("Visualize Pos Tags"):
tagged_docx = get_tags(docx)
processed_tags = mytag_visualizer(tagged_docx)
# st.write(processed_tags)# Raw
stc.html(processed_tags, height=1000, scrolling=True)
with st.beta_expander("Keywords"):
processed_docx = nfx.remove_stopwords(docx)
keywords_tokens = get_most_common_tokens(processed_docx, 5)
st.write(keywords_tokens)
with st.beta_expander("Pos Tags Plot"):
tagged_docx = get_tags(docx)
tagged_df = pd.DataFrame(tagged_docx, columns=["Tokens", "Tags"])
# st.dataframe(tagged_df)
df_tag_count = tagged_df["Tags"].value_counts().to_frame("counts")
df_tag_count["tag_type"] = df_tag_count.index
# st.dataframe(df_tag_count)
c = alt.Chart(df_tag_count).mark_bar().encode(x="tag_type", y="counts")
st.altair_chart(c, use_container_width=True)
with st.beta_expander("Word Freq Plot"):
plot_word_freq_with_altair(docx)
else:
st.subheader("About")
st.text("Build with Streamlit")
st.text("By Gift Ojeabulu")
st.success("Be strong and courageous. Do not be afraid or terrified because of them, or the LORD your God goes with you; he will never leave you nor forsake you.")
if __name__ == "__main__":
main()