Spaces:
Build error
Build error
Update app.py
Browse files
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': '
|
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 |
-
#
|
200 |
-
|
201 |
-
if
|
202 |
-
updated_manuscript = ""
|
203 |
-
|
204 |
-
|
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 |
-
|
332 |
-
|
333 |
-
|
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()
|