naman1102 commited on
Commit
631e1ee
·
1 Parent(s): 27f4250

Update analyzer.py

Browse files
Files changed (1) hide show
  1. analyzer.py +20 -1
analyzer.py CHANGED
@@ -26,14 +26,32 @@ def combine_repo_files_for_llm(repo_dir="repo_files", output_file="combined_repo
26
  Returns the path to the combined file.
27
  """
28
  combined_content = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  for root, _, files in os.walk(repo_dir):
30
  for file in files:
31
  if file.endswith(".py") or file.endswith(".md"):
32
  file_path = os.path.join(root, file)
 
 
 
33
  try:
34
  with open(file_path, "r", encoding="utf-8") as f:
35
  combined_content.append(f"\n# ===== File: {file} =====\n")
36
  combined_content.append(f.read())
 
37
  except Exception as e:
38
  combined_content.append(f"\n# Could not read {file_path}: {e}\n")
39
  with open(output_file, "w", encoding="utf-8") as out_f:
@@ -46,7 +64,8 @@ def analyze_combined_file(output_file="combined_repo.txt"):
46
  """
47
  try:
48
  with open(output_file, "r", encoding="utf-8") as f:
49
- code = f.read()
 
50
  return analyze_code(code)
51
  except Exception as e:
52
  return f"Error analyzing combined file: {e}"
 
26
  Returns the path to the combined file.
27
  """
28
  combined_content = []
29
+ seen_files = set()
30
+ # Priority files
31
+ priority_files = ["app.py", "README.md"]
32
+ for pf in priority_files:
33
+ pf_path = os.path.join(repo_dir, pf)
34
+ if os.path.isfile(pf_path):
35
+ try:
36
+ with open(pf_path, "r", encoding="utf-8") as f:
37
+ combined_content.append(f"\n# ===== File: {pf} =====\n")
38
+ combined_content.append(f.read())
39
+ seen_files.add(os.path.abspath(pf_path))
40
+ except Exception as e:
41
+ combined_content.append(f"\n# Could not read {pf_path}: {e}\n")
42
+ # All other .py and .md files
43
  for root, _, files in os.walk(repo_dir):
44
  for file in files:
45
  if file.endswith(".py") or file.endswith(".md"):
46
  file_path = os.path.join(root, file)
47
+ abs_path = os.path.abspath(file_path)
48
+ if abs_path in seen_files:
49
+ continue
50
  try:
51
  with open(file_path, "r", encoding="utf-8") as f:
52
  combined_content.append(f"\n# ===== File: {file} =====\n")
53
  combined_content.append(f.read())
54
+ seen_files.add(abs_path)
55
  except Exception as e:
56
  combined_content.append(f"\n# Could not read {file_path}: {e}\n")
57
  with open(output_file, "w", encoding="utf-8") as out_f:
 
64
  """
65
  try:
66
  with open(output_file, "r", encoding="utf-8") as f:
67
+ lines = f.readlines()
68
+ code = "".join(lines[:500])
69
  return analyze_code(code)
70
  except Exception as e:
71
  return f"Error analyzing combined file: {e}"