Update app.py
Browse files
app.py
CHANGED
@@ -380,9 +380,34 @@ def generate_detailed_documentation(file_contents, functionality_description):
|
|
380 |
prompt += f"\nFile: {os.path.basename(file_path)}\n{content}\n"
|
381 |
|
382 |
response = model.generate_content(prompt)
|
383 |
-
return response.text.strip()
|
384 |
-
|
385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
def generate_documentation_page():
|
387 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
388 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|
@@ -473,21 +498,18 @@ def generate_pdf(documentation):
|
|
473 |
pdf = FPDF()
|
474 |
pdf.set_auto_page_break(auto=True, margin=15)
|
475 |
pdf.add_page()
|
476 |
-
pdf.set_font("
|
477 |
|
478 |
-
#
|
479 |
for line in documentation.splitlines():
|
480 |
-
# Remove asterisks and backticks
|
481 |
-
line = line.replace("*", "").replace("`", "'")
|
482 |
-
|
483 |
-
# Detect headers and adjust formatting
|
484 |
if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
485 |
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
486 |
-
pdf.set_font("
|
487 |
-
|
488 |
-
pdf.set_font("
|
489 |
else:
|
490 |
-
pdf.
|
|
|
491 |
|
492 |
# Save and download the PDF
|
493 |
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
@@ -500,35 +522,15 @@ def generate_pdf(documentation):
|
|
500 |
)
|
501 |
os.unlink(pdf_file.name)
|
502 |
|
|
|
503 |
# Helper function to generate Markdown file
|
504 |
def generate_markdown_file(documentation):
|
505 |
-
|
506 |
-
Generate a Markdown file from the documentation with IDE-like formatting.
|
507 |
-
Adjustments:
|
508 |
-
- Removes asterisks (*)
|
509 |
-
- Replaces backticks (`) with single quotes (')
|
510 |
-
- Removes extra spaces between section headers and their content
|
511 |
-
- Removes Markdown-specific delimiters (e.g., ``` at the top and bottom)
|
512 |
-
"""
|
513 |
-
# Process and format content
|
514 |
-
formatted_documentation = ""
|
515 |
-
for line in documentation.splitlines():
|
516 |
-
# Remove asterisks and backticks
|
517 |
-
line = line.replace("*", "").replace("`", "'")
|
518 |
-
|
519 |
-
# Add a newline only for headers for better structure in Markdown
|
520 |
-
if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
521 |
-
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
522 |
-
formatted_documentation += f"## {line.strip()}\n"
|
523 |
-
else:
|
524 |
-
formatted_documentation += f"{line.strip()}\n"
|
525 |
-
|
526 |
-
# Save to a temporary Markdown file
|
527 |
markdown_file = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
528 |
with open(markdown_file.name, "w") as f:
|
529 |
-
f.write(
|
530 |
|
531 |
-
#
|
532 |
st.download_button(
|
533 |
label="Download Markdown File",
|
534 |
data=open(markdown_file.name, "rb").read(),
|
|
|
380 |
prompt += f"\nFile: {os.path.basename(file_path)}\n{content}\n"
|
381 |
|
382 |
response = model.generate_content(prompt)
|
383 |
+
return process_gemini_output(response.text.strip())
|
|
|
384 |
|
385 |
+
def process_gemini_output(output):
|
386 |
+
"""
|
387 |
+
Processes the raw output from Gemini to format it appropriately.
|
388 |
+
|
389 |
+
- Removes ``` at the top and bottom of the output.
|
390 |
+
- Removes all pairs of **.
|
391 |
+
- Replaces ` used as a quote with '.
|
392 |
+
|
393 |
+
Args:
|
394 |
+
output (str): The raw Gemini output.
|
395 |
+
|
396 |
+
Returns:
|
397 |
+
str: The processed and cleaned output.
|
398 |
+
"""
|
399 |
+
# Remove leading and trailing ```
|
400 |
+
if output.startswith("```") and output.endswith("```"):
|
401 |
+
output = output[3:-3].strip()
|
402 |
+
|
403 |
+
# Remove all pairs of **
|
404 |
+
output = output.replace("**", "")
|
405 |
+
|
406 |
+
# Replace ` with '
|
407 |
+
output = output.replace("`", "'")
|
408 |
+
|
409 |
+
return output
|
410 |
+
|
411 |
def generate_documentation_page():
|
412 |
st.subheader(f"Generate Documentation for {st.session_state.current_project}")
|
413 |
st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
|
|
|
498 |
pdf = FPDF()
|
499 |
pdf.set_auto_page_break(auto=True, margin=15)
|
500 |
pdf.add_page()
|
501 |
+
pdf.set_font("Arial", size=12)
|
502 |
|
503 |
+
# Add headers and content
|
504 |
for line in documentation.splitlines():
|
|
|
|
|
|
|
|
|
505 |
if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
506 |
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
507 |
+
pdf.set_font("Arial", style="B", size=14)
|
508 |
+
elif line.startswith("*") or line.startswith("- **Function**"):
|
509 |
+
pdf.set_font("Arial", style="B", size=12)
|
510 |
else:
|
511 |
+
pdf.set_font("Arial", size=12)
|
512 |
+
pdf.multi_cell(0, 10, line)
|
513 |
|
514 |
# Save and download the PDF
|
515 |
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
|
|
522 |
)
|
523 |
os.unlink(pdf_file.name)
|
524 |
|
525 |
+
|
526 |
# Helper function to generate Markdown file
|
527 |
def generate_markdown_file(documentation):
|
528 |
+
# Save as a temporary Markdown file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
529 |
markdown_file = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
530 |
with open(markdown_file.name, "w") as f:
|
531 |
+
f.write(documentation)
|
532 |
|
533 |
+
# Download the Markdown file
|
534 |
st.download_button(
|
535 |
label="Download Markdown File",
|
536 |
data=open(markdown_file.name, "rb").read(),
|