awacke1 commited on
Commit
827d4bc
ยท
verified ยท
1 Parent(s): cf61a61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +188 -80
app.py CHANGED
@@ -4,7 +4,6 @@ import os
4
  import glob
5
  import asyncio
6
  import hashlib
7
- import base64
8
  import unicodedata
9
  import streamlit as st
10
  from PIL import Image
@@ -19,51 +18,13 @@ from reportlab.pdfbase.ttfonts import TTFont
19
 
20
  st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
21
 
22
- def clean_text_for_tts(text):
23
- # Remove asterisks, pound signs, and emojis from text for audio generation.
24
- text = re.sub(r'[#*]', '', text)
25
- emoji_pattern = re.compile("["
26
- u"\U0001F600-\U0001F64F" # emoticons
27
- u"\U0001F300-\U0001F5FF" # symbols & pictographs
28
- u"\U0001F680-\U0001F6FF" # transport & map symbols
29
- u"\U0001F1E0-\U0001F1FF" # flags
30
- "]+", flags=re.UNICODE)
31
- text = emoji_pattern.sub(r'', text)
32
- return text.strip()
33
-
34
- def get_file_title_from_markdown(markdown_text):
35
- # Extract first sizable line (starting with '#' and non-empty) and clean it for use as a file name.
36
- for line in markdown_text.splitlines():
37
- if line.strip() and line.lstrip().startswith("#"):
38
- title = line.lstrip("#").strip()
39
- title = re.sub(r'[^A-Za-z0-9 ]+', '', title).strip()
40
- if title:
41
- return title.replace(" ", "_")
42
- return "output"
43
-
44
- async def generate_audio(text, voice, markdown_text):
45
- # Clean the text and generate a file name based on the markdown title.
46
- cleaned_text = clean_text_for_tts(text)
47
- title = get_file_title_from_markdown(markdown_text)
48
- filename = f"{title}.mp3"
49
- communicate = edge_tts.Communicate(cleaned_text, voice)
50
  await communicate.save(filename)
51
  return filename
52
 
53
- def get_download_link(file, file_type="mp3"):
54
- # Generate a base64 download link for a file.
55
- with open(file, "rb") as f:
56
- b64 = base64.b64encode(f.read()).decode()
57
- if file_type == "mp3":
58
- mime = "audio/mpeg"
59
- elif file_type == "pdf":
60
- mime = "application/pdf"
61
- else:
62
- mime = "application/octet-stream"
63
- return f'<a href="data:{mime};base64,{b64}" download="{os.path.basename(file)}">Download {os.path.basename(file)}</a>'
64
-
65
  def apply_emoji_font(text, emoji_font):
66
- # Replace emoji characters with HTML font tags using the specified emoji font.
67
  emoji_pattern = re.compile(
68
  r"([\U0001F300-\U0001F5FF"
69
  r"\U0001F600-\U0001F64F"
@@ -86,15 +47,14 @@ def apply_emoji_font(text, emoji_font):
86
  for match in emoji_pattern.finditer(text):
87
  start, end = match.span()
88
  if last_pos < start:
89
- segments.append(f'<font face="{emoji_font}">{text[last_pos:start]}</font>')
90
  segments.append(replace_emoji(match))
91
  last_pos = end
92
  if last_pos < len(text):
93
- segments.append(f'<font face="{emoji_font}">{text[last_pos:]}</font>')
94
  return ''.join(segments)
95
 
96
  def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers):
97
- # Convert markdown text into a list of lines with optional bold formatting.
98
  lines = markdown_text.strip().split('\n')
99
  pdf_content = []
100
  number_pattern = re.compile(r'^\d+\.\s')
@@ -111,7 +71,7 @@ def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers):
111
  total_lines = len(pdf_content)
112
  return pdf_content, total_lines
113
 
114
- def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns, emoji_font):
115
  buffer = io.BytesIO()
116
  page_width = A4[0] * 2
117
  page_height = A4[1]
@@ -174,7 +134,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
174
  else:
175
  column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), section_style))
176
  else:
