JSenkCC commited on
Commit
123141f
·
verified ·
1 Parent(s): 8cf437e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -42
app.py CHANGED
@@ -425,12 +425,17 @@ def process_gemini_output(output):
425
 
426
 
427
  def generate_documentation_page():
 
428
  # Sidebar with "Log Out" and "Back to Project" buttons
429
  st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
430
  st.sidebar.title(f"Project: {st.session_state.current_project}")
431
  if st.sidebar.button("Back to Project"):
432
  st.session_state.page = "project_view"
 
 
 
433
  st.rerun()
 
434
  if st.sidebar.button("Log Out"):
435
  st.session_state.authenticated = False
436
  st.session_state.username = None
@@ -463,19 +468,19 @@ def generate_documentation_page():
463
  # Read file contents
464
  file_contents = read_files(file_paths)
465
 
466
- # Calculate the total lines of code
467
- total_lines = sum(content.count("\n") for content in file_contents.values())
468
-
469
- # Estimate time remaining
470
- lines_per_minute = 2500
471
- estimated_time = total_lines / lines_per_minute
472
- st.info(f"Estimated time remaining: {int(estimated_time)} minute(s)")
473
 
474
- # Simulate real-time progress (optional for UX)
475
  progress_bar = st.progress(0)
476
- for i in range(int(estimated_time * 10)): # Simulate 10 steps per minute
477
- time.sleep(6) # Update every 6 seconds
478
- progress_bar.progress((i + 1) / (estimated_time * 10))
 
 
 
479
 
480
  # Generate documentation using Gemini
481
  documentation = generate_detailed_documentation(file_contents, functionality)
@@ -486,6 +491,10 @@ def generate_documentation_page():
486
  # Display the final documentation
487
  st.success("Documentation generated successfully!")
488
  st.text_area("Generated Documentation", documentation, height=600)
 
 
 
 
489
  except Exception as e:
490
  st.error(f"An error occurred: {e}")
491
  else:
@@ -505,49 +514,37 @@ def generate_documentation_page():
505
  markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
506
 
507
  # Show appropriate buttons based on file generation status
508
- pdf_generated = os.path.exists(pdf_path)
509
- markdown_generated = os.path.exists(markdown_path)
510
-
511
- # Generate and replace buttons dynamically
512
- if not pdf_generated:
513
  if st.button("Generate PDF"):
514
  try:
515
  generate_pdf(documentation, pdf_path)
516
- st.session_state.pdf_generated = True # Set a flag for PDF generation
517
- st.rerun() # Trigger a rerun to show the download button
518
  except Exception as e:
519
  st.error(f"Failed to generate PDF: {e}")
520
  else:
521
- try:
522
- with open(pdf_path, "rb") as pdf_file:
523
- st.download_button(
524
- label="Download PDF",
525
- data=pdf_file.read(),
526
- file_name=f"{st.session_state.current_project}_Documentation.pdf",
527
- mime="application/pdf",
528
- )
529
- except FileNotFoundError:
530
- st.write("Click 'Generate PDF' to be able to download and store the documentation as a PDF")
531
-
532
- if not markdown_generated:
533
  if st.button("Generate Markdown File"):
534
  try:
535
  generate_markdown_file(documentation, markdown_path)
536
- st.session_state.markdown_generated = True # Set a flag for Markdown generation
537
- st.rerun() # Trigger a rerun to show the download button
538
  except Exception as e:
539
  st.error(f"Failed to generate Markdown file: {e}")
540
  else:
541
- try:
542
- with open(markdown_path, "rb") as markdown_file:
543
- st.download_button(
544
- label="Download Markdown File",
545
- data=markdown_file.read(),
546
- file_name=f"{st.session_state.current_project}_Documentation.md",
547
- mime="text/markdown",
548
- )
549
- except FileNotFoundError:
550
- st.write("Click 'Generate Markdown File' to be able to download and store the documentation as a markdown file")
551
 
552
 
553
 
 
425
 
426
 
427
  def generate_documentation_page():
428
+ import time
429
  # Sidebar with "Log Out" and "Back to Project" buttons
430
  st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
431
  st.sidebar.title(f"Project: {st.session_state.current_project}")
432
  if st.sidebar.button("Back to Project"):
433
  st.session_state.page = "project_view"
434
+ # Clear the Gemini output when backing out
435
+ if "generated_documentation" in st.session_state:
436
+ del st.session_state["generated_documentation"]
437
  st.rerun()
438
+
439
  if st.sidebar.button("Log Out"):
440
  st.session_state.authenticated = False
441
  st.session_state.username = None
 
468
  # Read file contents
469
  file_contents = read_files(file_paths)
470
 
471
+ # Calculate estimated time based on lines of code
472
+ total_lines = sum(len(content.splitlines()) for content in file_contents.values())
473
+ estimated_time = (total_lines // 2500) * 60 # 1 minute per 2500 lines
474
+ estimated_time = max(estimated_time, 1) # Minimum 1 second for short tasks
 
 
 
475
 
476
+ # Show progress bar
477
  progress_bar = st.progress(0)
478
+ progress_message = st.empty()
479
+ for i in range(101):
480
+ time.sleep(estimated_time / 100) # Simulate the process
481
+ progress_bar.progress(i)
482
+ progress_message.write(f"Estimated time remaining: {int(estimated_time * (100 - i) / 100)} seconds")
483
+ progress_message.empty()
484
 
485
  # Generate documentation using Gemini
486
  documentation = generate_detailed_documentation(file_contents, functionality)
 
491
  # Display the final documentation
492
  st.success("Documentation generated successfully!")
493
  st.text_area("Generated Documentation", documentation, height=600)
494
+
495
+ # Remove the progress bar once the output is ready
496
+ progress_bar.empty()
497
+
498
  except Exception as e:
499
  st.error(f"An error occurred: {e}")
500
  else:
 
514
  markdown_path = os.path.join(user_folder, f"{st.session_state.current_project}_Documentation.md")
515
 
516
  # Show appropriate buttons based on file generation status
517
+ if not os.path.exists(pdf_path):
 
 
 
 
518
  if st.button("Generate PDF"):
519
  try:
520
  generate_pdf(documentation, pdf_path)
521
+ st.success("PDF generated successfully!")
 
522
  except Exception as e:
523
  st.error(f"Failed to generate PDF: {e}")
524
  else:
525
+ with open(pdf_path, "rb") as pdf_file:
526
+ st.download_button(
527
+ label="Download PDF",
528
+ data=pdf_file.read(),
529
+ file_name=f"{st.session_state.current_project}_Documentation.pdf",
530
+ mime="application/pdf",
531
+ )
532
+
533
+ if not os.path.exists(markdown_path):
 
 
 
534
  if st.button("Generate Markdown File"):
535
  try:
536
  generate_markdown_file(documentation, markdown_path)
537
+ st.success("Markdown file generated successfully!")
 
538
  except Exception as e:
539
  st.error(f"Failed to generate Markdown file: {e}")
540
  else:
541
+ with open(markdown_path, "rb") as markdown_file:
542
+ st.download_button(
543
+ label="Download Markdown File",
544
+ data=markdown_file.read(),
545
+ file_name=f"{st.session_state.current_project}_Documentation.md",
546
+ mime="text/markdown",
547
+ )
 
 
 
548
 
549
 
550