MCPcopy Create free account
hub / github.com/conflow-dev/ConFlow / main

Function main

recompiler.py:46–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 return parser.parse_args()
45
46def main():
47 args = parse_args()
48 model_file = args.model
49
50 if not model_file:
51 print("No model file specified.")
52 return
53
54 if not os.path.isfile(model_file):
55 print(f"The file {model_file} does not exist.")
56 sys.exit(1)
57
58 # Read the source code from the model file
59 with open(model_file, 'r') as f:
60 model_code = f.read()
61
62 # Custom layer name
63 custom_layer = 'MyDense'
64
65 # Parse model source code to AST
66 tree = ast.parse(model_code)
67
68 # Transformer to replace Dense with MyDense
69 class LayerReplacer(ast.NodeTransformer):
70 def visit_Call(self, node):
71 if isinstance(node.func, ast.Name) and node.func.id == 'Dense':
72 node.func.id = custom_layer
73 return self.generic_visit(node)
74
75 transformer = LayerReplacer()
76 modified_tree = transformer.visit(tree)
77
78 # Generate modified source code
79 modified_code = ast.unparse(modified_tree)
80
81 print("Modified Model:\n", modified_code)
82
83 output_file = f'encrypt_{model_file}'
84
85 # Write the modified model code to a new file
86 try:
87 with open(output_file, 'w') as file:
88 file.write(modified_code)
89 file.write("\n\n" + MyDense_complate)
90
91 print(f"File {output_file} has been created with the modified code.")
92 except IOError as e:
93 print(f"Failed to write to file {output_file}: {e}")
94
95if __name__ == "__main__":
96 main()

Callers 1

recompiler.pyFile · 0.85

Calls 2

parse_argsFunction · 0.85
LayerReplacerClass · 0.85

Tested by

no test coverage detected