JSenkCC commited on
Commit
27378a4
·
verified ·
1 Parent(s): c01e114

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -19
app.py CHANGED
@@ -470,35 +470,49 @@ def generate_documentation_page():
470
 
471
  # Define paths for PDF and Markdown files
472
  user_folder = os.path.join("user_projects", st.session_state.username)
 
 
473
  pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
474
  markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
475
 
476
  # Button to generate PDF
477
  if st.button("Generate PDF"):
478
- generate_pdf(documentation, pdf_path)
479
- st.success(f"PDF file generated successfully: {pdf_path}")
 
 
 
480
 
481
  # Button to generate Markdown file
482
  if st.button("Generate Markdown File"):
483
- generate_markdown_file(documentation, markdown_path)
484
- st.success(f"Markdown file generated successfully: {markdown_path}")
 
 
 
485
 
486
  # Provide download buttons
487
- with open(pdf_path, "rb") as pdf_file:
488
- st.download_button(
489
- label="Download PDF",
490
- data=pdf_file.read(),
491
- file_name=f"{st.session_state.current_project}_Documentation.pdf",
492
- mime="application/pdf",
493
- )
494
-
495
- with open(markdown_path, "rb") as markdown_file:
496
- st.download_button(
497
- label="Download Markdown File",
498
- data=markdown_file.read(),
499
- file_name=f"{st.session_state.current_project}_Documentation.md",
500
- mime="text/markdown",
501
- )
 
 
 
 
 
 
502
 
503
 
504
  # Helper function to generate PDF
 
470
 
471
  # Define paths for PDF and Markdown files
472
  user_folder = os.path.join("user_projects", st.session_state.username)
473
+ os.makedirs(user_folder, exist_ok=True) # Ensure the user folder exists
474
+
475
  pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
476
  markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
477
 
478
  # Button to generate PDF
479
  if st.button("Generate PDF"):
480
+ try:
481
+ generate_pdf(documentation, pdf_path)
482
+ st.success(f"PDF file generated successfully: {pdf_path}")
483
+ except Exception as e:
484
+ st.error(f"Failed to generate PDF: {e}")
485
 
486
  # Button to generate Markdown file
487
  if st.button("Generate Markdown File"):
488
+ try:
489
+ generate_markdown_file(documentation, markdown_path)
490
+ st.success(f"Markdown file generated successfully: {markdown_path}")
491
+ except Exception as e:
492
+ st.error(f"Failed to generate Markdown file: {e}")
493
 
494
  # Provide download buttons
495
+ try:
496
+ with open(pdf_path, "rb") as pdf_file:
497
+ st.download_button(
498
+ label="Download PDF",
499
+ data=pdf_file.read(),
500
+ file_name=f"{st.session_state.current_project}_Documentation.pdf",
501
+ mime="application/pdf",
502
+ )
503
+ except FileNotFoundError:
504
+ st.error("PDF file not found. Please regenerate it.")
505
+
506
+ try:
507
+ with open(markdown_path, "rb") as markdown_file:
508
+ st.download_button(
509
+ label="Download Markdown File",
510
+ data=markdown_file.read(),
511
+ file_name=f"{st.session_state.current_project}_Documentation.md",
512
+ mime="text/markdown",
513
+ )
514
+ except FileNotFoundError:
515
+ st.error("Markdown file not found. Please regenerate it.")
516
 
517
 
518
  # Helper function to generate PDF