177
- column_cells[col_idx].append(Paragraph(apply_emoji_font(item, emoji_font), item_style))
178
  max_cells = max(len(cells) for cells in column_cells) if column_cells else 0
179
  for cells in column_cells:
180
  cells.extend([Paragraph("", item_style)] * (max_cells - len(cells)))
@@ -211,15 +171,185 @@ def pdf_to_image(pdf_bytes):
211
  st.error(f"Failed to render PDF preview: {e}")
212
  return None
213
 
214
- # Auto-detect default markdown file from available .md files.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  md_files = [f for f in glob.glob("*.md") if os.path.basename(f) != "README.md"]
216
  md_options = [os.path.splitext(os.path.basename(f))[0] for f in md_files]
217
- if md_options:
218
- if 'markdown_content' not in st.session_state or not st.session_state.markdown_content:
219
- with open(f"{md_options[0]}.md", "r", encoding="utf-8") as f:
220
- st.session_state.markdown_content = f.read()
221
- else:
222
- st.session_state.markdown_content = ""
223
 
224
  with st.sidebar:
225
  st.markdown("### PDF Options")
@@ -231,6 +361,8 @@ with st.sidebar:
231
  auto_bold_numbers = st.checkbox("Auto Bold Numbered Lines", value=True, key="auto_bold_numbers")
232
  enlarge_numbered = st.checkbox("Enlarge Font Size for Numbered Lines", value=True, key="enlarge_numbered")
233
  num_columns = st.selectbox("Number of Columns", options=[1, 2, 3, 4, 5, 6], index=3)
 
 
234
  if md_options and selected_md:
235
  with open(f"{selected_md}.md", "r", encoding="utf-8") as f:
236
  st.session_state.markdown_content = f.read()
@@ -246,37 +378,14 @@ with st.sidebar:
246
  VOICES = ["en-US-AriaNeural", "en-US-JennyNeural", "en-GB-SoniaNeural", "en-US-GuyNeural", "en-US-AnaNeural"]
247
  selected_voice = st.selectbox("Select Voice for TTS", options=VOICES, index=0)
248
  if st.button("Generate Audio"):
249
- audio_file = asyncio.run(generate_audio(st.session_state.markdown_content, selected_voice, st.session_state.markdown_content))
250
  st.audio(audio_file)
251
  with open(audio_file, "rb") as f:
252
  audio_bytes = f.read()
253
  st.download_button("Download Audio", data=audio_bytes, file_name=os.path.basename(audio_file), mime="audio/mpeg")
254
- if st.button("Save PDF"):
255
- title = get_file_title_from_markdown(st.session_state.markdown_content)
256
- pdf_filename = f"{title}.pdf"
257
- with open(pdf_filename, "wb") as f:
258
- f.write(pdf_bytes)
259
- st.success(f"Saved PDF as {pdf_filename}")
260
- st.experimental_rerun()
261
- st.markdown("### Saved Audio Files")
262
- mp3_files = glob.glob("*.mp3")
263
- for mp3 in mp3_files:
264
- st.audio(mp3)
265
- st.markdown(get_download_link(mp3, "mp3"), unsafe_allow_html=True)
266
- if st.button("Delete All MP3"):
267
- for mp3 in mp3_files:
268
- try:
269
- os.remove(mp3)
270
- except Exception as e:
271
- st.error(f"Error deleting {mp3}: {e}")
272
- st.experimental_rerun()
273
- st.markdown("### Saved PDF Files")
274
- pdf_files = glob.glob("*.pdf")
275
- for pdf in pdf_files:
276
- st.markdown(get_download_link(pdf, "pdf"), unsafe_allow_html=True)
277
 
278
  with st.spinner("Generating PDF..."):
279
- pdf_bytes = create_pdf(st.session_state.markdown_content, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns, selected_font_name)
280
 
281
  with st.container():
282
  pdf_images = pdf_to_image(pdf_bytes)
@@ -288,4 +397,3 @@ with st.container():
288
 
289
  with st.sidebar:
290
  st.download_button(label="Download PDF", data=pdf_bytes, file_name="output.pdf", mime="application/pdf")
