Update app.py
Browse files
app.py
CHANGED
@@ -446,13 +446,6 @@ def generate_documentation_page():
|
|
446 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
447 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|
448 |
|
449 |
-
# Clear previously generated documentation files when starting a new analysis
|
450 |
-
if st.session_state.get("new_analysis_started", False):
|
451 |
-
st.session_state.pop("pdf_generated", None)
|
452 |
-
st.session_state.pop("markdown_generated", None)
|
453 |
-
st.session_state.pop("generated_documentation", None)
|
454 |
-
st.session_state.new_analysis_started = False
|
455 |
-
|
456 |
# Prompt user for functionality description
|
457 |
functionality = st.text_area(
|
458 |
"Describe the functionality",
|
@@ -462,36 +455,35 @@ def generate_documentation_page():
|
|
462 |
# Button to start analyzing functionality
|
463 |
if st.button("Analyze"):
|
464 |
if functionality.strip():
|
465 |
-
st.
|
466 |
-
st.write("Analyzing project files... Please wait.")
|
467 |
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
|
477 |
-
|
478 |
-
|
479 |
|
480 |
-
|
481 |
-
|
482 |
|
483 |
-
|
484 |
-
|
485 |
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
|
|
|
|
491 |
else:
|
492 |
-
st.error("
|
493 |
-
else:
|
494 |
-
st.error("Please enter the functionality to analyze.")
|
495 |
|
496 |
# Add export/download buttons if documentation is available
|
497 |
if "generated_documentation" in st.session_state and st.session_state.generated_documentation:
|
@@ -504,53 +496,50 @@ def generate_documentation_page():
|
|
504 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
505 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
506 |
|
507 |
-
|
|
|
|
|
508 |
|
509 |
-
#
|
510 |
-
|
511 |
-
if
|
512 |
-
if st.button("Generate PDF"):
|
513 |
-
try:
|
514 |
-
generate_pdf(documentation, pdf_path)
|
515 |
-
st.session_state.pdf_generated = True
|
516 |
-
st.success("PDF Available in the 'Saved Documentation' Page")
|
517 |
-
st.rerun()
|
518 |
-
except Exception as e:
|
519 |
-
st.error(f"Failed to generate PDF: {e}")
|
520 |
-
else:
|
521 |
try:
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
st.
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
except Exception as e:
|
542 |
-
st.error(f"Failed to generate Markdown file: {e}")
|
543 |
-
else:
|
544 |
try:
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
|
555 |
|
556 |
|
@@ -613,11 +602,12 @@ def generate_markdown_file(documentation, output_path):
|
|
613 |
|
614 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
615 |
def saved_documentation_page():
|
|
|
616 |
st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
|
617 |
st.sidebar.title(f"Project: {st.session_state.current_project}")
|
618 |
if st.sidebar.button("Back to Project"):
|
619 |
st.session_state.page = "project_view"
|
620 |
-
st.
|
621 |
if st.sidebar.button("Log Out"):
|
622 |
logout_user()
|
623 |
st.rerun()
|
@@ -630,25 +620,31 @@ def saved_documentation_page():
|
|
630 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
631 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
632 |
|
633 |
-
# Check if files exist
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
652 |
|
653 |
|
654 |
def project_view_page():
|
|
|
446 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
447 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|
448 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
# Prompt user for functionality description
|
450 |
functionality = st.text_area(
|
451 |
"Describe the functionality",
|
|
|
455 |
# Button to start analyzing functionality
|
456 |
if st.button("Analyze"):
|
457 |
if functionality.strip():
|
458 |
+
with st.spinner("Analyzing project files... Please wait."):
|
|
|
459 |
|
460 |
+
# Get the path of the current project
|
461 |
+
user_folder = os.path.join("user_projects", st.session_state.username)
|
462 |
+
project_folder = os.path.join(user_folder, st.session_state.current_project)
|
463 |
|
464 |
+
if os.path.exists(project_folder):
|
465 |
+
try:
|
466 |
+
# Gather all file paths in the project directory
|
467 |
+
file_paths = read_project_files(project_folder)
|
468 |
|
469 |
+
# Read file contents
|
470 |
+
file_contents = read_files(file_paths)
|
471 |
|
472 |
+
# Generate documentation using Gemini
|
473 |
+
documentation = generate_detailed_documentation(file_contents, functionality)
|
474 |
|
475 |
+
# Save the documentation in session state for exporting and viewing
|
476 |
+
st.session_state.generated_documentation = documentation
|
477 |
|
478 |
+
# Display the final documentation
|
479 |
+
st.success("Documentation generated successfully!")
|
480 |
+
st.text_area("Generated Documentation", documentation, height=600)
|
481 |
+
except Exception as e:
|
482 |
+
st.error(f"An error occurred: {e}")
|
483 |
+
else:
|
484 |
+
st.error("Project folder not found. Ensure the GitHub repository was cloned successfully.")
|
485 |
else:
|
486 |
+
st.error("Please enter the functionality to analyze.")
|
|
|
|
|
487 |
|
488 |
# Add export/download buttons if documentation is available
|
489 |
if "generated_documentation" in st.session_state and st.session_state.generated_documentation:
|
|
|
496 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
497 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
498 |
|
499 |
+
# Show appropriate buttons based on file generation status
|
500 |
+
pdf_generated = os.path.exists(pdf_path)
|
501 |
+
markdown_generated = os.path.exists(markdown_path)
|
502 |
|
503 |
+
# Generate and replace buttons dynamically
|
504 |
+
if not pdf_generated:
|
505 |
+
if st.button("Generate PDF"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
try:
|
507 |
+
generate_pdf(documentation, pdf_path)
|
508 |
+
st.session_state.pdf_generated = True # Set a flag for PDF generation
|
509 |
+
st.rerun() # Trigger a rerun to show the download button
|
510 |
+
except Exception as e:
|
511 |
+
st.error(f"Failed to generate PDF: {e}")
|
512 |
+
else:
|
513 |
+
try:
|
514 |
+
with open(pdf_path, "rb") as pdf_file:
|
515 |
+
st.download_button(
|
516 |
+
label="Download PDF",
|
517 |
+
data=pdf_file.read(),
|
518 |
+
file_name=f"{st.session_state.current_project}_Documentation.pdf",
|
519 |
+
mime="application/pdf",
|
520 |
+
)
|
521 |
+
except FileNotFoundError:
|
522 |
+
st.write("Click 'Generate PDF' to be able to download and store the documentation as a PDF")
|
523 |
+
|
524 |
+
if not markdown_generated:
|
525 |
+
if st.button("Generate Markdown File"):
|
|
|
|
|
|
|
526 |
try:
|
527 |
+
generate_markdown_file(documentation, markdown_path)
|
528 |
+
st.session_state.markdown_generated = True # Set a flag for Markdown generation
|
529 |
+
st.rerun() # Trigger a rerun to show the download button
|
530 |
+
except Exception as e:
|
531 |
+
st.error(f"Failed to generate Markdown file: {e}")
|
532 |
+
else:
|
533 |
+
try:
|
534 |
+
with open(markdown_path, "rb") as markdown_file:
|
535 |
+
st.download_button(
|
536 |
+
label="Download Markdown File",
|
537 |
+
data=markdown_file.read(),
|
538 |
+
file_name=f"{st.session_state.current_project}_Documentation.md",
|
539 |
+
mime="text/markdown",
|
540 |
+
)
|
541 |
+
except FileNotFoundError:
|
542 |
+
st.write("Click 'Generate Markdown File' to be able to download and store the documentation as a markdown file")
|
543 |
|
544 |
|
545 |
|
|
|
602 |
|
603 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
604 |
def saved_documentation_page():
|
605 |
+
# Sidebar with "Back to Project" and "Log Out" buttons
|
606 |
st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
|
607 |
st.sidebar.title(f"Project: {st.session_state.current_project}")
|
608 |
if st.sidebar.button("Back to Project"):
|
609 |
st.session_state.page = "project_view"
|
610 |
+
st.rerun()
|
611 |
if st.sidebar.button("Log Out"):
|
612 |
logout_user()
|
613 |
st.rerun()
|
|
|
620 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
621 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
622 |
|
623 |
+
# Check if files exist
|
624 |
+
pdf_exists = os.path.exists(pdf_path)
|
625 |
+
markdown_exists = os.path.exists(markdown_path)
|
626 |
+
|
627 |
+
# Display available documentation
|
628 |
+
if not pdf_exists and not markdown_exists:
|
629 |
+
st.info("No documentation has been generated yet. Please go to the 'Generate Documentation' page.")
|
630 |
+
else:
|
631 |
+
if pdf_exists:
|
632 |
+
with open(pdf_path, "rb") as pdf_file:
|
633 |
+
st.download_button(
|
634 |
+
label="Download PDF Documentation",
|
635 |
+
data=pdf_file.read(),
|
636 |
+
file_name=f"{st.session_state.current_project}_Documentation.pdf",
|
637 |
+
mime="application/pdf",
|
638 |
+
)
|
639 |
+
|
640 |
+
if markdown_exists:
|
641 |
+
with open(markdown_path, "rb") as markdown_file:
|
642 |
+
st.download_button(
|
643 |
+
label="Download Markdown Documentation",
|
644 |
+
data=markdown_file.read(),
|
645 |
+
file_name=f"{st.session_state.current_project}_Documentation.md",
|
646 |
+
mime="text/markdown",
|
647 |
+
)
|
648 |
|
649 |
|
650 |
def project_view_page():
|