Update app.py
Browse files
app.py
CHANGED
@@ -422,6 +422,17 @@ def process_gemini_output(output):
|
|
422 |
return "\n".join(processed_lines)
|
423 |
|
424 |
def generate_documentation_page():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
426 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|
427 |
|
@@ -464,7 +475,7 @@ def generate_documentation_page():
|
|
464 |
else:
|
465 |
st.error("Please enter the functionality to analyze.")
|
466 |
|
467 |
-
# Add export buttons if documentation is available
|
468 |
if "generated_documentation" in st.session_state and st.session_state.generated_documentation:
|
469 |
documentation = st.session_state.generated_documentation
|
470 |
|
@@ -475,44 +486,48 @@ def generate_documentation_page():
|
|
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 |
-
#
|
479 |
-
|
480 |
-
|
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 |
-
#
|
487 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
try:
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
st.
|
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
|
|
|
422 |
return "\n".join(processed_lines)
|
423 |
|
424 |
def generate_documentation_page():
|
425 |
+
# Sidebar with "Log Out" and "Back to Workspace" buttons
|
426 |
+
st.sidebar.title(f"Project: {st.session_state.current_project}")
|
427 |
+
if st.sidebar.button("Back to Workspace"):
|
428 |
+
st.session_state.page = "workspace"
|
429 |
+
st.rerun()
|
430 |
+
if st.sidebar.button("Log Out"):
|
431 |
+
st.session_state.authenticated = False
|
432 |
+
st.session_state.username = None
|
433 |
+
st.session_state.page = "login"
|
434 |
+
st.rerun()
|
435 |
+
|
436 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
437 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|
438 |
|
|
|
475 |
else:
|
476 |
st.error("Please enter the functionality to analyze.")
|
477 |
|
478 |
+
# Add export/download buttons if documentation is available
|
479 |
if "generated_documentation" in st.session_state and st.session_state.generated_documentation:
|
480 |
documentation = st.session_state.generated_documentation
|
481 |
|
|
|
486 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
487 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
488 |
|
489 |
+
# Track whether files have been generated
|
490 |
+
pdf_generated = os.path.exists(pdf_path)
|
491 |
+
markdown_generated = os.path.exists(markdown_path)
|
|
|
|
|
|
|
|
|
492 |
|
493 |
+
# Show appropriate buttons based on file generation status
|
494 |
+
if not pdf_generated:
|
495 |
+
if st.button("Generate PDF"):
|
496 |
+
try:
|
497 |
+
generate_pdf(documentation, pdf_path)
|
498 |
+
st.success(f"PDF file generated successfully: {pdf_path}")
|
499 |
+
except Exception as e:
|
500 |
+
st.error(f"Failed to generate PDF: {e}")
|
501 |
+
else:
|
502 |
+
try:
|
503 |
+
with open(pdf_path, "rb") as pdf_file:
|
504 |
+
st.download_button(
|
505 |
+
label="Download PDF",
|
506 |
+
data=pdf_file.read(),
|
507 |
+
file_name=f"{st.session_state.current_project}_Documentation.pdf",
|
508 |
+
mime="application/pdf",
|
509 |
+
)
|
510 |
+
except FileNotFoundError:
|
511 |
+
st.write("Click 'Generate PDF' to be able to download and store the documentation as a PDF")
|
512 |
+
|
513 |
+
if not markdown_generated:
|
514 |
+
if st.button("Generate Markdown File"):
|
515 |
+
try:
|
516 |
+
generate_markdown_file(documentation, markdown_path)
|
517 |
+
st.success(f"Markdown file generated successfully: {markdown_path}")
|
518 |
+
except Exception as e:
|
519 |
+
st.error(f"Failed to generate Markdown file: {e}")
|
520 |
+
else:
|
521 |
try:
|
522 |
+
with open(markdown_path, "rb") as markdown_file:
|
523 |
+
st.download_button(
|
524 |
+
label="Download Markdown File",
|
525 |
+
data=markdown_file.read(),
|
526 |
+
file_name=f"{st.session_state.current_project}_Documentation.md",
|
527 |
+
mime="text/markdown",
|
528 |
+
)
|
529 |
+
except FileNotFoundError:
|
530 |
+
st.write("Click 'Generate Markdown File' to be able to download and store the documentation as a markdown file")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
|
532 |
|
533 |
# Helper function to generate PDF
|