291
-
 
4
  import glob
5
  import asyncio
6
  import hashlib
 
7
  import unicodedata
8
  import streamlit as st
9
  from PIL import Image
 
18
 
19
  st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
20
 
21
+ async def generate_audio(text, voice):
22
+ filename = f"{hashlib.md5(text.encode()).hexdigest()}_{voice}.mp3"
23
+ communicate = edge_tts.Communicate(text, voice)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  await communicate.save(filename)
25
  return filename
26
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def apply_emoji_font(text, emoji_font):
 
28
  emoji_pattern = re.compile(
29
  r"([\U0001F300-\U0001F5FF"
30
  r"\U0001F600-\U0001F64F"
 
47
  for match in emoji_pattern.finditer(text):
48
  start, end = match.span()
49
  if last_pos < start:
50
+ segments.append(f'<font face="DejaVuSans">{text[last_pos:start]}</font>')
51
  segments.append(replace_emoji(match))
52
  last_pos = end
53
  if last_pos < len(text):
54
+ segments.append(f'<font face="DejaVuSans">{text[last_pos:]}</font>')
55
  return ''.join(segments)
56
 
57
  def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers):
 
58
  lines = markdown_text.strip().split('\n')
59
  pdf_content = []
60
  number_pattern = re.compile(r'^\d+\.\s')
 
71
  total_lines = len(pdf_content)
72
  return pdf_content, total_lines
73
 
74
+ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns):
75
  buffer = io.BytesIO()
76
  page_width = A4[0] * 2
77
  page_height = A4[1]
 
134
  else:
135
  column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), section_style))
136
  else:
137
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(item, "DejaVuSans"), item_style))
138
  max_cells = max(len(cells) for cells in column_cells) if column_cells else 0
139
  for cells in column_cells:
140
  cells.extend([Paragraph("", item_style)] * (max_cells - len(cells)))
 
171
  st.error(f"Failed to render PDF preview: {e}")
172
  return None
173
 
