awacke1 commited on
Commit
099c24d
ยท
verified ยท
1 Parent(s): e09f4c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py CHANGED
@@ -112,6 +112,37 @@ def render_emoji_as_svg(emoji_char, size_pt):
112
  return drawing
113
  except Exception as e: print(f"Could not render emoji {emoji_char} as SVG: {e}"); return None
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  # --- UI & File Handling ---
116
  FILE_ICONS = defaultdict(lambda: 'โ“', {
117
  '.md': '๐Ÿ“œ', '.txt': '๐Ÿ“„', '.py': '๐Ÿ', '.js': 'โšก', '.html': '๐ŸŒ', '.css': '๐ŸŽจ', '.json': '๐Ÿ”ฎ',
@@ -178,6 +209,26 @@ def update_staging_and_manuscript(files, current_manuscript):
178
  return text_gallery, image_gallery, pdf_gallery, updated_manuscript
179
 
180
  # --- Main PDF Generation Logic (heavily adapted from before) ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  def markdown_to_story(markdown_text, font_name, font_sizes, use_svg_engine):
182
  styles = getSampleStyleSheet()
183
  font_size_body, font_size_h1, font_size_h2, font_size_h3 = font_sizes
 
112
  return drawing
113
  except Exception as e: print(f"Could not render emoji {emoji_char} as SVG: {e}"); return None
114
 
115
+ # --- AI Content Generation (Simulation) ---
116
+ def generate_ai_content_api(prompt):
117
+ """
118
+ Simulates a call to an LLM to generate markdown content.
119
+ """
120
+ if not prompt:
121
+ return "# The Golem awaits your command!\n\nPlease enter a prompt in the box above and click '๐Ÿง  Animate Golem!' to get started. I can help you write reports, stories, poems, and more! โœจ"
122
+
123
+ import time
124
+ time.sleep(1.5)
125
+
126
+ sample_story = f"""
127
+ # The Quest for the Sunstone โ˜€๏ธ
128
+
129
+ Long ago, in the mystical land of Aerthos, a creeping shadow began to fall across the valleys. The once-vibrant flowers ๐ŸŒธ drooped, and the rivers ran slow. The elders knew the cause: the light of the Sunstone, hidden deep within Mount Cinder, was fading.
130
+
131
+ ## The Prophecy ๐Ÿ“œ
132
+
133
+ An ancient prophecy spoke of a hero who would rekindle the stone. It read:
134
+ > When darkness drapes the verdant ground,
135
+ > A soul of courage shall be found.
136
+ > Through trials of fire ๐Ÿ”ฅ, wit, and might,
137
+ > They'll bring once more the sacred light.
138
+
139
+ ## The Chosen One ๐Ÿฆธโ€โ™€๏ธ
140
+
141
+ A young woman named Elara, known for her kindness and bravery, was chosen. She accepted the quest, her only companions a loyal wolf ๐Ÿบ and a map gifted by the village shaman.
142
+ """
143
+ return f"# Golem's Vision for: '{prompt}'\n\n{sample_story}"
144
+
145
+
146
  # --- UI & File Handling ---
147
  FILE_ICONS = defaultdict(lambda: 'โ“', {
148
  '.md': '๐Ÿ“œ', '.txt': '๐Ÿ“„', '.py': '๐Ÿ', '.js': 'โšก', '.html': '๐ŸŒ', '.css': '๐ŸŽจ', '.json': '๐Ÿ”ฎ',
 
209
  return text_gallery, image_gallery, pdf_gallery, updated_manuscript
210
 
211
  # --- Main PDF Generation Logic (heavily adapted from before) ---
212
+ def _draw_header_footer(canvas, doc, header_text, footer_text, title):
213
+ """Draws the header and footer on each page."""
214
+ canvas.saveState()
215
+ page_num = canvas.getPageNumber()
216
+
217
+ final_footer_text = footer_text.replace("[Page #]", str(page_num)).replace("[Total Pages]", str(doc.page))
218
+ final_header_text = header_text.replace("[Page #]", str(page_num)).replace("[Title]", title)
219
+
220
+ if final_header_text:
221
+ canvas.setFont('Helvetica', 9)
222
+ canvas.setFillColor(colors.grey)
223
+ canvas.drawRightString(doc.width + doc.leftMargin, doc.height + doc.topMargin + 0.25*inch, final_header_text)
224
+
225
+ if final_footer_text:
226
+ canvas.setFont('Helvetica', 9)
227
+ canvas.setFillColor(colors.grey)
228
+ canvas.drawString(doc.leftMargin, doc.bottomMargin - 0.25*inch, final_footer_text)
229
+
230
+ canvas.restoreState()
231
+
232
  def markdown_to_story(markdown_text, font_name, font_sizes, use_svg_engine):
233
  styles = getSampleStyleSheet()
234
  font_size_body, font_size_h1, font_size_h2, font_size_h3 = font_sizes