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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -356,7 +356,8 @@ def generate_detailed_documentation(file_contents, functionality_description):
356
  '
357
  Functionality Flow:
358
  <Explain the sequence of functions and data flow. If there are multiple initial input points required for the user-defined functionality, show the flow of each one.
359
- An example flow description is: 1. User enters 3. 2. foo(3) is called. 3. foo(3) calls bar() and fubar(3) to return a list filled with... 7. dubar(97) returns 'yes' to the user>
 
360
  '
361
  4. Generate detailed documentation for each function in the codebase:
362
  '
@@ -385,11 +386,12 @@ def generate_detailed_documentation(file_contents, functionality_description):
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
  - Replaces leading '*' with '-' for lists.
 
393
 
394
  Args:
395
  output (str): The raw Gemini output.
@@ -412,14 +414,19 @@ def process_gemini_output(output):
412
  processed_lines = []
413
  for line in lines:
414
  stripped_line = line.strip()
 
 
415
  if stripped_line.startswith("*"):
416
- # Only replace if the '*' is at the start or followed by whitespace
417
  processed_lines.append(line.replace("*", "-", 1))
 
 
 
 
418
  else:
419
  processed_lines.append(line)
420
 
421
  return "\n".join(processed_lines)
422
-
423
  def generate_documentation_page():
424
  st.subheader(f"Generate Documentation for {st.session_state.current_project}")
425
  st.write("Enter the functionality or parts of the project for which you'd like to generate documentation.")
@@ -507,21 +514,32 @@ def generate_documentation_page():
507
 
508
  # Helper function to generate PDF
509
  def generate_pdf(documentation):
 
 
 
 
 
 
 
 
 
510
  pdf = FPDF()
511
  pdf.set_auto_page_break(auto=True, margin=15)
512
  pdf.add_page()
513
- pdf.set_font("Arial", size=12)
514
 
515
  # Add headers and content
516
  for line in documentation.splitlines():
517
  if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
518
  line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
519
- pdf.set_font("Arial", style="B", size=14)
520
- elif line.startswith("*") or line.startswith("- **Function**"):
521
- pdf.set_font("Arial", style="B", size=12)
 
 
522
  else:
523
- pdf.set_font("Arial", size=12)
524
- pdf.multi_cell(0, 10, line)
525
 
526
  # Save and download the PDF
527
  pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
 
356
  '
357
  Functionality Flow:
358
  <Explain the sequence of functions and data flow. If there are multiple initial input points required for the user-defined functionality, show the flow of each one.
359
+ An example flow description is: 1. User enters 3. 2. foo(3) is called. 3. foo(3) calls bar() and fubar(3) to return a list filled with... 7. dubar(97) returns 'yes' to the user
360
+ make sure there is no empty line between 'Functionality Flow:' and what is to be placed in this section>
361
  '
362
  4. Generate detailed documentation for each function in the codebase:
363
  '
 
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
  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
 
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")