awacke1 commited on
Commit
d8f01e5
ยท
verified ยท
1 Parent(s): e4736b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -145,7 +145,7 @@ A young woman named Elara, known for her kindness and bravery, was chosen. She a
145
 
146
  # --- UI & File Handling ---
147
  FILE_ICONS = defaultdict(lambda: 'โ“', {
148
- '.md': '๏ฟฝ', '.txt': '๐Ÿ“„', '.py': '๐Ÿ', '.js': 'โšก', '.html': '๐ŸŒ', '.css': '๐ŸŽจ', '.json': '๐Ÿ”ฎ',
149
  '.png': '๐Ÿ–ผ๏ธ', '.jpg': '๐Ÿ–ผ๏ธ', '.jpeg': '๐Ÿ–ผ๏ธ', '.gif': '๐Ÿ–ผ๏ธ', '.bmp': '๐Ÿ–ผ๏ธ', '.tiff': '๐Ÿ–ผ๏ธ',
150
  '.pdf': '๐Ÿ“š'
151
  })
@@ -174,6 +174,7 @@ def update_staging_and_manuscript(files, current_manuscript):
174
 
175
  text_gallery, image_gallery, pdf_gallery = [], [], []
176
  text_content_to_add = []
 
177
 
178
  if not files:
179
  return text_gallery, image_gallery, pdf_gallery, current_manuscript
@@ -189,6 +190,7 @@ def update_staging_and_manuscript(files, current_manuscript):
189
  elif ext == '.pdf':
190
  pdf_gallery.append((create_file_icon_image(file_path), file_path.name))
191
  else: # Treat everything else as a text file
 
192
  text_gallery.append((create_file_icon_image(file_path), file_path.name))
193
  try:
194
  with open(file_path, 'r', encoding='utf-8') as f:
@@ -196,15 +198,12 @@ def update_staging_and_manuscript(files, current_manuscript):
196
  except Exception as e:
197
  print(f"Could not read {file_path.name}: {e}")
198
 
199
- # Update manuscript
200
- updated_manuscript = current_manuscript
201
- if "Golem awaits" in updated_manuscript:
202
- updated_manuscript = "" # Clear placeholder if it exists
203
-
204
- if text_content_to_add:
205
- separator = "\n\n---\n\n"
206
- if not updated_manuscript.strip(): separator = "" # Don't add separator if manuscript is empty
207
- updated_manuscript += separator + "\n\n".join(text_content_to_add)
208
 
209
  return text_gallery, image_gallery, pdf_gallery, updated_manuscript
210
 
@@ -328,10 +327,9 @@ def generate_pdfs_api(files, ai_content, layouts, fonts, num_columns, header_tex
328
 
329
  log, all_text = "", []
330
  if ai_content and "Golem awaits" not in ai_content: all_text.append(ai_content)
331
- for p in txt_files:
332
- try: all_text.append(p.read_text(encoding='utf-8'))
333
- except Exception as e: log += f"โš ๏ธ Failed to read {p.name}: {e}\n"
334
- md_content = "\n\n---\n\n".join(all_text)
335
 
336
  generated_pdfs = []
337
  EMOJI_IMAGE_CACHE.clear(); EMOJI_SVG_CACHE.clear()
 
145
 
146
  # --- UI & File Handling ---
147
  FILE_ICONS = defaultdict(lambda: 'โ“', {
148
+ '.md': '๐Ÿ“œ', '.txt': '๐Ÿ“„', '.py': '๐Ÿ', '.js': 'โšก', '.html': '๐ŸŒ', '.css': '๐ŸŽจ', '.json': '๏ฟฝ',
149
  '.png': '๐Ÿ–ผ๏ธ', '.jpg': '๐Ÿ–ผ๏ธ', '.jpeg': '๐Ÿ–ผ๏ธ', '.gif': '๐Ÿ–ผ๏ธ', '.bmp': '๐Ÿ–ผ๏ธ', '.tiff': '๐Ÿ–ผ๏ธ',
150
  '.pdf': '๐Ÿ“š'
151
  })
 
174
 
175
  text_gallery, image_gallery, pdf_gallery = [], [], []
176
  text_content_to_add = []
177
+ has_text_files = False
178
 
179
  if not files:
180
  return text_gallery, image_gallery, pdf_gallery, current_manuscript
 
190
  elif ext == '.pdf':
191
  pdf_gallery.append((create_file_icon_image(file_path), file_path.name))
192
  else: # Treat everything else as a text file
193
+ has_text_files = True
194
  text_gallery.append((create_file_icon_image(file_path), file_path.name))
195
  try:
196
  with open(file_path, 'r', encoding='utf-8') as f:
 
198
  except Exception as e:
199
  print(f"Could not read {file_path.name}: {e}")
200
 
201
+ # If any text-based files were uploaded, their content replaces the manuscript.
202
+ # Otherwise, the manuscript is left untouched.
203
+ if has_text_files:
204
+ updated_manuscript = "\n\n---\n\n".join(text_content_to_add)
205
+ else:
206
+ updated_manuscript = current_manuscript
 
 
 
207
 
208
  return text_gallery, image_gallery, pdf_gallery, updated_manuscript
209
 
 
327
 
328
  log, all_text = "", []
329
  if ai_content and "Golem awaits" not in ai_content: all_text.append(ai_content)
330
+ # The uploaded text content is now part of ai_content, so we don't need to re-read it here.
331
+ # This was part of the original bug.
332
+ md_content = ai_content
 
333
 
334
  generated_pdfs = []
335
  EMOJI_IMAGE_CACHE.clear(); EMOJI_SVG_CACHE.clear()