awacke1 commited on
Commit
b51b5a6
ยท
verified ยท
1 Parent(s): 45c2a49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -192
app.py CHANGED
@@ -15,11 +15,18 @@ from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
15
  from reportlab.lib import colors
16
  from reportlab.pdfbase import pdfmetrics
17
  from reportlab.pdfbase.ttfonts import TTFont
 
 
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
@@ -78,7 +85,6 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
78
  doc = SimpleDocTemplate(buffer, pagesize=(page_width, page_height), leftMargin=36, rightMargin=36, topMargin=36, bottomMargin=36)
79
  styles = getSampleStyleSheet()
80
  spacer_height = 10
81
- section_spacer_height = 15
82
  pdf_content, total_lines = markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers)
83
  item_style = ParagraphStyle(
84
  'ItemStyle', parent=styles['Normal'], fontName="DejaVuSans",
@@ -171,218 +177,61 @@ def pdf_to_image(pdf_bytes):
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")
356
- selected_md = st.selectbox("Select Markdown File", options=md_options, index=0 if md_options else -1)
 
 
 
 
 
 
 
 
357
  available_font_files = {os.path.splitext(os.path.basename(f))[0]: f for f in glob.glob("*.ttf")}
358
- selected_font_name = st.selectbox("Select Emoji Font", options=list(available_font_files.keys()), index=list(available_font_files.keys()).index("NotoEmoji-Bold") if "NotoEmoji-Bold" in available_font_files else 0)
 
359
  base_font_size = st.slider("Font Size (points)", min_value=6, max_value=16, value=8, step=1)
360
  render_with_bold = st.checkbox("Render with Bold Formatting (remove ** markers)", value=True, key="render_with_bold")
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()
369
  edited_markdown = st.text_area("Modify the markdown content below:", value=st.session_state.markdown_content, height=300, key=f"markdown_{selected_md}_{selected_font_name}_{num_columns}")
370
  if st.button("Update PDF"):
371
  st.session_state.markdown_content = edited_markdown
372
- if md_options and selected_md:
373
  with open(f"{selected_md}.md", "w", encoding="utf-8") as f:
374
  f.write(edited_markdown)
375
  st.experimental_rerun()
376
- st.download_button(label="Save Markdown", data=st.session_state.markdown_content, file_name=f"{selected_md}.md" if selected_md else "default.md", mime="text/markdown")
 
 
 
 
 
 
 
 
 
 
 
377
  st.markdown("### Text-to-Speech")
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)
@@ -395,5 +244,11 @@ with st.container():
395
  else:
396
  st.info("Download the PDF to view it locally.")
397
 
 
398
  with st.sidebar:
399
- st.download_button(label="Download PDF", data=pdf_bytes, file_name="output.pdf", mime="application/pdf")
 
 
 
 
 
 
15
  from reportlab.lib import colors
16
  from reportlab.pdfbase import pdfmetrics
17
  from reportlab.pdfbase.ttfonts import TTFont
18
+ from datetime import datetime
19
+ import pytz
20
 
21
  st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
22
 
23
+ def get_timestamp_prefix():
24
+ central = pytz.timezone("US/Central")
25
+ now = datetime.now(central)
26
+ # Format: three-letter day, MMDD, HHmm + AM/PM (all uppercase)
27
+ return now.strftime("%a %m%d %I%M%p").upper()
28
+
29
+ async def generate_audio(text, voice, filename):
30
  communicate = edge_tts.Communicate(text, voice)
31
  await communicate.save(filename)
32
  return filename
 
85
  doc = SimpleDocTemplate(buffer, pagesize=(page_width, page_height), leftMargin=36, rightMargin=36, topMargin=36, bottomMargin=36)
86
  styles = getSampleStyleSheet()
87
  spacer_height = 10
 
88
  pdf_content, total_lines = markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers)
