File size: 1,973 Bytes
e369f76 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import json
import numpy as np
import random
import os
import zipfile
def export_json(data, filename):
with open(filename, 'w') as f:
json.dump(data, f, indent=4)
print(f"Data exported to {filename}")
def seed_everything(seed):
random.seed(seed)
np.random.seed(seed)
print(f"Random seeds set to {seed}")
def zip_project(output_name="rft_simulation_engine.zip"):
files_to_zip = [
'agent.py',
'simulation.py',
'visualization.py',
'app.py',
'utils.py',
'requirements.txt',
'README.md',
'test_runner.py',
'final_agent_states.json',
'phi_plot.png',
'tau_plot.png',
'fitness_plot.png',
'coherence_plot.png',
'stability_plot.png'
]
with zipfile.ZipFile(output_name, 'w') as zf:
for file in files_to_zip:
if os.path.exists(file):
zf.write(file)
print(f"Added {file} to {output_name}")
else:
print(f"Warning: {file} not found, skipping.")
print(f"Successfully created {output_name} containing all specified files.")
def zip_huggingface_repo(output_name='rft_hf_repo.zip'):
"""Creates a zip archive containing only the core project files for Hugging Face deployment."""
files_to_include = [
'agent.py',
'simulation.py',
'visualization.py',
'app.py',
'utils.py',
'requirements.txt',
'README.md'
]
with zipfile.ZipFile(output_name, 'w') as zf:
for file in files_to_include:
if os.path.exists(file):
zf.write(file)
print(f"Added {file} to {output_name}")
else:
print(f"Warning: {file} not found, skipping for Hugging Face repo zip.")
print(f"Successfully created Hugging Face repository zip: {output_name}")
print("utils.py updated successfully with new zip_huggingface_repo function.")
|