JSenkCC commited on
Commit
215dabc
Β·
verified Β·
1 Parent(s): 40da730

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -43
app.py CHANGED
@@ -638,27 +638,6 @@ def saved_documentation_page():
638
  mime="text/markdown",
639
  )
640
 
641
-
642
-
643
-
644
- def display_tree_structure(folder_path, prefix=""):
645
- """Recursively display the folder structure in a tree-like format."""
646
- try:
647
- items = sorted(os.listdir(folder_path)) # Sort items for consistent display
648
- for i, item in enumerate(items):
649
- item_path = os.path.join(folder_path, item)
650
- is_last_item = i == len(items) - 1
651
- connector = "└── " if is_last_item else "β”œβ”€β”€ "
652
- st.write(f"{prefix}{connector}{item}")
653
-
654
- if os.path.isdir(item_path):
655
- # Recursively display sub-folders with additional indentation
656
- new_prefix = prefix + (" " if is_last_item else "β”‚ ")
657
- display_tree_structure(item_path, new_prefix)
658
- except Exception as e:
659
- st.error(f"Error displaying folder contents: {e}")
660
-
661
-
662
  def project_view_page():
663
  # Sidebar with logout and return buttons
664
  st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
@@ -680,26 +659,16 @@ def project_view_page():
680
  user_folder = os.path.join("user_projects", st.session_state.username)
681
  project_folder = os.path.join(user_folder, st.session_state.current_project)
682
 
683
- # Check for `.git` directory and focus on `origin` folder
684
- git_dir = os.path.join(project_folder, ".git")
685
- origin_dir = os.path.join(git_dir, "refs", "remotes", "origin")
686
 
687
- if not os.path.exists(origin_dir):
688
- st.error("The 'origin' folder does not exist in this project.")
689
- return
690
-
691
- # Count number of files in `origin`
692
- num_files = sum(
693
- [len(files) for _, _, files in os.walk(origin_dir)]
694
- )
695
-
696
- # Count total lines of code in all text files in `origin`
697
  num_lines = 0
698
- for root, _, files in os.walk(origin_dir):
699
  for file in files:
700
  file_path = os.path.join(root, file)
701
  try:
702
- with open(file_path, "r", encoding="utf-8") as f:
703
  num_lines += sum(1 for _ in f)
704
  except (UnicodeDecodeError, IsADirectoryError):
705
  continue
@@ -725,18 +694,28 @@ def project_view_page():
725
  if st.button("Show File Structure"):
726
  st.session_state.show_file_structure = not st.session_state.show_file_structure
727
 
728
- # Display tree structure for `origin`
729
  if "show_file_structure" not in st.session_state:
730
  st.session_state.show_file_structure = False
731
 
732
  if st.session_state.show_file_structure:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733
  st.write("File structure:")
734
- st.write(".") # Root representation
735
- display_tree_structure(origin_dir)
736
-
737
-
738
-
739
-
740
 
741
  if __name__ == "__main__":
742
  main()
 
638
  mime="text/markdown",
639
  )
640
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  def project_view_page():
642
  # Sidebar with logout and return buttons
643
  st.sidebar.image("SimplifAI Logo Long.jpeg", use_container_width=True)
 
659
  user_folder = os.path.join("user_projects", st.session_state.username)
660
  project_folder = os.path.join(user_folder, st.session_state.current_project)
661
 
662
+ # Count number of files
663
+ num_files = sum([len(files) for _, _, files in os.walk(project_folder)])
 
664
 
665
+ # Count total lines of code in all text files
 
 
 
 
 
 
 
 
 
666
  num_lines = 0
667
+ for root, _, files in os.walk(project_folder):
668
  for file in files:
669
  file_path = os.path.join(root, file)
670
  try:
671
+ with open(file_path, 'r', encoding='utf-8') as f:
672
  num_lines += sum(1 for _ in f)
673
  except (UnicodeDecodeError, IsADirectoryError):
674
  continue
 
694
  if st.button("Show File Structure"):
695
  st.session_state.show_file_structure = not st.session_state.show_file_structure
696
 
697
+ # Display file structure if toggled
698
  if "show_file_structure" not in st.session_state:
699
  st.session_state.show_file_structure = False
700
 
701
  if st.session_state.show_file_structure:
702
+ def generate_tree(folder_path, prefix=""):
703
+ """Generates a tree-like structure for the given folder."""
704
+ items = sorted(os.listdir(folder_path))
705
+ tree = ""
706
+ for index, item in enumerate(items):
707
+ item_path = os.path.join(folder_path, item)
708
+ connector = "└── " if index == len(items) - 1 else "β”œβ”€β”€ "
709
+ tree += f"{prefix}{connector}{item}\n"
710
+ if os.path.isdir(item_path):
711
+ subtree_prefix = prefix + (" " if index == len(items) - 1 else "β”‚ ")
712
+ tree += generate_tree(item_path, subtree_prefix)
713
+ return tree
714
+
715
+ # Display the tree structure
716
  st.write("File structure:")
717
+ tree_structure = f".\n{generate_tree(project_folder)}"
718
+ st.text(tree_structure)
 
 
 
 
719
 
720
  if __name__ == "__main__":
721
  main()