JSenkCC commited on
Commit
b127a31
·
verified ·
1 Parent(s): 7b1b6cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -40
app.py CHANGED
@@ -78,8 +78,8 @@ def main():
78
  project_view_page()
79
  elif st.session_state.page == "generate_documentation":
80
  generate_documentation_page()
81
- elif st.session_state.page == "view_documentation":
82
- view_documentation_page()
83
 
84
  def login_page():
85
  st.subheader("Please Log In or Register to Continue")
@@ -585,44 +585,51 @@ def generate_markdown_file(documentation, output_path):
585
 
586
 
587
  #------------------------------------------------------------------------------------------------------------------------------------------------------------------------
588
- def view_documentation_page():
589
- st.subheader(f"View Documentation for {st.session_state.current_project}")
590
- st.write("This page displays the generated documentation for the selected project.")
591
-
592
- # Check if files are available in session state
593
- pdf_path = st.session_state.get("pdf_file_path")
594
- markdown_path = st.session_state.get("markdown_file_path")
595
-
596
- # Display PDF file if it exists
597
- if pdf_path and os.path.exists(pdf_path):
598
- st.write("### PDF Documentation")
599
- with open(pdf_path, "rb") as pdf_file:
600
- pdf_data = pdf_file.read()
601
- st.download_button(
602
- label="Download PDF",
603
- data=pdf_data,
604
- file_name=os.path.basename(pdf_path),
605
- mime="application/pdf",
606
- )
607
- st.write("View PDF Documentation below:")
608
- st.pdf_viewer(pdf_path)
609
-
610
- # Display Markdown file if it exists
611
- if markdown_path and os.path.exists(markdown_path):
612
- st.write("### Markdown Documentation")
613
- with open(markdown_path, "r") as md_file:
614
- markdown_content = md_file.read()
615
- st.download_button(
616
- label="Download Markdown",
617
- data=markdown_content,
618
- file_name=os.path.basename(markdown_path),
619
- mime="text/markdown",
620
- )
621
- st.markdown(f"```\n{markdown_content}\n```", unsafe_allow_html=True)
622
-
623
- if st.button("Back to Project"):
624
  st.session_state.page = "project_view"
625
  st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
626
 
627
 
628
 
@@ -647,8 +654,8 @@ def project_view_page():
647
  st.session_state.page = "generate_documentation"
648
  st.rerun()
649
 
650
- if st.button("View Documentation"):
651
- st.session_state.page = "view_documentation"
652
  st.rerun()
653
 
654
  # Toggle file structure display (if required)
 
78
  project_view_page()
79
  elif st.session_state.page == "generate_documentation":
80
  generate_documentation_page()
81
+ elif st.session_state.page == "saved_documentation":
82
+ saved_documentation_page()
83
 
84
  def login_page():
85
  st.subheader("Please Log In or Register to Continue")
 
585
 
586
 
587
  #------------------------------------------------------------------------------------------------------------------------------------------------------------------------
588
+ def saved_documentation_page():
589
+ # Sidebar with "Back to Project" and "Log Out" buttons
590
+ st.sidebar.title(f"Project: {st.session_state.current_project}")
591
+ if st.sidebar.button("Back to Project"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  st.session_state.page = "project_view"
593
  st.rerun()
594
+ if st.sidebar.button("Log Out"):
595
+ st.session_state.authenticated = False
596
+ st.session_state.username = None
597
+ st.session_state.page = "login"
598
+ st.rerun()
599
+
600
+ st.subheader(f"Saved Documentation for {st.session_state.current_project}")
601
+ st.write("Below is a list of saved documentation for this project. Click to download.")
602
+
603
+ # Define paths for generated files
604
+ user_folder = os.path.join("user_projects", st.session_state.username)
605
+ pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
606
+ markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
607
+
608
+ # Check if files exist
609
+ pdf_exists = os.path.exists(pdf_path)
610
+ markdown_exists = os.path.exists(markdown_path)
611
+
612
+ # Display available documentation
613
+ if not pdf_exists and not markdown_exists:
614
+ st.info("No documentation has been generated yet. Please go to the 'Generate Documentation' page.")
615
+ else:
616
+ if pdf_exists:
617
+ with open(pdf_path, "rb") as pdf_file:
618
+ st.download_button(
619
+ label="Download PDF Documentation",
620
+ data=pdf_file.read(),
621
+ file_name=f"{st.session_state.current_project}_Documentation.pdf",
622
+ mime="application/pdf",
623
+ )
624
+
625
+ if markdown_exists:
626
+ with open(markdown_path, "rb") as markdown_file:
627
+ st.download_button(
628
+ label="Download Markdown Documentation",
629
+ data=markdown_file.read(),
630
+ file_name=f"{st.session_state.current_project}_Documentation.md",
631
+ mime="text/markdown",
632
+ )
633
 
634
 
635
 
 
654
  st.session_state.page = "generate_documentation"
655
  st.rerun()
656
 
657
+ if st.button("Saved Documentation"):
658
+ st.session_state.page = "saved_documentation"
659
  st.rerun()
660
 
661
  # Toggle file structure display (if required)