89
  item_style = ParagraphStyle(
90
  'ItemStyle', parent=styles['Normal'], fontName="DejaVuSans",
 
177
  st.error(f"Failed to render PDF preview: {e}")
178
  return None
179
 
180
+ # -- Markdown File Selection --
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  md_files = [f for f in glob.glob("*.md") if os.path.basename(f) != "README.md"]
182
  md_options = [os.path.splitext(os.path.basename(f))[0] for f in md_files]
183
 
184
  with st.sidebar:
185
  st.markdown("### PDF Options")
186
+ if md_options:
187
+ selected_md = st.selectbox("Select Markdown File", options=md_options, index=0)
188
+ with open(f"{selected_md}.md", "r", encoding="utf-8") as f:
189
+ st.session_state.markdown_content = f.read()
190
+ else:
191
+ st.warning("No markdown file found. Please add one to your folder.")
192
+ selected_md = None
193
+ st.session_state.markdown_content = ""
194
+
195
  available_font_files = {os.path.splitext(os.path.basename(f))[0]: f for f in glob.glob("*.ttf")}
196
+ selected_font_name = st.selectbox("Select Emoji Font", options=list(available_font_files.keys()),
197
+ index=list(available_font_files.keys()).index("NotoEmoji-Bold") if "NotoEmoji-Bold" in available_font_files else 0)
198
  base_font_size = st.slider("Font Size (points)", min_value=6, max_value=16, value=8, step=1)
199
  render_with_bold = st.checkbox("Render with Bold Formatting (remove ** markers)", value=True, key="render_with_bold")
200
  auto_bold_numbers = st.checkbox("Auto Bold Numbered Lines", value=True, key="auto_bold_numbers")
201
  enlarge_numbered = st.checkbox("Enlarge Font Size for Numbered Lines", value=True, key="enlarge_numbered")
202
  num_columns = st.selectbox("Number of Columns", options=[1, 2, 3, 4, 5, 6], index=3)
203
+
204
+ # Use the file's content for editing
 
 
 
205
  edited_markdown = st.text_area("Modify the markdown content below:", value=st.session_state.markdown_content, height=300, key=f"markdown_{selected_md}_{selected_font_name}_{num_columns}")
206
  if st.button("Update PDF"):
207
  st.session_state.markdown_content = edited_markdown
208
+ if selected_md:
209
  with open(f"{selected_md}.md", "w", encoding="utf-8") as f:
210
  f.write(edited_markdown)
211
  st.experimental_rerun()
212
+
213
+ # Create a timestamp prefix for file naming
214
+ prefix = get_timestamp_prefix()
215
+
216
+ # Download button for Markdown with new naming convention
217
+ st.download_button(
218
+ label="Save Markdown",
219
+ data=st.session_state.markdown_content,
220
+ file_name=f"{prefix} {selected_md}.md" if selected_md else f"{prefix} default.md",
221
+ mime="text/markdown"
222
+ )
223
+
224
  st.markdown("### Text-to-Speech")
225
  VOICES = ["en-US-AriaNeural", "en-US-JennyNeural", "en-GB-SoniaNeural", "en-US-GuyNeural", "en-US-AnaNeural"]
226
  selected_voice = st.selectbox("Select Voice for TTS", options=VOICES, index=0)
227
  if st.button("Generate Audio"):
228
+ # Create a filename for the audio file using the timestamp, markdown name, and selected voice
229
+ audio_filename = f"{prefix} {selected_md} {selected_voice}.mp3" if selected_md else f"{prefix} default {selected_voice}.mp3"
230
+ audio_file = asyncio.run(generate_audio(st.session_state.markdown_content, selected_voice, audio_filename))
231
  st.audio(audio_file)
232
  with open(audio_file, "rb") as f:
233
  audio_bytes = f.read()
234
+ st.download_button("Download Audio", data=audio_bytes, file_name=audio_filename, mime="audio/mpeg")
235
 
236
  with st.spinner("Generating PDF..."):
237
  pdf_bytes = create_pdf(st.session_state.markdown_content, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns)
 
244
  else:
245
  st.info("Download the PDF to view it locally.")
246
 
247
+ # Download button for PDF with new naming convention
248
  with st.sidebar:
249
+ st.download_button(
250
+ label="Download PDF",
251
+ data=pdf_bytes,
252
+ file_name=f"{prefix} {selected_md}.pdf" if selected_md else f"{prefix} output.pdf",
253
+ mime="application/pdf"
254
+ )