Update app.py
Browse files
app.py
CHANGED
@@ -401,18 +401,19 @@ def generate_documentation_page():
|
|
401 |
|
402 |
if os.path.exists(project_folder):
|
403 |
try:
|
404 |
-
#
|
405 |
-
|
406 |
-
|
407 |
-
# Read file contents
|
408 |
-
file_contents = read_files(file_paths)
|
409 |
-
|
410 |
-
# Generate documentation using Gemini
|
411 |
-
documentation = generate_detailed_documentation(file_contents, functionality)
|
412 |
|
413 |
# Display the final documentation
|
414 |
st.success("Documentation generated successfully!")
|
415 |
-
st.text_area("Generated Documentation",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
416 |
except Exception as e:
|
417 |
st.error(f"An error occurred: {e}")
|
418 |
else:
|
@@ -420,6 +421,55 @@ def generate_documentation_page():
|
|
420 |
else:
|
421 |
st.error("Please enter the functionality to analyze.")
|
422 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
423 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
424 |
|
425 |
|
|
|
401 |
|
402 |
if os.path.exists(project_folder):
|
403 |
try:
|
404 |
+
# Call Gemini to identify required functions
|
405 |
+
gemini_result = identify_required_functions(project_folder, functionality)
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
407 |
# Display the final documentation
|
408 |
st.success("Documentation generated successfully!")
|
409 |
+
st.text_area("Generated Documentation", gemini_result, height=600)
|
410 |
+
|
411 |
+
# Buttons to generate PDF and Markdown files
|
412 |
+
if st.button("Generate PDF"):
|
413 |
+
generate_pdf(gemini_result)
|
414 |
+
if st.button("Generate Markdown File"):
|
415 |
+
generate_markdown_file(gemini_result)
|
416 |
+
|
417 |
except Exception as e:
|
418 |
st.error(f"An error occurred: {e}")
|
419 |
else:
|
|
|
421 |
else:
|
422 |
st.error("Please enter the functionality to analyze.")
|
423 |
|
424 |
+
|
425 |
+
# Helper function to generate PDF
|
426 |
+
def generate_pdf(documentation):
|
427 |
+
pdf = FPDF()
|
428 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
429 |
+
pdf.add_page()
|
430 |
+
pdf.set_font("Arial", size=12)
|
431 |
+
|
432 |
+
# Add headers and content
|
433 |
+
for line in documentation.splitlines():
|
434 |
+
if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
435 |
+
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
436 |
+
pdf.set_font("Arial", style="B", size=14)
|
437 |
+
elif line.startswith("*") or line.startswith("- **Function**"):
|
438 |
+
pdf.set_font("Arial", style="B", size=12)
|
439 |
+
else:
|
440 |
+
pdf.set_font("Arial", size=12)
|
441 |
+
pdf.multi_cell(0, 10, line)
|
442 |
+
|
443 |
+
# Save and download the PDF
|
444 |
+
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
445 |
+
pdf.output(pdf_file.name)
|
446 |
+
st.download_button(
|
447 |
+
label="Download PDF",
|
448 |
+
data=open(pdf_file.name, "rb").read(),
|
449 |
+
file_name="documentation.pdf",
|
450 |
+
mime="application/pdf",
|
451 |
+
)
|
452 |
+
os.unlink(pdf_file.name)
|
453 |
+
|
454 |
+
# Helper function to generate Markdown file
|
455 |
+
def generate_markdown_file(documentation):
|
456 |
+
# Format the documentation
|
457 |
+
formatted_documentation = documentation.replace("**", "**").replace(":", ":\n")
|
458 |
+
|
459 |
+
# Save as a temporary Markdown file
|
460 |
+
markdown_file = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
461 |
+
with open(markdown_file.name, "w") as f:
|
462 |
+
f.write(formatted_documentation)
|
463 |
+
|
464 |
+
# Download the Markdown file
|
465 |
+
st.download_button(
|
466 |
+
label="Download Markdown File",
|
467 |
+
data=open(markdown_file.name, "rb").read(),
|
468 |
+
file_name="documentation.md",
|
469 |
+
mime="text/markdown",
|
470 |
+
)
|
471 |
+
os.unlink(markdown_file.name)
|
472 |
+
|
473 |
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
474 |
|
475 |
|