174
+ default_markdown = """# Deities Guide: Mythology and Moral Lessons ๐ŸŒŸโœจ
175
+
176
+ 1. ๐Ÿ“œ **Introduction**
177
+ - **Purpose**: Explore deities, spirits, saints, and beings with their epic stories and morals! ๐ŸŒ๐Ÿ“–
178
+ - **Usage**: A guide for learning and storytelling across traditions. ๐ŸŽญโœ๏ธ
179
+ - **Themes**: Justice โš–๏ธ, faith ๐Ÿ™, hubris ๐Ÿ˜ค, redemption ๐ŸŒˆ, cosmic order ๐ŸŒŒ.
180
+
181
+ 2. ๐Ÿ› ๏ธ **Core Concepts of Divinity**
182
+ - **Powers**: Creation ๐ŸŒ, omniscience ๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ, shapeshifting ๐Ÿฆ‹ across entities.
183
+ - **Life Cycle**: Mortality ๐Ÿ’€, immortality โœจ, transitions like saints and avatars ๐ŸŒŸ.
184
+ - **Communication**: Omens ๐ŸŒฉ๏ธ, visions ๐Ÿ‘๏ธ, miracles โœจ from gods and spirits.
185
+
186
+ 3. โšก **Standard Abilities**
187
+ - **Creation**: Gods and spirits shape worlds, e.g., Allah ๐ŸŒ and Vishnu ๐ŸŒ€.
188
+ - **Influence**: Saints and prophets intercede, like Muhammad ๐Ÿ•Œ and Paul โœ๏ธ.
189
+ - **Transformation**: Angels and avatars shift forms, e.g., Gabriel ๐Ÿ˜‡ and Krishna ๐Ÿฆš.
190
+ - **Knowledge**: Foresight ๐Ÿ”ฎ or revelation ๐Ÿ“œ, as with the Holy Spirit ๐Ÿ•Š๏ธ and Brahma ๐Ÿง .
191
+ - **Judgment**: Divine authority ๐Ÿ‘‘, e.g., Yahweh โš–๏ธ and Yama ๐Ÿ’€.
192
+
193
+ 4. โณ **Mortality and Immortality**
194
+ - **Gods**: Eternal โฐ, like Allah ๐ŸŒŸ and Shiva ๐Ÿ•‰๏ธ.
195
+ - **Spirits**: Realm-bound ๐ŸŒ , e.g., jinn ๐Ÿ”ฅ and devas โœจ.
196
+ - **Saints/Prophets**: Mortal to divine ๐ŸŒโžก๏ธ๐ŸŒŒ, e.g., Moses ๐Ÿ“œ and Rama ๐Ÿน.
197
+ - **Beings**: Limbo states โ“, like cherubim ๐Ÿ˜‡ and rakshasas ๐Ÿ‘น.
198
+ - **Lessons**: Faith ๐Ÿ™ and duty โš™๏ธ define transitions.
199
+
200
+ 5. ๐ŸŒ  **Ascension and Signs**
201
+ - **Paths**: Birth ๐Ÿ‘ถ, deeds ๐Ÿ›ก๏ธ, revelation ๐Ÿ“–, as with Jesus โœ๏ธ and Arjuna ๐Ÿน.
202
+ - **Signs**: Miracles โœจ and prophecies ๐Ÿ”ฎ, like those in the Quran ๐Ÿ“˜ and Gita ๐Ÿ“š.
203
+ - **Morals**: Obedience ๐ŸงŽ and devotion โค๏ธ shape destiny ๐ŸŒŸ.
204
+
205
+ 6. ๐ŸŽฒ **Storytelling and Games**
206
+ - **Portrayal**: Gods, spirits, and saints in narratives or RPGs ๐ŸŽฎ๐Ÿ“œ.
207
+ - **Dynamics**: Clerics โ›ช, imams ๐Ÿ•Œ, and sadhus ๐Ÿง˜ serve higher powers.
208
+ - **Balance**: Power ๐Ÿ’ช vs. personality ๐Ÿ˜Š for depth.
209
+
210
+ 7. ๐ŸŽฎ **Dungeon Mastering Beings**
211
+ - **Gods**: Epic scope ๐ŸŒŒ, e.g., Allah โœจ and Vishnu ๐ŸŒ€.
212
+ - **Spirits**: Local influence ๐Ÿž๏ธ, like jinn ๐Ÿ”ฅ and apsaras ๐Ÿ’ƒ.
213
+ - **Saints**: Moral anchors โš“, e.g., St. Francis ๐Ÿพ and Ali โš”๏ธ.
214
+
215
+ 8. ๐Ÿ™ **Devotee Relationships**
216
+ - **Clerics**: Serve gods, e.g., Krishnaโ€™s priests ๐Ÿฆš.
217
+ - **Mediums**: Channel spirits, like jinn whisperers ๐Ÿ”ฅ๐Ÿ‘๏ธ.
218
+ - **Faithful**: Venerate saints and prophets, e.g., Fatimaโ€™s followers ๐ŸŒน.
219
+
220
+ 9. ๐Ÿฆ… **American Indian Traditions**
221
+ - **Coyote, Raven, White Buffalo Woman**: Trickster kin ๐ŸฆŠ๐Ÿฆ and wise mother ๐Ÿƒ.
222
+ - **Relation**: Siblings and guide teach balance โš–๏ธ.
223
+ - **Lesson**: Chaos ๐ŸŒช๏ธ breeds wisdom ๐Ÿง .
224
+
225
+ 10. โš”๏ธ **Arthurian Legends**
226
+ - **Merlin, Morgan le Fay, Arthur**: Mentor ๐Ÿง™, rival ๐Ÿง™โ€โ™€๏ธ, son ๐Ÿ‘‘.
227
+ - **Relation**: Family tests loyalty ๐Ÿค.
228
+ - **Lesson**: Honor ๐Ÿ›ก๏ธ vs. betrayal ๐Ÿ—ก๏ธ.
229
+
230
+ 11. ๐Ÿ›๏ธ **Babylonian Mythology**
231
+ - **Marduk, Tiamat, Ishtar**: Son โš”๏ธ, mother ๐ŸŒŠ, lover โค๏ธ.
232
+ - **Relation**: Kinship drives order ๐Ÿฐ.
233
+ - **Lesson**: Power ๐Ÿ’ช reshapes chaos ๐ŸŒช๏ธ.
234
+
235
+ 12. โœ๏ธ **Christian Trinity**
236
+ - **God (Yahweh), Jesus, Holy Spirit**: Father ๐Ÿ‘‘, Son โœ๏ธ, Spirit ๐Ÿ•Š๏ธ.
237
+ - **Relation**: Divine family redeems ๐ŸŒˆ.
238
+ - **Lesson**: Faith ๐Ÿ™ restores grace โœจ.
239
+
240
+ 13. ๐Ÿ˜‡ **Christian Saints & Angels**
241
+ - **St. Michael, Gabriel, Mary**: Warrior โš”๏ธ, messenger ๐Ÿ“œ, mother ๐ŸŒน.
242
+ - **Relation**: Heavenly kin serve God ๐Ÿ‘‘.
243
+ - **Lesson**: Duty โš™๏ธ upholds divine will ๐ŸŒŸ.
244
+
245
+ 14. ๐Ÿ€ **Celtic Mythology**
246
+ - **Lugh, Morrigan, Cernunnos**: Son โ˜€๏ธ, mother ๐Ÿฆ‡, father ๐ŸฆŒ.
247
+ - **Relation**: Family governs cycles ๐ŸŒ.
248
+ - **Lesson**: Courage ๐Ÿ’ช in fate ๐ŸŽฒ.
249
+
250
+ 15. ๐ŸŒ„ **Central American Traditions**
251
+ - **Quetzalcoatl, Tezcatlipoca, Huitzilopochtli**: Brothers ๐Ÿ๐Ÿ† and war son โš”๏ธ.
252
+ - **Relation**: Sibling rivalry creates ๐ŸŒ.
253
+ - **Lesson**: Sacrifice ๐Ÿฉธ builds worlds ๐Ÿฐ.
254
+
255
+ 16. ๐Ÿ‰ **Chinese Mythology**
256
+ - **Jade Emperor, Nuwa, Sun Wukong**: Father ๐Ÿ‘‘, mother ๐Ÿ, rebel son ๐Ÿ’.
257
+ - **Relation**: Family enforces harmony ๐ŸŽถ.
258
+ - **Lesson**: Duty โš™๏ธ curbs chaos ๐ŸŒช๏ธ.
259
+
260
+ 17. ๐Ÿ™ **Cthulhu Mythos**
261
+ - **Cthulhu, Nyarlathotep, Yog-Sothoth**: Elder kin ๐Ÿ™๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ๐ŸŒŒ.
262
+ - **Relation**: Cosmic trio overwhelms ๐Ÿ˜ฑ.
263
+ - **Lesson**: Insignificance ๐ŸŒŒ humbles ๐Ÿ™‡.
264
+
265
+ 18. โ˜ฅ **Egyptian Mythology**
266
+ - **Ra, Osiris, Isis**: Father โ˜€๏ธ, son โšฐ๏ธ, mother ๐ŸŒŸ.
267
+ - **Relation**: Family ensures renewal ๐Ÿ”„.
268
+ - **Lesson**: Justice โš–๏ธ prevails.
269
+
270
+ 19. โ„๏ธ **Finnish Mythology**
271
+ - **Vรคinรคmรถinen, Louhi, Ukko**: Son ๐ŸŽถ, mother โ„๏ธ, father โšก.
272
+ - **Relation**: Kinship tests wisdom ๐Ÿง .
273
+ - **Lesson**: Perseverance ๐Ÿ‹๏ธ wins.
274
+
275
+ 20. ๐Ÿ›๏ธ **Greek Mythology**
276
+ - **Zeus, Hera, Athena**: Father โšก, mother ๐Ÿ‘‘, daughter ๐Ÿฆ‡.
277
+ - **Relation**: Family rules with tension โš”๏ธ.
278
+ - **Lesson**: Hubris ๐Ÿ˜ค meets wisdom ๐Ÿง .
279
+
280
+ 21. ๐Ÿ•‰๏ธ **Hindu Trimurti**
281
+ - **Brahma, Vishnu, Shiva**: Creator ๐ŸŒ€, preserver ๐Ÿ›ก๏ธ, destroyer ๐Ÿ”ฅ.
282
+ - **Relation**: Divine trio cycles existence ๐Ÿ”„.
283
+ - **Lesson**: Balance โš–๏ธ sustains life ๐ŸŒ.
284
+
285
+ 22. ๐ŸŒบ **Hindu Avatars & Devis**
286
+ - **Krishna, Rama, Durga**: Sons ๐Ÿฆš๐Ÿน and fierce mother ๐Ÿ—ก๏ธ.
287
+ - **Relation**: Avatars and goddess protect dharma โš–๏ธ.
288
+ - **Lesson**: Duty โš™๏ธ defeats evil ๐Ÿ‘น.
289
+
290
+ 23. ๐ŸŒธ **Japanese Mythology**
291
+ - **Amaterasu, Susanoo, Tsukuyomi**: Sister โ˜€๏ธ, brothers ๐ŸŒŠ๐ŸŒ™.
292
+ - **Relation**: Siblings balance cosmos ๐ŸŒŒ.
293
+ - **Lesson**: Harmony ๐ŸŽถ vs. chaos ๐ŸŒช๏ธ.
294
+
295
+ 24. ๐Ÿ—ก๏ธ **Melnibonean Legends**
296
+ - **Arioch, Xiombarg, Elric**: Lords ๐Ÿ‘‘ and mortal son โš”๏ธ.
297
+ - **Relation**: Pact binds chaos ๐ŸŒช๏ธ.
298
+ - **Lesson**: Power ๐Ÿ’ช corrupts ๐Ÿ˜ˆ.
299
+
300
+ 25. โ˜ช๏ธ **Muslim Divine & Messengers**
301
+ - **Allah, Muhammad, Gabriel**: God ๐ŸŒŸ, prophet ๐Ÿ•Œ, angel ๐Ÿ˜‡.
302
+ - **Relation**: Messenger reveals divine will ๐Ÿ“œ.
303
+ - **Lesson**: Submission ๐Ÿ™‡ brings peace โ˜ฎ๏ธ.
304
+
305
+ 26. ๐Ÿ‘ป **Muslim Spirits & Kin**
306
+ - **Jinn, Iblis, Khidr**: Spirits ๐Ÿ”ฅ๐Ÿ˜ˆ and guide ๐ŸŒฟ defy or aid.
307
+ - **Relation**: Supernatural kin test faith ๐Ÿ™.
308
+ - **Lesson**: Obedience ๐ŸงŽ vs. rebellion ๐Ÿ˜ก.
309
+
310
+ 27. ๐Ÿฐ **Nehwon Legends**
311
+ - **Death, Ningauble, Sheelba**: Fateful trio ๐Ÿ’€๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ๐ŸŒฟ.
312
+ - **Relation**: Guides shape destiny ๐ŸŽฒ.
313
+ - **Lesson**: Cunning ๐Ÿง  defies fate โšฐ๏ธ.
314
+
315
+ 28. ๐Ÿง **Nonhuman Traditions**
316
+ - **Corellon, Moradin, Gruumsh**: Elf ๐Ÿง, dwarf โ›๏ธ, orc ๐Ÿ—ก๏ธ fathers.
317
+ - **Relation**: Rivals define purpose โš”๏ธ.
318
+ - **Lesson**: Community ๐Ÿค endures.
319
+
320
+ 29. แšฑ **Norse Mythology**
321
+ - **Odin, Frigg, Loki**: Father ๐Ÿ‘๏ธ, mother ๐Ÿ‘‘, trickster son ๐ŸฆŠ.
322
+ - **Relation**: Family faces doom โšก.
323
+ - **Lesson**: Sacrifice ๐Ÿฉธ costs.
324
+
325
+ 30. ๐Ÿ—ฟ **Sumerian Mythology**
326
+ - **Enki, Inanna, Anu**: Son ๐ŸŒŠ, daughter โค๏ธ, father ๐ŸŒŒ.
327
+ - **Relation**: Kin wield knowledge ๐Ÿง .
328
+ - **Lesson**: Ambition ๐ŸŒŸ shapes.
329
+
330
+ 31. ๐Ÿ“š **Appendices**
331
+ - **Planes**: Realms of gods, spirits, saints, e.g., Paradise ๐ŸŒˆ and Svarga โœจ.
332
+ - **Symbols**: Rituals ๐Ÿ•‰๏ธ and artifacts ๐Ÿ—ฟ of faith.
333
+ - **Charts**: Domains and duties for devotees ๐Ÿ“Š.
334
+
335
+ 32. ๐ŸŒŒ **Planes of Existence**
336
+ - **Heaven/Paradise**: Christian/Muslim abode ๐ŸŒŸ.
337
+ - **Svarga**: Hindu divine realm โœจ.
338
+ - **Underworld**: Spirits linger, e.g., Sheol โšฐ๏ธ and Naraka ๐Ÿ”ฅ.
339
+
340
+ 33. ๐Ÿ• **Temple Trappings**
341
+ - **Cross/Crescent**: Christian/Muslim faith โœ๏ธโ˜ช๏ธ.
342
+ - **Mandalas**: Hindu devotion ๐ŸŒ€.
343
+ - **Relics**: Saintsโ€™ and prophetsโ€™ legacy ๐Ÿ—๏ธ.
344
+
345
+ 34. ๐Ÿ“Š **Clerical Chart**
346
+ - **Gods**: Domains, e.g., creation ๐ŸŒ and mercy โค๏ธ.
347
+ - **Spirits**: Influence, like guidance ๐ŸŒฟ and mischief ๐Ÿ˜ˆ.
348
+ - **Saints/Prophets**: Virtues, e.g., justice โš–๏ธ and prophecy ๐Ÿ”ฎ.
349
+ """
350
+
351
  md_files = [f for f in glob.glob("*.md") if os.path.basename(f) != "README.md"]
