Spaces:
Sleeping
Sleeping
| import os | |
| import ast | |
| def get_imports(file_path): | |
| with open(file_path, 'r') as file: | |
| tree = ast.parse(file.read(), filename=file_path) | |
| imports = [] | |
| for node in ast.walk(tree): | |
| if isinstance(node, ast.Import): | |
| for alias in node.names: | |
| imports.append(alias.name) | |
| elif isinstance(node, ast.ImportFrom): | |
| imports.append(node.module) | |
| return imports | |
| def enumerate_imports(file_path, base_dir): | |
| imports = get_imports(file_path) | |
| all_imports = {file_path: imports} | |
| for imp in imports: | |
| imp_path = os.path.join(base_dir, imp.replace('.', '/') + '.py') | |
| if os.path.exists(imp_path): | |
| all_imports.update(enumerate_imports(imp_path, base_dir)) | |
| return all_imports | |
| # Path to the LLModels.py file | |
| base_dir = 'C:\\Users\\serban.tica\\Documents\\tobi_llm_intent_recognition' | |
| llmodels_path = os.path.join(base_dir, 'LLModels.py') | |
| # Enumerate all imports | |
| all_imports = enumerate_imports(llmodels_path, base_dir) | |
| # Print the results | |
| for file, imports in all_imports.items(): | |
| print(f"File: {file}") | |
| for imp in imports: | |
| print(f" Import: {imp}") |