LucidMinds3ye commited on
Commit
b911810
·
verified ·
1 Parent(s): 4e06840

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -272
app.py CHANGED
@@ -1,72 +1,3 @@
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>
@@ -145,39 +76,40 @@ st.markdown("""
145
  border-radius: 8px;
146
  padding: 12px;
147
  }
148
- /* Select box label styling */
 
 
 
149
  .stSelectbox label {
150
  color: #2c3e50 !important;
151
  font-size: 1.1rem;
152
  font-weight: 500;
153
  }
154
- /* DROPDOWN INPUT BOX - FIXED */
155
- div[data-baseweb="select"] > div {
156
- background-color: #f8f9fa !important;
157
  color: #000000 !important;
158
- border: 2px solid #4a7c59 !important;
159
- border-radius: 8px !important;
160
- padding: 8px 12px !important;
161
- font-size: 1.1rem !important;
162
  }
163
- /* DROPDOWN OPTIONS PANEL - FIXED */
164
- div[data-baseweb="popover"] {
165
- background-color: #ffffff !important;
166
- border: 2px solid #4a7c59 !important;
167
- border-radius: 8px !important;
168
  }
169
- /* DROPDOWN OPTIONS - FIXED */
170
- div[data-baseweb="popover"] li {
171
- background-color: #ffffff !important;
 
172
  color: #000000 !important;
173
  padding: 10px 15px !important;
174
- font-size: 1.1rem !important;
175
  }
176
- /* DROPDOWN OPTIONS HOVER - FIXED */
177
- div[data-baseweb="popover"] li:hover {
 
178
  background-color: #f0f7f0 !important;
179
  color: #000000 !important;
180
  }
 
181
  /* Number input styling */
182
  .stNumberInput input {
183
  color: #000000 !important;
@@ -187,20 +119,24 @@ st.markdown("""
187
  border-radius: 8px !important;
188
  padding: 8px 12px !important;
189
  }
190
- /* Number input label */
 
191
  .stNumberInput label {
192
  color: #2c3e50 !important;
193
  font-size: 1.1rem !important;
194
  font-weight: 500 !important;
195
  }
196
- /* Make all text consistent */
 
197
  body, p, div, span, h1, h2, h3, h4, h5, h6 {
198
  color: #2c3e50 !important;
199
  }
 
200
  /* Tab styling */
201
  .stTabs [data-baseweb="tab-list"] {
202
  gap: 8px;
203
  }
 