352
  md_options = [os.path.splitext(os.path.basename(f))[0] for f in md_files]
 
 
 
 
 
 
353
 
354
  with st.sidebar:
355
  st.markdown("### PDF Options")
 
361
  auto_bold_numbers = st.checkbox("Auto Bold Numbered Lines", value=True, key="auto_bold_numbers")
362
  enlarge_numbered = st.checkbox("Enlarge Font Size for Numbered Lines", value=True, key="enlarge_numbered")
363
  num_columns = st.selectbox("Number of Columns", options=[1, 2, 3, 4, 5, 6], index=3)
364
+ if 'markdown_content' not in st.session_state or not md_options:
365
+ st.session_state.markdown_content = default_markdown
366
  if md_options and selected_md:
367
  with open(f"{selected_md}.md", "r", encoding="utf-8") as f:
368
  st.session_state.markdown_content = f.read()
 
378
  VOICES = ["en-US-AriaNeural", "en-US-JennyNeural", "en-GB-SoniaNeural", "en-US-GuyNeural", "en-US-AnaNeural"]
379
  selected_voice = st.selectbox("Select Voice for TTS", options=VOICES, index=0)
380
  if st.button("Generate Audio"):
381
+ audio_file = asyncio.run(generate_audio(st.session_state.markdown_content, selected_voice))
382
  st.audio(audio_file)
383
  with open(audio_file, "rb") as f:
384
  audio_bytes = f.read()
385
  st.download_button("Download Audio", data=audio_bytes, file_name=os.path.basename(audio_file), mime="audio/mpeg")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
 
387
  with st.spinner("Generating PDF..."):
388
+ pdf_bytes = create_pdf(st.session_state.markdown_content, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns)
389
 
390
  with st.container():
391
  pdf_images = pdf_to_image(pdf_bytes)
 
397
 
398
  with st.sidebar:
399
  st.download_button(label="Download PDF", data=pdf_bytes, file_name="output.pdf", mime="application/pdf")