awacke1 commited on
Commit
56c076f
·
verified ·
1 Parent(s): fee4187

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +476 -0
app.py ADDED
@@ -0,0 +1,476 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import io
3
+ import re
4
+ import streamlit as st
5
+
6
+ st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
7
+
8
+ from PIL import Image
9
+ import fitz
10
+
11
+ from reportlab.lib.pagesizes import A4
12
+ from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
13
+ from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
14
+ from reportlab.lib import colors
15
+ from reportlab.pdfbase import pdfmetrics
16
+ from reportlab.pdfbase.ttfonts import TTFont
17
+
18
+ available_fonts = {
19
+ "NotoEmoji Variable": "NotoEmoji-VariableFont_wght.ttf",
20
+ "NotoEmoji Bold": "NotoEmoji-Bold.ttf",
21
+ "NotoEmoji Light": "NotoEmoji-Light.ttf",
22
+ "NotoEmoji Medium": "NotoEmoji-Medium.ttf",
23
+ "NotoEmoji Regular": "NotoEmoji-Regular.ttf",
24
+ "NotoEmoji SemiBold": "NotoEmoji-SemiBold.ttf"
25
+ }
26
+
27
+ with st.sidebar:
28
+ selected_font_name = st.selectbox(
29
+ "Select NotoEmoji Font",
30
+ options=list(available_fonts.keys())
31
+ )
32
+ selected_font_path = available_fonts[selected_font_name]
33
+
34
+ auto_size = st.checkbox("Auto-size text", value=True)
35
+ base_font_size = st.slider("Base Font Size (points)", min_value=6, max_value=16, value=10, step=1)
36
+ if auto_size:
37
+ st.info("Font size will adjust between 6-16 points based on content length, starting from your base size.")
38
+
39
+ show_subitems = st.checkbox("Show Sub-items (e.g., 1.1, 2.1.3)", value=True)
40
+ plain_text_mode = st.checkbox("Render as Plain Text (Preserve Bold Only)", value=False)
41
+
42
+ pdfmetrics.registerFont(TTFont(selected_font_name, selected_font_path))
43
+
44
+ def apply_emoji_font(text, emoji_font):
45
+ emoji_pattern = re.compile(
46
+ r"([\U0001F300-\U0001F5FF"
47
+ r"\U0001F600-\U0001F64F"
48
+ r"\U0001F680-\U0001F6FF"
49
+ r"\U0001F700-\U0001F77F"
50
+ r"\U0001F780-\U0001F7FF"
51
+ r"\U0001F800-\U0001F8FF"
52
+ r"\U0001F900-\U0001F9FF"
53
+ r"\U0001FA00-\U0001FA6F"
54
+ r"\U0001FA70-\U0001FAFF"
55
+ r"\u2600-\u26FF"
56
+ r"\u2700-\u27BF]+)"
57
+ )
58
+ def replace_emoji(match):
59
+ emoji = match.group(1)
60
+ if len(emoji) > 1:
61
+ emoji = emoji[0]
62
+ return f'<font face="{emoji_font}">{emoji}</font>'
63
+ return emoji_pattern.sub(replace_emoji, text)
64
+
65
+ default_markdown = """# 🌟 Deities Guide: Mythology and Moral Lessons 🌟
66
+
67
+ ## 1. 📜 Introduction
68
+ 1. Purpose: Explore deities, spirits, saints, and beings with their stories and morals.
69
+ 2. Usage: Guide for learning and storytelling across traditions.
70
+ 3. Themes: Justice, faith, hubris, redemption, cosmic order.
71
+
72
+ ## 2. 🛠️ Core Concepts of Divinity
73
+ 1. Powers: Creation, omniscience, shapeshifting across entities.
74
+ 2. Life Cycle: Mortality, immortality, transitions (e.g., saints, avatars).
75
+ 3. Communication: Omens, visions, miracles from gods and spirits.
76
+
77
+ ### 2.1. ⚡ Standard Abilities
78
+ 1. Creation: Gods and spirits shape worlds (e.g., Allah, Vishnu).
79
+ 2. Influence: Saints, prophets intercede (e.g., Muhammad, Paul).
80
+ 3. Transformation: Angels, avatars shift forms (e.g., Gabriel, Krishna).
81
+ 4. Knowledge: Foresight or revelation (e.g., Holy Spirit, Brahma).
82
+ 5. Judgment: Divine authority (e.g., Yahweh, Yama).
83
+
84
+ ### 2.2. ⏳ Mortality and Immortality
85
+ 1. Gods: Eternal (e.g., Allah, Shiva).
86
+ 2. Spirits: Realm-bound (e.g., jinn, devas).
87
+ 3. Saints/Prophets: Mortal to divine (e.g., Moses, Rama).
88
+ 4. Beings: Limbo states (e.g., cherubim, rakshasas).
89
+ 5. Lessons: Faith, duty define transitions.
90
+
91
+ ### 2.3. 🌠 Ascension and Signs
92
+ 1. Paths: Birth, deeds, revelation (e.g., Jesus, Arjuna).
93
+ 2. Signs: Miracles, prophecies (e.g., Quran, Gita).
94
+ 3. Morals: Obedience, devotion shape destiny.
95
+
96
+ ## 3. 🎲 Storytelling and Games
97
+ 1. Portrayal: Gods, spirits, saints in narratives or RPGs.
98
+ 2. Dynamics: Clerics, imams, sadhus serve higher powers.
99
+ 3. Balance: Power vs. personality for depth.
100
+
101
+ ### 3.1. 🎮 Dungeon Mastering Beings
102
+ 1. Gods: Epic scope (e.g., Allah, Vishnu).
103
+ 2. Spirits: Local influence (e.g., jinn, apsaras).
104
+ 3. Saints: Moral anchors (e.g., St. Francis, Ali).
105
+
106
+ ### 3.2. 🙏 Devotee Relationships
107
+ 1. Clerics: Serve gods (e.g., Krishna’s priests).
108
+ 2. Mediums: Channel spirits (e.g., jinn whisperers).
109
+ 3. Faithful: Venerate saints/prophets (e.g., Fatima’s followers).
110
+
111
+ ## 4. 🌐 Traditions and Legends
112
+ *(Top three figures—gods, spirits, saints, beings—with relationships and morals)*
113
+ 1. **American Indian** 🦅
114
+ 1. Coyote, Raven, White Buffalo Woman: Trickster kin and wise mother.
115
+ 2. Relation: Siblings and guide teach balance.
116
+ 3. Lesson: Chaos breeds wisdom.
117
+ 2. **Arthurian** ⚔️
118
+ 1. Merlin, Morgan le Fay, Arthur: Mentor, rival, son.
119
+ 2. Relation: Family tests loyalty.
120
+ 3. Lesson: Honor vs. betrayal.
121
+ 3. **Babylonian** 🏛️
122
+ 1. Marduk, Tiamat, Ishtar: Son, mother, lover.
123
+ 2. Relation: Kinship drives order.
124
+ 3. Lesson: Power reshapes chaos.
125
+ 4. **Christian: Trinity** ✝️
126
+ 1. God (Yahweh), Jesus, Holy Spirit: Father, Son, Spirit.
127
+ 2. Relation: Divine family redeems.
128
+ 3. Lesson: Faith restores grace.
129
+ 5. **Christian: Saints & Angels** 😇
130
+ 1. St. Michael, Gabriel, Mary: Warrior, messenger, mother.
131
+ 2. Relation: Heavenly kin serve God.
132
+ 3. Lesson: Duty upholds divine will.
133
+ 6. **Celtic** 🍀
134
+ 1. Lugh, Morrigan, Cernunnos: Son, mother, father.
135
+ 2. Relation: Family governs cycles.
136
+ 3. Lesson: Courage in fate.
137
+ 7. **Central American** 🌄
138
+ 1. Quetzalcoatl, Tezcatlipoca, Huitzilopochtli: Brothers and war son.
139
+ 2. Relation: Sibling rivalry creates.
140
+ 3. Lesson: Sacrifice builds worlds.
141
+ 8. **Chinese** 🐉
142
+ 1. Jade Emperor, Nuwa, Sun Wukong: Father, mother, rebel son.
143
+ 2. Relation: Family enforces harmony.
144
+ 3. Lesson: Duty curbs chaos.
145
+ 9. **Cthulhu** 🐙
146
+ 1. Cthulhu, Nyarlathotep, Yog-Sothoth: Elder kin.
147
+ 2. Relation: Cosmic trio overwhelms.
148
+ 3. Lesson: Insignificance humbles.
149
+ 10. **Egyptian** ☥
150
+ 1. Ra, Osiris, Isis: Father, son, mother.
151
+ 2. Relation: Family ensures renewal.
152
+ 3. Lesson: Justice prevails.
153
+ 11. **Finnish** ❄️
154
+ 1. Väinämöinen, Louhi, Ukko: Son, mother, father.
155
+ 2. Relation: Kinship tests wisdom.
156
+ 3. Lesson: Perseverance wins.
157
+ 12. **Greek** 🏛️
158
+ 1. Zeus, Hera, Athena: Father, mother, daughter.
159
+ 2. Relation: Family rules with tension.
160
+ 3. Lesson: Hubris meets wisdom.
161
+ 13. **Hindu: Trimurti** 🕉️
162
+ 1. Brahma, Vishnu, Shiva: Creator, preserver, destroyer.
163
+ 2. Relation: Divine trio cycles existence.
164
+ 3. Lesson: Balance sustains life.
165
+ 14. **Hindu: Avatars & Devis** 🌺
166
+ 1. Krishna, Rama, Durga: Sons and fierce mother.
167
+ 2. Relation: Avatars and goddess protect dharma.
168
+ 3. Lesson: Duty defeats evil.
169
+ 15. **Japanese** 🌸
170
+ 1. Amaterasu, Susanoo, Tsukuyomi: Sister, brothers.
171
+ 2. Relation: Siblings balance cosmos.
172
+ 3. Lesson: Harmony vs. chaos.
173
+ 16. **Melnibonean** 🗡️
174
+ 1. Arioch, Xiombarg, Elric: Lords and mortal son.
175
+ 2. Relation: Pact binds chaos.
176
+ 3. Lesson: Power corrupts.
177
+ 17. **Muslim: Divine & Messengers** ☪️
178
+ 1. Allah, Muhammad, Gabriel: God, prophet, angel.
179
+ 2. Relation: Messenger reveals divine will.
180
+ 3. Lesson: Submission brings peace.
181
+ 18. **Muslim: Spirits & Kin** 👻
182
+ 1. Jinn, Iblis, Khidr: Spirits and guide defy or aid.
183
+ 2. Relation: Supernatural kin test faith.
184
+ 3. Lesson: Obedience vs. rebellion.
185
+ 19. **Nehwon** 🏰
186
+ 1. Death, Ningauble, Sheelba: Fateful trio.
187
+ 2. Relation: Guides shape destiny.
188
+ 3. Lesson: Cunning defies fate.
189
+ 20. **Nonhumans’** 🧝
190
+ 1. Corellon, Moradin, Gruumsh: Elf, dwarf, orc fathers.
191
+ 2. Relation: Rivals define purpose.
192
+ 3. Lesson: Community endures.
193
+ 21. **Norse** ᚱ
194
+ 1. Odin, Frigg, Loki: Father, mother, trickster son.
195
+ 2. Relation: Family faces doom.
196
+ 3. Lesson: Sacrifice costs.
197
+ 22. **Sumerian** 🗿
198
+ 1. Enki, Inanna, Anu: Son, daughter, father.
199
+ 2. Relation: Kin wield knowledge.
200
+ 3. Lesson: Ambition shapes.
201
+
202
+ ## 5. 📚 Appendices
203
+ 1. Planes: Realms of gods, spirits, saints (e.g., Paradise, Svarga).
204
+ 2. Symbols: Rituals and artifacts of faith.
205
+ 3. Charts: Domains and duties for devotees.
206
+
207
+ ### 5.1. 🌌 Planes of Existence
208
+ 1. Heaven/Paradise: Christian/Muslim abode.
209
+ 2. Svarga: Hindu divine realm.
210
+ 3. Underworld: Spirits linger (e.g., Sheol, Naraka).
211
+
212
+ ### 5.2. 🕍 Temple Trappings
213
+ 1. Cross/Crescent: Christian/Muslim faith.
214
+ 2. Mandalas: Hindu devotion.
215
+ 3. Relics: Saints’ and prophets’ legacy.
216
+
217
+ ### 5.3. 📊 Clerical Chart
218
+ 1. Gods: Domains (e.g., creation, mercy).
219
+ 2. Spirits: Influence (e.g., guidance, mischief).
220
+ 3. Saints/Prophets: Virtues (e.g., justice, prophecy).
221
+ """
222
+
223
+ def markdown_to_pdf_content(markdown_text, show_subitems=True, plain_text_mode=False, font_size=10):
224
+ lines = markdown_text.strip().split('\n')
225
+ pdf_content = []
226
+
227
+ if plain_text_mode:
228
+ for line in lines:
229
+ line = line.strip()
230
+ if not line:
231
+ continue
232
+ if line.startswith('# '):
233
+ continue
234
+ bold_pattern = re.compile(r'\*\*(.*?)\*\*')
235
+ line = bold_pattern.sub(r'<b>\1</b>', line)
236
+ pdf_content.append(line)
237
+ else:
238
+ in_list = False
239
+ current_item = None
240
+ sub_items = []
241
+
242
+ for line in lines:
243
+ line = line.strip()
244
+ if not line:
245
+ continue
246
+
247
+ if line.startswith('# '):
248
+ continue
249
+ elif line.startswith('## '):
250
+ if current_item and sub_items:
251
+ pdf_content.append([current_item, sub_items])
252
+ sub_items = []
253
+ current_item = None
254
+ section = line.replace('## ', '').strip()
255
+ pdf_content.append(f"<b>{section}</b>")
256
+ in_list = False
257
+ elif line.startswith('### '):
258
+ if current_item and sub_items:
259
+ pdf_content.append([current_item, sub_items])
260
+ sub_items = []
261
+ current_item = None
262
+ if show_subitems:
263
+ subsection = line.replace('### ', '').strip()
264
+ pdf_content.append(f"<b>{subsection}</b>")
265
+ in_list = False
266
+ elif re.match(r'^\d+\.', line):
267
+ if current_item and sub_items:
268
+ pdf_content.append([current_item, sub_items])
269
+ sub_items = []
270
+ current_item = line.strip()
271
+ in_list = True
272
+ elif re.match(r'^\d+\.\d+\.', line):
273
+ if show_subitems:
274
+ sub_items.append(line.strip())
275
+ elif line.startswith('*') and not in_list:
276
+ pdf_content.append(line.strip())
277
+ else:
278
+ if in_list:
279
+ sub_items.append(line.strip())
280
+ else:
281
+ pdf_content.append(line.strip())
282
+
283
+ if current_item and sub_items:
284
+ pdf_content.append([current_item, sub_items])
285
+
286
+ total_lines = sum(1 + len(subs) if isinstance(item, list) else 1 for item in pdf_content)
287
+ total_chars = sum(len(item) if isinstance(item, str) else len(item[0]) + sum(len(sub) for sub in item[1]) for item in pdf_content)
288
+ avg_line_length = total_chars / total_lines if total_lines > 0 else 1
289
+
290
+ page_height = A4[0] - 72
291
+ page_width = A4[1] * 2 - 72
292
+ line_height = font_size * 1.15
293
+ lines_per_column = page_height / line_height
294
+
295
+ chars_per_line = avg_line_length * (font_size / 10)
296
+ lines_per_column_width = page_width / (chars_per_line * 0.1)
297
+
298
+ num_columns = max(2, int(total_lines / lines_per_column))
299
+ num_columns = min(num_columns, int(lines_per_column_width))
300
+ if num_columns % 2 != 0:
301
+ num_columns += 1
302
+ num_columns = min(num_columns, 6)
303
+
304
+ lines_per_column = total_lines / num_columns
305
+ columns = [[] for _ in range(num_columns)]
306
+ current_line_count = 0
307
+ current_column = 0
308
+
309
+ for item in pdf_content:
310
+ item_lines = 1 + (len(item[1]) if isinstance(item, list) else 0)
311
+ if current_line_count >= lines_per_column and current_column < num_columns - 1:
312
+ current_column += 1
313
+ current_line_count = 0
314
+ columns[current_column].append(item)
315
+ current_line_count += item_lines
316
+
317
+ return columns, total_lines, num_columns
318
+
319
+ def create_main_pdf(markdown_text, base_font_size=10, auto_size=False, show_subitems=True, plain_text_mode=False):
320
+ buffer = io.BytesIO()
321
+ doc = SimpleDocTemplate(
322
+ buffer,
323
+ pagesize=(A4[1] * 2, A4[0]),
324
+ leftMargin=36,
325
+ rightMargin=36,
326
+ topMargin=36,
327
+ bottomMargin=36
328
+ )
329
+
330
+ styles = getSampleStyleSheet()
331
+ story = []
332
+ spacer_height = 10
333
+ columns, total_lines, num_columns = markdown_to_pdf_content(markdown_text, show_subitems, plain_text_mode, base_font_size)
334
+
335
+ if auto_size:
336
+ base_font_size = max(6, min(16, base_font_size * 300 / total_lines))
337
+
338
+ item_font_size = base_font_size
339
+ subitem_font_size = base_font_size * 0.85
340
+ section_font_size = base_font_size * 1.1
341
+ title_font_size = min(20, base_font_size * 1.4)
342
+
343
+ title_style = ParagraphStyle(
344
+ 'Heading1',
345
+ parent=styles['Heading1'],
346
+ fontName="Helvetica-Bold",
347
+ textColor=colors.darkblue,
348
+ alignment=1,
349
+ fontSize=title_font_size,
350
+ leading=title_font_size * 1.2
351
+ )
352
+
353
+ section_style = ParagraphStyle(
354
+ 'SectionStyle',
355
+ parent=styles['Heading2'],
356
+ fontName="Helvetica-Bold",
357
+ textColor=colors.darkblue,
358
+ fontSize=section_font_size,
359
+ leading=section_font_size * 1.2,
360
+ spaceAfter=2
361
+ )
362
+
363
+ item_style = ParagraphStyle(
364
+ 'ItemStyle',
365
+ parent=styles['Normal'],
366
+ fontName="Helvetica",
367
+ fontSize=item_font_size,
368
+ leading=item_font_size * 1.15,
369
+ spaceAfter=1
370
+ )
371
+
372
+ subitem_style = ParagraphStyle(
373
+ 'SubItemStyle',
374
+ parent=styles['Normal'],
375
+ fontName="Helvetica",
376
+ fontSize=subitem_font_size,
377
+ leading=subitem_font_size * 1.15,
378
+ leftIndent=8,
379
+ spaceAfter=1
380
+ )
381
+
382
+ story.append(Paragraph(apply_emoji_font("Deities Guide: Mythology and Moral Lessons", selected_font_name), title_style))
383
+ story.append(Spacer(1, spacer_height))
384
+
385
+ column_cells = [[] for _ in range(num_columns)]
386
+ for col_idx, column in enumerate(columns):
387
+ for item in column:
388
+ if plain_text_mode:
389
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(item, selected_font_name), item_style))
390
+ else:
391
+ if isinstance(item, str) and item.startswith('<b>'):
392
+ text = item.replace('<b>', '').replace('</b>', '')
393
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(text, selected_font_name), section_style))
394
+ elif isinstance(item, list):
395
+ main_item, sub_items = item
396
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(main_item, selected_font_name), item_style))
397
+ for sub_item in sub_items:
398
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(sub_item, selected_font_name), subitem_style))
399
+ else:
400
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(item, selected_font_name), item_style))
401
+
402
+ max_cells = max(len(cells) for cells in column_cells)
403
+ for cells in column_cells:
404
+ cells.extend([Paragraph("", item_style)] * (max_cells - len(cells)))
405
+
406
+ col_width = (A4[1] * 2 - 72) / num_columns
407
+ table_data = list(zip(*column_cells))
408
+ table = Table(table_data, colWidths=[col_width] * num_columns, hAlign='CENTER')
409
+ table.setStyle(TableStyle([
410
+ ('VALIGN', (0, 0), (-1, -1), 'TOP'),
411
+ ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
412
+ ('BACKGROUND', (0, 0), (-1, -1), colors.white),
413
+ ('GRID', (0, 0), (-1, -1), 0, colors.white),
414
+ ('LINEAFTER', (0, 0), (num_columns-1, -1), 0.5, colors.grey),
415
+ ('LEFTPADDING', (0, 0), (-1, -1), 2),
416
+ ('RIGHTPADDING', (0, 0), (-1, -1), 2),
417
+ ('TOPPADDING', (0, 0), (-1, -1), 1),
418
+ ('BOTTOMPADDING', (0, 0), (-1, -1), 1),
419
+ ]))
420
+
421
+ story.append(table)
422
+ doc.build(story)
423
+ buffer.seek(0)
424
+ return buffer.getvalue()
425
+
426
+ def pdf_to_image(pdf_bytes):
427
+ try:
428
+ doc = fitz.open(stream=pdf_bytes, filetype="pdf")
429
+ images = []
430
+ for page in doc:
431
+ pix = page.get_pixmap(matrix=fitz.Matrix(2.0, 2.0))
432
+ img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
433
+ images.append(img)
434
+ doc.close()
435
+ return images
436
+ except Exception as e:
437
+ st.error(f"Failed to render PDF preview: {e}")
438
+ return None
439
+
440
+ if 'markdown_content' not in st.session_state:
441
+ st.session_state.markdown_content = default_markdown
442
+
443
+ with st.spinner("Generating PDF..."):
444
+ pdf_bytes = create_main_pdf(st.session_state.markdown_content, base_font_size, auto_size, show_subitems, plain_text_mode)
445
+
446
+ with st.container():
447
+ pdf_images = pdf_to_image(pdf_bytes)
448
+ if pdf_images:
449
+ for i, img in enumerate(pdf_images):
450
+ st.image(img, caption=f"Multi-Column Spread", use_container_width=True)
451
+ else:
452
+ st.info("Download the PDF to view it locally.")
453
+
454
+ st.download_button(
455
+ label="Download PDF",
456
+ data=pdf_bytes,
457
+ file_name="deities_guide_multi_column.pdf",
458
+ mime="application/pdf"
459
+ )
460
+
461
+ edited_markdown = st.text_area(
462
+ "Modify the markdown content below:",
463
+ value=st.session_state.markdown_content,
464
+ height=300
465
+ )
466
+
467
+ if st.button("Update PDF"):
468
+ st.session_state.markdown_content = edited_markdown
469
+ st.rerun()
470
+
471
+ st.download_button(
472
+ label="Save Markdown",
473
+ data=st.session_state.markdown_content,
474
+ file_name="deities_guide.md",
475
+ mime="text/markdown"
476
+ )