JSenkCC commited on
Commit
e9cae80
·
verified ·
1 Parent(s): ceb9cfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -27
app.py CHANGED
@@ -386,12 +386,11 @@ def generate_detailed_documentation(file_contents, functionality_description):
386
  def process_gemini_output(output):
387
  """
388
  Processes the raw output from Gemini to format it appropriately.
389
-
390
  - Removes ``` at the top and bottom of the output.
391
  - Removes all pairs of **.
392
  - Replaces ` used as a quote with '.
393
  - Replaces leading '*' with '-' for lists.
394
- - Makes function names under "Function Documentation" bold.
395
 
396
  Args:
397
  output (str): The raw Gemini output.
@@ -414,19 +413,14 @@ def process_gemini_output(output):
414
  processed_lines = []
415
  for line in lines:
416
  stripped_line = line.strip()
417
-
418
- # Replace '*' at the start of lines with '-'
419
  if stripped_line.startswith("*"):
 
420
  processed_lines.append(line.replace("*", "-", 1))
421
-
422
- # Make function names bold (lines starting with "- '" and ending with "':")
423
- elif stripped_line.startswith("- '") and stripped_line.endswith("':"):
424
- processed_lines.append(f"**{line.strip()}**")
425
  else:
426
  processed_lines.append(line)
427
 
428
  return "\n".join(processed_lines)
429
-
430
  def generate_documentation_page():
431
  st.subheader(f"Generate Documentation for {st.session_state.current_project}")
432
  st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
@@ -514,32 +508,21 @@ def generate_documentation_page():
514
 
515
  # Helper function to generate PDF
516
  def generate_pdf(documentation):
517
- """
518
- Generates a PDF from the processed documentation with a programming IDE font (Courier).
519
-
520
- - Function names are bolded.
521
- - Uses Courier for all text.
522
-
523
- Args:
524
- documentation (str): The formatted documentation.
525
- """
526
  pdf = FPDF()
527
  pdf.set_auto_page_break(auto=True, margin=15)
528
  pdf.add_page()
529
- pdf.set_font("Courier", size=12) # Use Courier for IDE-like font
530
 
531
  # Add headers and content
532
  for line in documentation.splitlines():
533
  if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
534
  line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
535
- pdf.set_font("Courier", style="B", size=14)
536
- pdf.multi_cell(0, 10, line)
537
- elif line.startswith("**- '") and line.endswith("':**"): # Bold function names
538
- pdf.set_font("Courier", style="B", size=12)
539
- pdf.multi_cell(0, 10, line.replace("**", ""))
540
  else:
541
- pdf.set_font("Courier", size=12)
542
- pdf.multi_cell(0, 10, line)
543
 
544
  # Save and download the PDF
545
  pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
@@ -634,4 +617,3 @@ def project_view_page():
634
  if __name__ == "__main__":
635
  main()
636
 
637
-
 
386
  def process_gemini_output(output):
387
  """
388
  Processes the raw output from Gemini to format it appropriately.
389
+
390
  - Removes ``` at the top and bottom of the output.
391
  - Removes all pairs of **.
392
  - Replaces ` used as a quote with '.
393
  - Replaces leading '*' with '-' for lists.
 
394
 
395
  Args:
396
  output (str): The raw Gemini output.
 
413
  processed_lines = []
414
  for line in lines:
415
  stripped_line = line.strip()
 
 
416
  if stripped_line.startswith("*"):
417
+ # Only replace if the '*' is at the start or followed by whitespace
418
  processed_lines.append(line.replace("*", "-", 1))
 
 
 
 
419
  else:
420
  processed_lines.append(line)
421
 
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.")
 
508
 
509
  # Helper function to generate PDF
510
  def generate_pdf(documentation):
 
 
 
 
 
 
 
 
 
511
  pdf = FPDF()
512
  pdf.set_auto_page_break(auto=True, margin=15)
513
  pdf.add_page()
514
+ pdf.set_font("Arial", size=12)
515
 
516
  # Add headers and content
517
  for line in documentation.splitlines():
518
  if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
519
  line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
520
+ pdf.set_font("Arial", style="B", size=14)
521
+ elif line.startswith("*") or line.startswith("- **Function**"):
522
+ pdf.set_font("Arial", style="B", size=12)
 
 
523
  else:
524
+ pdf.set_font("Arial", size=12)
525
+ pdf.multi_cell(0, 10, line)
526
 
527
  # Save and download the PDF
528
  pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
 
617
  if __name__ == "__main__":
618
  main()
619