LucidMinds3ye commited on
Commit
cf14daf
·
verified ·
1 Parent(s): e41d86c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +295 -0
app.py ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sqlite3
3
+ from datetime import datetime
4
+
5
+ # Set up the page
6
+ st.set_page_config(
7
+ page_title="Scripture Decipher",
8
+ page_icon="📖",
9
+ layout="wide"
10
+ )
11
+
12
+ # Initialize database
13
+ def init_db():
14
+ conn = sqlite3.connect('scripture_decipher.db')
15
+ c = conn.cursor()
16
+ c.execute('''CREATE TABLE IF NOT EXISTS simplified_verses
17
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
18
+ book TEXT NOT NULL,
19
+ chapter INTEGER NOT NULL,
20
+ verse INTEGER NOT NULL,
21
+ original_text TEXT NOT NULL,
22
+ simplified_text TEXT NOT NULL,
23
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')
24
+ conn.commit()
25
+ conn.close()
26
+
27
+ # Add a new simplified verse to the database
28
+ def add_simplified_verse(book, chapter, verse, original_text, simplified_text):
29
+ conn = sqlite3.connect('scripture_decipher.db')
30
+ c = conn.cursor()
31
+ c.execute("INSERT INTO simplified_verses (book, chapter, verse, original_text, simplified_text) VALUES (?, ?, ?, ?, ?)",
32
+ (book, chapter, verse, original_text, simplified_text))
33
+ conn.commit()
34
+ conn.close()
35
+
36
+ # Get all simplified verses from the database
37
+ def get_all_simplified_verses():
38
+ conn = sqlite3.connect('scripture_decipher.db')
39
+ c = conn.cursor()
40
+ c.execute("SELECT * FROM simplified_verses ORDER BY created_at DESC")
41
+ verses = c.fetchall()
42
+ conn.close()
43
+ return verses
44
+
45
+ # Sample Bible verses data
46
+ SAMPLE_VERSES = {
47
+ "John": {
48
+ 3: {
49
+ 16: "For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life."
50
+ }
51
+ },
52
+ "Matthew": {
53
+ 5: {
54
+ 3: "Blessed are the poor in spirit, for theirs is the kingdom of heaven.",
55
+ 4: "Blessed are those who mourn, for they shall be comforted.",
56
+ 5: "Blessed are the meek, for they shall inherit the earth."
57
+ }
58
+ },
59
+ "Psalm": {
60
+ 23: {
61
+ 1: "The Lord is my shepherd; I shall not want.",
62
+ 4: "Even though I walk through the valley of the shadow of death, I will fear no evil, for you are with me; your rod and your staff, they comfort me."
63
+ }
64
+ }
65
+ }
66
+
67
+ # Initialize database
68
+ init_db()
69
+
70
+ # Custom CSS for styling
71
+ st.markdown("""
72
+ <style>
73
+ .main-header {
74
+ font-size: 3.5rem;
75
+ color: #4a7c59;
76
+ text-align: center;
77
+ margin-bottom: 1rem;
78
+ }
79
+ .sub-header {
80
+ font-size: 1.5rem;
81
+ color: #8d5b4c;
82
+ border-bottom: 2px solid #4a7c59;
83
+ padding-bottom: 0.5rem;
84
+ }
85
+ .scripture-box {
86
+ background-color: #f8f9fa;
87
+ border-radius: 10px;
88
+ padding: 20px;
89
+ margin: 15px 0;
90
+ border-left: 5px solid #4a7c59;
91
+ }
92
+ .stButton>button {
93
+ background-color: #4a7c59;
94
+ color: white;
95
+ border: none;
96
+ padding: 10px 20px;
97
+ border-radius: 5px;
98
+ font-weight: bold;
99
+ }
100
+ .stButton>button:hover {
101
+ background-color: #3a6349;
102
+ color: white;
103
+ }
104
+ .success-box {
105
+ background-color: #d4edda;
106
+ color: #155724;
107
+ padding: 15px;
108
+ border-radius: 5px;
109
+ margin: 15px 0;
110
+ }
111
+ </style>
112
+ """, unsafe_allow_html=True)
113
+
114
+ # App title and description
115
+ st.markdown('<h1 class="main-header">📖 Scripture Decipher</h1>', unsafe_allow_html=True)
116
+ st.markdown("""
117
+ <div style="text-align: center; margin-bottom: 2rem;">
118
+ <p style="font-size: 1.2rem;">Making Bible scriptures easier to understand for everyone</p>
119
+ </div>
120
+ """, unsafe_allow_html=True)
121
+
122
+ # Create tabs for different functionalities
123
+ tab1, tab2, tab3 = st.tabs(["Simplify Scripture", "View Saved Verses", "About"])
124
+
125
+ with tab1:
126
+ st.markdown('<h2 class="sub-header">Simplify a Bible Verse</h2>', unsafe_allow_html=True)
127
+
128
+ col1, col2 = st.columns([1, 2])
129
+
130
+ with col1:
131
+ # Book selection
132
+ books = list(SAMPLE_VERSES.keys())
133
+ selected_book = st.selectbox("Select Book", books)
134
+
135
+ # Chapter selection based on book
136
+ if selected_book:
137
+ chapters = list(SAMPLE_VERSES[selected_book].keys())
138
+ selected_chapter = st.selectbox("Select Chapter", chapters)
139
+
140
+ # Verse selection based on chapter
141
+ if selected_chapter:
142
+ verses = list(SAMPLE_VERSES[selected_book][selected_chapter].keys())
143
+ selected_verse = st.selectbox("Select Verse", verses)
144
+
145
+ with col2:
146
+ # Display original verse
147
+ if selected_book and selected_chapter and selected_verse:
148
+ original_text = SAMPLE_VERSES[selected_book][selected_chapter][selected_verse]
149
+ st.markdown("### Original Scripture")
150
+ st.markdown(f'<div class="scripture-box">{selected_book} {selected_chapter}:{selected_verse} - "{original_text}"</div>', unsafe_allow_html=True)
151
+
152
+ # Input for simplified version
153
+ simplified_text = st.text_area(
154
+ "Simplified Version",
155
+ placeholder="Enter your simplified version of this verse here...",
156
+ height=150
157
+ )
158
+
159
+ # Sample simplified versions for demonstration
160
+ sample_simplifications = {
161
+ "John 3:16": "God loved people so much that He sent His only Son Jesus. Anyone who believes in Him will live forever with God instead of dying separated from Him.",
162
+ "Matthew 5:3": "Happy are those who realize they need God's help, because Heaven belongs to them.",
163
+ "Psalm 23:1": "The Lord takes care of all my needs, just like a shepherd cares for his sheep."
164
+ }
165
+
166
+ current_ref = f"{selected_book} {selected_chapter}:{selected_verse}"
167
+ if current_ref in sample_simplifications:
168
+ with st.expander("See example simplification"):
169
+ st.info(sample_simplifications[current_ref])
170
+
171
+ # Save button
172
+ if st.button("Save Simplified Verse") and simplified_text:
173
+ add_simplified_verse(
174
+ selected_book, selected_chapter, selected_verse,
175
+ original_text, simplified_text
176
+ )
177
+ st.markdown('<div class="success-box">Simplified verse saved successfully!</div>', unsafe_allow_html=True)
178
+
179
+ with tab2:
180
+ st.markdown('<h2 class="sub-header">Saved Simplified Verses</h2>', unsafe_allow_html=True)
181
+
182
+ # Get all saved verses from database
183
+ saved_verses = get_all_simplified_verses()
184
+
185
+ if not saved_verses:
186
+ st.info("No simplified verses saved yet. Use the 'Simplify Scripture' tab to get started.")
187
+ else:
188
+ # Filter options
189
+ col1, col2, col3 = st.columns(3)
190
+ with col1:
191
+ filter_book = st.selectbox("Filter by Book", ["All"] + books, key="filter_book")
192
+ with col2:
193
+ sort_order = st.selectbox("Sort Order", ["Newest First", "Oldest First"])
194
+ with col3:
195
+ items_per_page = st.selectbox("Items per page", [5, 10, 20], index=0)
196
+
197
+ # Filter and sort verses
198
+ filtered_verses = saved_verses
199
+ if filter_book != "All":
200
+ filtered_verses = [v for v in saved_verses if v[1] == filter_book]
201
+
202
+ if sort_order == "Oldest First":
203
+ filtered_verses = sorted(filtered_verses, key=lambda x: x[6])
204
+ else:
205
+ filtered_verses = sorted(filtered_verses, key=lambda x: x[6], reverse=True)
206
+
207
+ # Pagination
208
+ total_verses = len(filtered_verses)
209
+ if total_verses > 0:
210
+ total_pages = (total_verses - 1) // items_per_page + 1
211
+ page = st.number_input("Page", min_value=1, max_value=total_pages, value=1)
212
+ start_idx = (page - 1) * items_per_page
213
+ end_idx = min(start_idx + items_per_page, total_verses)
214
+
215
+ st.write(f"Showing {start_idx + 1}-{end_idx} of {total_verses} verses")
216
+
217
+ # Display verses for current page
218
+ for verse in filtered_verses[start_idx:end_idx]:
219
+ with st.expander(f"{verse[1]} {verse[2]}:{verse[3]} - {verse[6].split()[0]}"):
220
+ col1, col2 = st.columns(2)
221
+ with col1:
222
+ st.write("**Original:**")
223
+ st.markdown(f'<div class="scripture-box">{verse[4]}</div>', unsafe_allow_html=True)
224
+ with col2:
225
+ st.write("**Simplified:**")
226
+ st.markdown(f'<div style="background-color: #e8f4f8; border-radius: 10px; padding: 20px; margin: 15px 0; border-left: 5px solid #5c8da5;">{verse[5]}</div>', unsafe_allow_html=True)
227
+
228
+ # Statistics
229
+ st.markdown("---")
230
+ st.subheader("Statistics")
231
+ col1, col2, col3 = st.columns(3)
232
+
233
+ with col1:
234
+ st.metric("Total Verses Simplified", total_verses)
235
+
236
+ with col2:
237
+ if total_verses > 0:
238
+ books_count = {}
239
+ for verse in saved_verses:
240
+ book = verse[1]
241
+ books_count[book] = books_count.get(book, 0) + 1
242
+ most_common_book = max(books_count, key=books_count.get)
243
+ st.metric("Most Common Book", most_common_book)
244
+
245
+ with col3:
246
+ if total_verses > 0:
247
+ earliest = min([verse[6] for verse in saved_verses])
248
+ st.metric("First Simplification", earliest.split()[0])
249
+
250
+ with tab3:
251
+ st.markdown('<h2 class="sub-header">About Scripture Decipher</h2>', unsafe_allow_html=True)
252
+
253
+ st.markdown("""
254
+ <div class="scripture-box">
255
+ <h3>Our Mission</h3>
256
+ <p>Scripture Decipher is designed to make the Bible more accessible and understandable to people of all backgrounds.
257
+ We believe that everyone should be able to engage with scripture in a way that resonates with them.</p>
258
+ </div>
259
+ """, unsafe_allow_html=True)
260
+
261
+ col1, col2 = st.columns(2)
262
+
263
+ with col1:
264
+ st.markdown("""
265
+ ### How It Works
266
+ 1. Select a book, chapter, and verse from the Bible
267
+ 2. Read the original text
268
+ 3. Create your simplified version that's easier to understand
269
+ 4. Save it to your personal database
270
+ 5. Review all your simplified verses anytime
271
+ """)
272
+
273
+ with col2:
274
+ st.markdown("""
275
+ ### Benefits
276
+ - Helps with personal Bible study
277
+ - Useful for teaching and sermons
278
+ - Creates a personal repository of understood scriptures
279
+ - Great for new believers or those new to the Bible
280
+ """)
281
+
282
+ st.markdown("---")
283
+ st.markdown("""
284
+ <div style="text-align: center;">
285
+ <p>Created with ❤️ for the Hugging Face community</p>
286
+ </div>
287
+ """, unsafe_allow_html=True)
288
+
289
+ # Add footer
290
+ st.markdown("---")
291
+ st.markdown("""
292
+ <div style="text-align: center; color: #6c757d; padding: 20px;">
293
+ <p>Scripture Decipher • Making the Bible accessible to all</p>
294
+ </div>
295
+ """, unsafe_allow_html=True)