Update app.py
Browse files
app.py
CHANGED
@@ -433,16 +433,11 @@ def process_gemini_output(output):
|
|
433 |
|
434 |
|
435 |
def generate_documentation_page():
|
436 |
-
# Sidebar with "Log Out" and "Back to Project" buttons
|
437 |
st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
|
438 |
st.sidebar.title(f"Project: {st.session_state.current_project}")
|
439 |
if st.sidebar.button("Back to Project"):
|
440 |
st.session_state.page = "project_view"
|
441 |
-
|
442 |
-
if "generated_documentation" in st.session_state:
|
443 |
-
del st.session_state["generated_documentation"]
|
444 |
-
st.rerun()
|
445 |
-
|
446 |
if st.sidebar.button("Log Out"):
|
447 |
logout_user()
|
448 |
st.rerun()
|
@@ -456,82 +451,76 @@ def generate_documentation_page():
|
|
456 |
placeholder="e.g., Explain the function of the file `main.py`",
|
457 |
)
|
458 |
|
459 |
-
#
|
460 |
if st.button("Analyze"):
|
461 |
if functionality.strip():
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
file_paths = read_project_files(project_folder)
|
474 |
-
|
475 |
-
# Read file contents
|
476 |
-
file_contents = read_files(file_paths)
|
477 |
-
|
478 |
-
# Simulate processing time based on lines of code
|
479 |
-
total_lines = sum(len(content.splitlines()) for content in file_contents.values())
|
480 |
-
estimated_time = (total_lines / 2500) * 60 # 1 minute per 2500 lines
|
481 |
-
estimated_time = max(estimated_time, 2) # Ensure at least 2 seconds for the spinner
|
482 |
-
time.sleep(estimated_time)
|
483 |
-
|
484 |
-
# Generate documentation using Gemini
|
485 |
-
documentation = generate_detailed_documentation(file_contents, functionality)
|
486 |
-
|
487 |
-
# Save the documentation in session state for exporting and viewing
|
488 |
-
st.session_state.generated_documentation = documentation
|
489 |
-
|
490 |
-
# Display the final documentation
|
491 |
-
st.success("Documentation generated successfully!")
|
492 |
-
st.text_area("Generated Documentation", documentation, height=600)
|
493 |
-
|
494 |
-
except Exception as e:
|
495 |
-
st.error(f"An error occurred: {e}")
|
496 |
-
else:
|
497 |
-
st.error("Project folder not found. Ensure the GitHub repository was cloned successfully.")
|
498 |
else:
|
499 |
st.error("Please enter the functionality to analyze.")
|
500 |
|
501 |
-
#
|
502 |
-
if
|
503 |
-
|
|
|
|
|
|
|
|
|
504 |
|
505 |
# Define paths for PDF and Markdown files
|
506 |
user_folder = os.path.join("user_projects", st.session_state.username)
|
507 |
-
os.makedirs(user_folder, exist_ok=True)
|
508 |
|
509 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
510 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
511 |
|
512 |
-
#
|
513 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
514 |
if st.button("Generate PDF"):
|
515 |
try:
|
516 |
-
generate_pdf(
|
517 |
-
st.
|
518 |
-
st.
|
|
|
519 |
except Exception as e:
|
520 |
st.error(f"Failed to generate PDF: {e}")
|
521 |
-
else:
|
522 |
-
st.success("PDF has already been generated! Check the 'Saved Documentation' Page.")
|
523 |
|
524 |
-
#
|
525 |
-
if
|
526 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
try:
|
528 |
-
generate_markdown_file(
|
529 |
-
st.
|
530 |
-
st.
|
|
|
531 |
except Exception as e:
|
532 |
st.error(f"Failed to generate Markdown file: {e}")
|
533 |
-
|
534 |
-
st.success("Markdown has already been generated! Check the 'Saved Documentation' Page.")
|
535 |
|
536 |
|
537 |
|
@@ -592,12 +581,11 @@ def generate_markdown_file(documentation, output_path):
|
|
592 |
|
593 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
594 |
def saved_documentation_page():
|
595 |
-
# Sidebar with "Back to Project" and "Log Out" buttons
|
596 |
st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
|
597 |
st.sidebar.title(f"Project: {st.session_state.current_project}")
|
598 |
if st.sidebar.button("Back to Project"):
|
599 |
st.session_state.page = "project_view"
|
600 |
-
st.
|
601 |
if st.sidebar.button("Log Out"):
|
602 |
logout_user()
|
603 |
st.rerun()
|
@@ -610,31 +598,26 @@ def saved_documentation_page():
|
|
610 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
611 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
612 |
|
613 |
-
# Check if files exist
|
614 |
-
|
615 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
616 |
|
617 |
-
# Display available documentation
|
618 |
-
if not pdf_exists and not markdown_exists:
|
619 |
-
st.info("No documentation has been generated yet. Please go to the 'Generate Documentation' page.")
|
620 |
-
else:
|
621 |
-
if pdf_exists:
|
622 |
-
with open(pdf_path, "rb") as pdf_file:
|
623 |
-
st.download_button(
|
624 |
-
label="Download PDF Documentation",
|
625 |
-
data=pdf_file.read(),
|
626 |
-
file_name=f"{st.session_state.current_project}_Documentation.pdf",
|
627 |
-
mime="application/pdf",
|
628 |
-
)
|
629 |
-
|
630 |
-
if markdown_exists:
|
631 |
-
with open(markdown_path, "rb") as markdown_file:
|
632 |
-
st.download_button(
|
633 |
-
label="Download Markdown Documentation",
|
634 |
-
data=markdown_file.read(),
|
635 |
-
file_name=f"{st.session_state.current_project}_Documentation.md",
|
636 |
-
mime="text/markdown",
|
637 |
-
)
|
638 |
|
639 |
def project_view_page():
|
640 |
# Sidebar with logout and return buttons
|
|
|
433 |
|
434 |
|
435 |
def generate_documentation_page():
|
|
|
436 |
st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
|
437 |
st.sidebar.title(f"Project: {st.session_state.current_project}")
|
438 |
if st.sidebar.button("Back to Project"):
|
439 |
st.session_state.page = "project_view"
|
440 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
441 |
if st.sidebar.button("Log Out"):
|
442 |
logout_user()
|
443 |
st.rerun()
|
|
|
451 |
placeholder="e.g., Explain the function of the file `main.py`",
|
452 |
)
|
453 |
|
454 |
+
# Reset generated files when a new analysis starts
|
455 |
if st.button("Analyze"):
|
456 |
if functionality.strip():
|
457 |
+
st.session_state.generated_documentation = None
|
458 |
+
st.session_state.generated_pdf = None
|
459 |
+
st.session_state.generated_markdown = None
|
460 |
+
st.write("Analyzing project files... Please wait.")
|
461 |
+
# Simulate analysis
|
462 |
+
import time
|
463 |
+
time.sleep(3) # Replace this with actual analysis logic
|
464 |
+
|
465 |
+
# Example analysis result
|
466 |
+
st.session_state.generated_documentation = f"Documentation for functionality: {functionality}"
|
467 |
+
st.success("Analysis complete! Documentation is ready.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
468 |
else:
|
469 |
st.error("Please enter the functionality to analyze.")
|
470 |
|
471 |
+
# Display the documentation if available
|
472 |
+
if st.session_state.get("generated_documentation"):
|
473 |
+
st.text_area(
|
474 |
+
"Generated Documentation",
|
475 |
+
st.session_state.generated_documentation,
|
476 |
+
height=400,
|
477 |
+
)
|
478 |
|
479 |
# Define paths for PDF and Markdown files
|
480 |
user_folder = os.path.join("user_projects", st.session_state.username)
|
481 |
+
os.makedirs(user_folder, exist_ok=True)
|
482 |
|
483 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
484 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
485 |
|
486 |
+
# Handle PDF generation and download
|
487 |
+
if st.session_state.get("generated_pdf"):
|
488 |
+
with open(pdf_path, "rb") as pdf_file:
|
489 |
+
st.download_button(
|
490 |
+
label="Download PDF",
|
491 |
+
data=pdf_file.read(),
|
492 |
+
file_name=f"{st.session_state.current_project}_Documentation.pdf",
|
493 |
+
mime="application/pdf",
|
494 |
+
)
|
495 |
+
else:
|
496 |
if st.button("Generate PDF"):
|
497 |
try:
|
498 |
+
generate_pdf(st.session_state.generated_documentation, pdf_path)
|
499 |
+
st.session_state.generated_pdf = True
|
500 |
+
st.info("PDF Available in the 'Saved Documentation' Page")
|
501 |
+
st.experimental_rerun() # Trigger rerun to show the download button
|
502 |
except Exception as e:
|
503 |
st.error(f"Failed to generate PDF: {e}")
|
|
|
|
|
504 |
|
505 |
+
# Handle Markdown generation and download
|
506 |
+
if st.session_state.get("generated_markdown"):
|
507 |
+
with open(markdown_path, "rb") as markdown_file:
|
508 |
+
st.download_button(
|
509 |
+
label="Download Markdown",
|
510 |
+
data=markdown_file.read(),
|
511 |
+
file_name=f"{st.session_state.current_project}_Documentation.md",
|
512 |
+
mime="text/markdown",
|
513 |
+
)
|
514 |
+
else:
|
515 |
+
if st.button("Generate Markdown"):
|
516 |
try:
|
517 |
+
generate_markdown_file(st.session_state.generated_documentation, markdown_path)
|
518 |
+
st.session_state.generated_markdown = True
|
519 |
+
st.info("Markdown Available in the 'Saved Documentation' Page")
|
520 |
+
st.experimental_rerun() # Trigger rerun to show the download button
|
521 |
except Exception as e:
|
522 |
st.error(f"Failed to generate Markdown file: {e}")
|
523 |
+
|
|
|
524 |
|
525 |
|
526 |
|
|
|
581 |
|
582 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
583 |
def saved_documentation_page():
|
|
|
584 |
st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
|
585 |
st.sidebar.title(f"Project: {st.session_state.current_project}")
|
586 |
if st.sidebar.button("Back to Project"):
|
587 |
st.session_state.page = "project_view"
|
588 |
+
st.experimental_rerun()
|
589 |
if st.sidebar.button("Log Out"):
|
590 |
logout_user()
|
591 |
st.rerun()
|
|
|
598 |
pdf_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.pdf")
|
599 |
markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
|
600 |
|
601 |
+
# Check if files exist and display download options
|
602 |
+
if os.path.exists(pdf_path):
|
603 |
+
with open(pdf_path, "rb") as pdf_file:
|
604 |
+
st.download_button(
|
605 |
+
label="Download PDF Documentation",
|
606 |
+
data=pdf_file.read(),
|
607 |
+
file_name=f"{st.session_state.current_project}_Documentation.pdf",
|
608 |
+
mime="application/pdf",
|
609 |
+
)
|
610 |
+
if os.path.exists(markdown_path):
|
611 |
+
with open(markdown_path, "rb") as markdown_file:
|
612 |
+
st.download_button(
|
613 |
+
label="Download Markdown Documentation",
|
614 |
+
data=markdown_file.read(),
|
615 |
+
file_name=f"{st.session_state.current_project}_Documentation.md",
|
616 |
+
mime="text/markdown",
|
617 |
+
)
|
618 |
+
if not os.path.exists(pdf_path) and not os.path.exists(markdown_path):
|
619 |
+
st.info("No documentation has been generated yet.")
|
620 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
621 |
|
622 |
def project_view_page():
|
623 |
# Sidebar with logout and return buttons
|