204
  .stTabs [data-baseweb="tab"] {
205
  height: 50px;
206
  white-space: pre-wrap;
@@ -210,10 +146,12 @@ st.markdown("""
210
  padding: 12px 24px;
211
  font-weight: bold;
212
  }
 
213
  .stTabs [aria-selected="true"] {
214
  background-color: #4a7c59;
215
  color: white !important;
216
  }
 
217
  /* Expander styling */
218
  .streamlit-expanderHeader {
219
  font-size: 1.2rem;
@@ -224,6 +162,7 @@ st.markdown("""
224
  border-radius: 8px;
225
  margin: 8px 0;
226
  }
 
227
  /* Metric cards styling */
228
  [data-testid="metric-container"] {
229
  background-color: #f0f7f0;
@@ -232,6 +171,7 @@ st.markdown("""
232
  padding: 15px;
233
  text-align: center;
234
  }
 
235
  /* Footer styling */
236
  .footer {
237
  text-align: center;
@@ -241,186 +181,4 @@ st.markdown("""
241
  font-style: italic;
242
  }
243
  </style>
244
- """, unsafe_allow_html=True)
245
-
246
- # App title and description
247
- st.markdown('<h1 class="main-header">📖 Scripture Decipher</h1>', unsafe_allow_html=True)
248
- st.markdown("""
249
- <div style="text-align: center; margin-bottom: 2rem;">
250
- <p style="font-size: 1.2rem;">Making Bible scriptures easier to understand for everyone</p>
251
- </div>
252
- """, unsafe_allow_html=True)
253
-
254
- # Create tabs for different functionalities
255
- tab1, tab2, tab3 = st.tabs(["Simplify Scripture", "View Saved Verses", "About"])
256
-
257
- with tab1:
258
- st.markdown('<h2 class="sub-header">Simplify a Bible Verse</h2>', unsafe_allow_html=True)
259
-
260
- col1, col2 = st.columns([1, 2])
261
-
262
- with col1:
263
- # Book selection
264
- books = list(SAMPLE_VERSES.keys())
265
- selected_book = st.selectbox("Select Book", books)
266
-
267
- # Chapter selection based on book
268
- if selected_book:
269
- chapters = list(SAMPLE_VERSES[selected_book].keys())
270
- selected_chapter = st.selectbox("Select Chapter", chapters)
271
-
272
- # Verse selection based on chapter
273
- if selected_chapter:
274
- verses = list(SAMPLE_VERSES[selected_book][selected_chapter].keys())
275
- selected_verse = st.selectbox("Select Verse", verses)
276
-
277
- with col2:
278
- # Display original verse
279
- if selected_book and selected_chapter and selected_verse:
280
- original_text = SAMPLE_VERSES[selected_book][selected_chapter][selected_verse]
281
- st.markdown("### Original Scripture")
282
- st.markdown(f'<div class="scripture-box">{selected_book} {selected_chapter}:{selected_verse} - "{original_text}"</div>', unsafe_allow_html=True)
283
-
284
- # Input for simplified version
285
- simplified_text = st.text_area(
286
- "Simplified Version",
287
- placeholder="Enter your simplified version of this verse here...",
288
- height=150
289
- )
290
-
291
- # Sample simplified versions for demonstration
292
- sample_simplifications = {
293
- "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.",
294
- "Matthew 5:3": "Happy are those who realize they need God's help, because Heaven belongs to them.",
295
- "Psalm 23:1": "The Lord takes care of all my needs, just like a shepherd cares for his sheep."
296
- }
297
-
298
- current_ref = f"{selected_book} {selected_chapter}:{selected_verse}"
299
- if current_ref in sample_simplifications:
300
- with st.expander("See example simplification"):
301
- st.info(sample_simplifications[current_ref])
302
-
303
- # Save button
304
- if st.button("Save Simplified Verse") and simplified_text:
305
- add_simplified_verse(
306
- selected_book, selected_chapter, selected_verse,
307
- original_text, simplified_text
308
- )
309
- st.markdown('<div class="success-box">Simplified verse saved successfully!</div>', unsafe_allow_html=True)
310
-
311
- with tab2:
312
- st.markdown('<h2 class="sub-header">Saved Simplified Verses</h2>', unsafe_allow_html=True)
313
-
314
- # Get all saved verses from database
315
- saved_verses = get_all_simplified_verses()
316
-
317
- if not saved_verses:
318
- st.info("No simplified verses saved yet. Use the 'Simplify Scripture' tab to get started.")
319
- else:
320
- # Filter options
321
- col1, col2, col3 = st.columns(3)
322
- with col1:
323
- filter_book = st.selectbox("Filter by Book", ["All"] + books, key="filter_book")
324
- with col2:
325
- sort_order = st.selectbox("Sort Order", ["Newest First", "Oldest First"])
326
- with col3:
327
- items_per_page = st.selectbox("Items per page", [5, 10, 20], index=0)
328
-
329
- # Filter and sort verses
330
- filtered_verses = saved_verses
331
- if filter_book != "All":
332
- filtered_verses = [v for v in saved_verses if v[1] == filter_book]
333
-
334
- if sort_order == "Oldest First":
335
- filtered_verses = sorted(filtered_verses, key=lambda x: x[6])
336
- else:
337
- filtered_verses = sorted(filtered_verses, key=lambda x: x[6], reverse=True)
338
-
339
- # Pagination
340
- total_verses = len(filtered_verses)
341
- if total_verses > 0:
342
- total_pages = (total_verses - 1) // items_per_page + 1
343
- page = st.number_input("Page", min_value=1, max_value=total_pages, value=1)
344
- start_idx = (page - 1) * items_per_page
345
- end_idx = min(start_idx + items_per_page, total_verses)
346
-
347
- st.write(f"Showing {start_idx + 1}-{end_idx} of {total_verses} verses")
348
-
349
- # Display verses for current page
350
- for verse in filtered_verses[start_idx:end_idx]:
351
- with st.expander(f"{verse[1]} {verse[2]}:{verse[3]} - {verse[6].split()[0]}"):
352
- col1, col2 = st.columns(2)
353
- with col1:
354
- st.write("**Original:**")
355
- st.markdown(f'<div class="scripture-box">{verse[4]}</div>', unsafe_allow_html=True)
356
- with col2:
357
- st.write("**Simplified:**")
358
- 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)
359
-
360
- # Statistics
361
- st.markdown("---")
362
- st.subheader("Statistics")
363
- col1, col2, col3 = st.columns(3)
364
-
365
- with col1:
366
- st.metric("Total Verses Simplified", total_verses)
367
-
368
- with col2:
369
- if total_verses > 0:
370
- books_count = {}
371
- for verse in saved_verses:
372
- book = verse[1]
373
- books_count[book] = books_count.get(book, 0) + 1
374
- most_common_book = max(books_count, key=books_count.get)
375
- st.metric("Most Common Book", most_common_book)
376
-
377
- with col3:
378
- if total_verses > 0:
379
- earliest = min([verse[6] for verse in saved_verses])
380
- st.metric("First Simplification", earliest.split()[0])
381
-
382
- with tab3:
383
- st.markdown('<h2 class="sub-header">About Scripture Decipher</h2>', unsafe_allow_html=True)
384
-
385
- st.markdown("""
386
- <div class="scripture-box">
387
- <h3>Our Mission</h3>
388
- <p>Scripture Decipher is designed to make the Bible more accessible and understandable to people of all backgrounds.
389
- We believe that everyone should be able to engage with scripture in a way that resonates with them.</p>
390
- </div>
391
- """, unsafe_allow_html=True)
392
-
393
- col1, col2 = st.columns(2)
394
-
395
- with col1:
396
- st.markdown("""
397
- ### How It Works
398
- 1. Select a book, chapter, and verse from the Bible
399
- 2. Read the original text
400
- 3. Create your simplified version that's easier to understand
401
- 4. Save it to your personal database
402
- 5. Review all your simplified verses anytime
403
- """)
404
-
405
- with col2:
406
- st.markdown("""
407
- ### Benefits
408
- - Helps with personal Bible study
409
- - Useful for teaching and sermons
410
- - Creates a personal repository of understood scriptures
411
- - Great for new believers or those new to the Bible
412
- """)
413
-
414
- st.markdown("---")
415
- st.markdown("""
416
- <div style="text-align: center;">
417
- <p>Created with ❤️ for the Hugging Face community</p>
418
- </div>
419
- """, unsafe_allow_html=True)
420
- # Add footer
421
- st.markdown("---")
422
- st.markdown("""
423
- <div style="text-align: center; color: #6c757d; padding: 20px;">
424
- <p>Scripture Decipher • Making the Bible accessible to all</p>
425
- </div>
426
  """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Custom CSS for styling
2
  st.markdown("""
3
  <style>
 
76
  border-radius: 8px;
77
  padding: 12px;
78
  }
79
+
80
+ /* DROPDOWN FIXES - SIMPLIFIED APPROACH */
81
+
82
+ /* Select box labels */
83
  .stSelectbox label {
84
  color: #2c3e50 !important;
85
  font-size: 1.1rem;
86
  font-weight: 500;
87
  }
88
+
89
+ /* Dropdown input text - make it black */
90
+ .stSelectbox div[data-baseweb="select"] div {
91
  color: #000000 !important;
 
 
 
 
92
  }
93
+
94
+ /* Dropdown options panel */
95
+ section[data-baseweb="popover"] div {
96
+ background-color: white !important;
97
+ color: #000000 !important;
98
  }
99
+
100
+ /* Individual dropdown options */
101
+ section[data-baseweb="popover"] li {
102
+ background-color: white !important;
103
  color: #000000 !important;
104
  padding: 10px 15px !important;
 
105
  }
106
+
107
+ /* Dropdown options on hover */
108
+ section[data-baseweb="popover"] li:hover {
109
  background-color: #f0f7f0 !important;
110
  color: #000000 !important;
111
  }
112
+
113
  /* Number input styling */
114
  .stNumberInput input {
115
  color: #000000 !important;
 
119
  border-radius: 8px !important;
120
  padding: 8px 12px !important;
121
  }
122
+
123
+ /* Number input labels */
124
  .stNumberInput label {
125
  color: #2c3e50 !important;
126
  font-size: 1.1rem !important;
127
  font-weight: 500 !important;
128
  }
129
+
130
+ /* Make all regular text consistent */
131
  body, p, div, span, h1, h2, h3, h4, h5, h6 {
132
  color: #2c3e50 !important;
133
  }
134
+
135
  /* Tab styling */
136
  .stTabs [data-baseweb="tab-list"] {
137
  gap: 8px;
138
  }
139
+
140
  .stTabs [data-baseweb="tab"] {
141
  height: 50px;
142
  white-space: pre-wrap;
 
146
  padding: 12px 24px;
147
  font-weight: bold;
148
  }
149
+
150
  .stTabs [aria-selected="true"] {
151
  background-color: #4a7c59;
152
  color: white !important;
153
  }
154
+
155
  /* Expander styling */
156
  .streamlit-expanderHeader {
157
  font-size: 1.2rem;
 
162
  border-radius: 8px;
163
  margin: 8px 0;
164
  }
165
+
166
  /* Metric cards styling */
167
  [data-testid="metric-container"] {
168
  background-color: #f0f7f0;
 
171
  padding: 15px;
172
  text-align: center;
173
  }
174
+
175
  /* Footer styling */
176
  .footer {
177
  text-align: center;
 
181
  font-style: italic;
182
  }
183
  </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  """, unsafe_allow_html=True)