JSenkCC commited on
Commit
f2dbe16
·
verified ·
1 Parent(s): 472a94d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -10
app.py CHANGED
@@ -401,19 +401,21 @@ def generate_documentation_page():
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,6 +423,40 @@ def generate_documentation_page():
421
  else:
422
  st.error("Please enter the functionality to analyze.")
423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
 
425
  # Helper function to generate PDF
426
  def generate_pdf(documentation):
 
401
 
402
  if os.path.exists(project_folder):
403
  try:
404
+ # Gather all file paths in the project directory
405
+ file_paths = read_project_files(project_folder)
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
+ # Save the documentation in session state for exporting
414
+ st.session_state.generated_documentation = documentation
 
 
 
415
 
416
+ # Display the final documentation
417
+ st.success("Documentation generated successfully!")
418
+ st.text_area("Generated Documentation", documentation, height=600)
419
  except Exception as e:
420
  st.error(f"An error occurred: {e}")
421
  else:
 
423
  else:
424
  st.error("Please enter the functionality to analyze.")
425
 
426
+ # Add export buttons if documentation is available
427
+ if "generated_documentation" in st.session_state and st.session_state.generated_documentation:
428
+ documentation = st.session_state.generated_documentation
429
+
430
+ # Button to generate PDF
431
+ if st.button("Generate PDF"):
432
+ pdf = fpdf.FPDF()
433
+ pdf.set_auto_page_break(auto=True, margin=15)
434
+ pdf.add_page()
435
+ pdf.set_font("Arial", size=12)
436
+
437
+ # Write documentation to PDF with headers
438
+ for line in documentation.split("\n"):
439
+ if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
440
+ line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
441
+ pdf.set_font("Arial", style="B", size=14)
442
+ elif line.startswith("* **") or line.startswith("- **"):
443
+ pdf.set_font("Arial", style="B", size=12)
444
+ else:
445
+ pdf.set_font("Arial", size=12)
446
+ pdf.multi_cell(0, 10, line)
447
+
448
+ pdf_file_path = os.path.join(user_folder, f"{st.session_state.current_project}_documentation.pdf")
449
+ pdf.output(pdf_file_path)
450
+ st.success(f"PDF file generated at: {pdf_file_path}")
451
+
452
+ # Button to generate Markdown file
453
+ if st.button("Generate Markdown File"):
454
+ markdown_file_path = os.path.join(user_folder, f"{st.session_state.current_project}_documentation.md")
455
+ with open(markdown_file_path, "w") as md_file:
456
+ md_file.write(f"# Documentation for {st.session_state.current_project}\n\n")
457
+ md_file.write(documentation)
458
+ st.success(f"Markdown file generated at: {markdown_file_path}")
459
+
460
 
461
  # Helper function to generate PDF
462
  def generate_pdf(documentation):