Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -327,50 +327,53 @@ def save_file_content(content, filename, file_type):
|
|
327 |
def main():
|
328 |
st.title("πβ¨ Super Smart File Handler with Markdown Magic! β¨π")
|
329 |
|
|
|
330 |
show_sidebar_history()
|
331 |
|
|
|
332 |
upload_tab, book_tab = st.tabs(["π€ File Upload", "π Book View"])
|
333 |
|
334 |
with upload_tab:
|
335 |
col1, col2 = st.columns(2)
|
336 |
|
337 |
with col1:
|
338 |
-
|
339 |
"π€ Upload single file",
|
340 |
type=list(FILE_TYPES.keys()),
|
341 |
-
help="Supports: " + ", ".join([f"{v} (.{k})" for k, v in FILE_TYPES.items()])
|
|
|
342 |
)
|
343 |
|
344 |
with col2:
|
345 |
-
|
346 |
"π Upload multiple files",
|
347 |
type=list(FILE_TYPES.keys()),
|
348 |
accept_multiple_files=True,
|
349 |
-
help="Upload multiple files to view as a book"
|
|
|
350 |
)
|
351 |
|
352 |
-
# Process single file upload
|
353 |
-
if
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
|
361 |
-
#
|
362 |
-
if
|
363 |
-
for uploaded_file in
|
364 |
content, file_type = read_file_content(uploaded_file)
|
365 |
if content is not None:
|
366 |
st.session_state.file_data[uploaded_file.name] = content
|
367 |
st.session_state.file_types[uploaded_file.name] = file_type
|
368 |
-
st.success(f"π Loaded {len(
|
369 |
|
370 |
-
#
|
371 |
show_file_history()
|
372 |
|
373 |
-
#
|
374 |
if st.session_state.file_data:
|
375 |
st.subheader("π Your Files")
|
376 |
for filename, content in st.session_state.file_data.items():
|
@@ -393,10 +396,8 @@ if uploaded_file:
|
|
393 |
if save_file_content(content, filename, file_type):
|
394 |
st.success(f"β¨ Saved {filename} successfully!")
|
395 |
|
396 |
-
# π Book Mode - Show all markdown files in book format
|
397 |
with book_tab:
|
398 |
show_book_view()
|
399 |
|
400 |
-
# π Launch the app!
|
401 |
if __name__ == "__main__":
|
402 |
main()
|
|
|
327 |
def main():
|
328 |
st.title("πβ¨ Super Smart File Handler with Markdown Magic! β¨π")
|
329 |
|
330 |
+
# Show markdown history in sidebar
|
331 |
show_sidebar_history()
|
332 |
|
333 |
+
# Add tabs for different upload methods
|
334 |
upload_tab, book_tab = st.tabs(["π€ File Upload", "π Book View"])
|
335 |
|
336 |
with upload_tab:
|
337 |
col1, col2 = st.columns(2)
|
338 |
|
339 |
with col1:
|
340 |
+
single_uploaded_file = st.file_uploader(
|
341 |
"π€ Upload single file",
|
342 |
type=list(FILE_TYPES.keys()),
|
343 |
+
help="Supports: " + ", ".join([f"{v} (.{k})" for k, v in FILE_TYPES.items()]),
|
344 |
+
key="single_uploader"
|
345 |
)
|
346 |
|
347 |
with col2:
|
348 |
+
multiple_uploaded_files = st.file_uploader(
|
349 |
"π Upload multiple files",
|
350 |
type=list(FILE_TYPES.keys()),
|
351 |
accept_multiple_files=True,
|
352 |
+
help="Upload multiple files to view as a book",
|
353 |
+
key="multiple_uploader"
|
354 |
)
|
355 |
|
356 |
+
# Process single file upload
|
357 |
+
if single_uploaded_file:
|
358 |
+
content, file_type = read_file_content(single_uploaded_file)
|
359 |
+
if content is not None:
|
360 |
+
st.session_state.file_data[single_uploaded_file.name] = content
|
361 |
+
st.session_state.file_types[single_uploaded_file.name] = file_type
|
362 |
+
st.success(f"π Loaded {FILE_TYPES.get(file_type, 'π')} file: {single_uploaded_file.name}")
|
|
|
363 |
|
364 |
+
# Process multiple file upload
|
365 |
+
if multiple_uploaded_files:
|
366 |
+
for uploaded_file in multiple_uploaded_files:
|
367 |
content, file_type = read_file_content(uploaded_file)
|
368 |
if content is not None:
|
369 |
st.session_state.file_data[uploaded_file.name] = content
|
370 |
st.session_state.file_types[uploaded_file.name] = file_type
|
371 |
+
st.success(f"π Loaded {len(multiple_uploaded_files)} files")
|
372 |
|
373 |
+
# Show file history
|
374 |
show_file_history()
|
375 |
|
376 |
+
# Show individual files
|
377 |
if st.session_state.file_data:
|
378 |
st.subheader("π Your Files")
|
379 |
for filename, content in st.session_state.file_data.items():
|
|
|
396 |
if save_file_content(content, filename, file_type):
|
397 |
st.success(f"β¨ Saved {filename} successfully!")
|
398 |
|
|
|
399 |
with book_tab:
|
400 |
show_book_view()
|
401 |
|
|
|
402 |
if __name__ == "__main__":
|
403 |
main()
|