JSenkCC commited on
Commit
ab8bac1
·
verified ·
1 Parent(s): adaac82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -658,9 +658,21 @@ def project_view_page():
658
  # Calculate project metrics
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
  num_files = sum([len(files) for _, _, files in os.walk(project_folder)])
662
- num_lines = sum([sum(1 for _ in open(os.path.join(root, file), 'r', encoding="utf-8"))
663
- for root, _, files in os.walk(project_folder) for file in files if file.endswith(".py")])
 
 
 
 
 
 
 
 
 
 
664
 
665
  # Display metrics side by side
666
  col1, col2 = st.columns(2)
 
658
  # Calculate project metrics
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
+ # Only include text files (e.g., .py, .txt, .json, etc.)
672
+ with open(file_path, 'r', encoding='utf-8') as f:
673
+ num_lines += sum(1 for _ in f)
674
+ except (UnicodeDecodeError, IsADirectoryError):
675
+ continue # Skip binary or non-text files
676
 
677
  # Display metrics side by side
678
  col1, col2 = st.columns(2)