awacke1 commited on
Commit
2f692d1
Β·
verified Β·
1 Parent(s): 3ce715c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
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
- uploaded_file = st.file_uploader(
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
- uploaded_files = st.file_uploader(
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 uploaded_file:
354
- content, file_type = read_file_content(uploaded_file)
355
- if content is not None:
356
- st.session_state.file_data[uploaded_file.name] = content
357
- st.session_state.file_types[uploaded_file.name] = file_type # This is the correct line
358
- st.success(f"πŸŽ‰ Loaded {FILE_TYPES.get(file_type, 'πŸ“„')} file: {uploaded_file.name}")
359
-
360
 
361
- # πŸ“š Process multiple file upload - Bulk file loading magic!
362
- if uploaded_files:
363
- for uploaded_file in uploaded_files:
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(uploaded_files)} files")
369
 
370
- # πŸ“‹ Show the journey - Display file history
371
  show_file_history()
372
 
373
- # πŸ“‚ File Explorer - Show and manage individual files
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()