Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -159,7 +159,7 @@ def process_directory(directory, partial_paths=None, file_paths=None):
|
|
| 159 |
|
| 160 |
print(f"Total number of files: {len(files)}")
|
| 161 |
for file_path in files:
|
| 162 |
-
print(f"Paths of files: {
|
| 163 |
file_ext = os.path.splitext(file_path)[1]
|
| 164 |
|
| 165 |
if os.path.getsize(file_path) == 0:
|
|
@@ -203,13 +203,13 @@ def chunk_python_file_content(content, char_limit=1572):
|
|
| 203 |
# Parse the content into an abstract syntax tree (AST)
|
| 204 |
tree = ast.parse(content)
|
| 205 |
|
|
|
|
| 206 |
chunks = []
|
| 207 |
current_chunk = ""
|
| 208 |
current_chunk_size = 0
|
| 209 |
|
| 210 |
# Find all class definitions and top-level functions in the AST
|
| 211 |
class_nodes = [node for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
|
| 212 |
-
function_nodes = [node for node in ast.walk(tree) if isinstance(node, ast.FunctionDef) and not isinstance(node, ast.ClassDef)]
|
| 213 |
|
| 214 |
for class_node in class_nodes:
|
| 215 |
method_nodes = [node for node in class_node.body if isinstance(node, ast.FunctionDef)]
|
|
@@ -253,23 +253,6 @@ def chunk_python_file_content(content, char_limit=1572):
|
|
| 253 |
current_chunk += f"# This is a class method of class: {class_node.name}\n{method_def.strip()}\n"
|
| 254 |
current_chunk_size = method_def_size
|
| 255 |
|
| 256 |
-
for function_node in function_nodes:
|
| 257 |
-
function_def = get_source_segment(source_lines, function_node)
|
| 258 |
-
function_def_size = len(function_def)
|
| 259 |
-
|
| 260 |
-
# Add function definition to the current chunk if it fits
|
| 261 |
-
if current_chunk_size + function_def_size <= char_limit:
|
| 262 |
-
current_chunk += f"{function_def.strip()}\n"
|
| 263 |
-
current_chunk_size += function_def_size
|
| 264 |
-
else:
|
| 265 |
-
# Start a new chunk if the function definition exceeds the limit
|
| 266 |
-
if current_chunk:
|
| 267 |
-
chunks.append(current_chunk.strip())
|
| 268 |
-
current_chunk = ""
|
| 269 |
-
current_chunk_size = 0
|
| 270 |
-
current_chunk += f"{function_def.strip()}\n"
|
| 271 |
-
current_chunk_size = function_def_size
|
| 272 |
-
|
| 273 |
if current_chunk:
|
| 274 |
chunks.append(current_chunk.strip())
|
| 275 |
|
|
|
|
| 159 |
|
| 160 |
print(f"Total number of files: {len(files)}")
|
| 161 |
for file_path in files:
|
| 162 |
+
#print(f"Paths of files: {iles}")
|
| 163 |
file_ext = os.path.splitext(file_path)[1]
|
| 164 |
|
| 165 |
if os.path.getsize(file_path) == 0:
|
|
|
|
| 203 |
# Parse the content into an abstract syntax tree (AST)
|
| 204 |
tree = ast.parse(content)
|
| 205 |
|
| 206 |
+
|
| 207 |
chunks = []
|
| 208 |
current_chunk = ""
|
| 209 |
current_chunk_size = 0
|
| 210 |
|
| 211 |
# Find all class definitions and top-level functions in the AST
|
| 212 |
class_nodes = [node for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
|
|
|
|
| 213 |
|
| 214 |
for class_node in class_nodes:
|
| 215 |
method_nodes = [node for node in class_node.body if isinstance(node, ast.FunctionDef)]
|
|
|
|
| 253 |
current_chunk += f"# This is a class method of class: {class_node.name}\n{method_def.strip()}\n"
|
| 254 |
current_chunk_size = method_def_size
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
if current_chunk:
|
| 257 |
chunks.append(current_chunk.strip())
|
| 258 |
|