Spaces:
Runtime error
Runtime error
| import sys | |
| import os | |
| import numpy as np | |
| import cv2 | |
| # Add parent directory to path to import logos | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../') | |
| from logos.baker import BreadBaker | |
| from logos.fractal_engine import LogosFractalEngine, ContextAction | |
| from logos.logos_core import calculate_heat_code, unpack_atom, pack_atom, META_SIZE | |
| def test_bake_cycle(): | |
| print("Initializing Local Test Environment...") | |
| # Create a synthetic test image (Gradient) | |
| img_size = 256 | |
| img = np.zeros((img_size, img_size, 3), dtype=np.uint8) | |
| for y in range(img_size): | |
| for x in range(img_size): | |
| img[y, x] = [x % 255, y % 255, (x+y) % 255] | |
| print(f"Created Test Image: {img_size}x{img_size}") | |
| # Initialize Baker | |
| baker = BreadBaker(variance_threshold=10, min_block_size=8) | |
| # Bake | |
| print("Baking...") | |
| atom_defs = baker.bake(img, prefix_path=[]) | |
| print(f"Generated {len(atom_defs)} atom definitions") | |
| # Pack Atoms (Simulating DSPBridge) | |
| atoms = [] | |
| for i, adef in enumerate(atom_defs): | |
| path = adef['path_bits'] | |
| payload = adef['payload'] | |
| hc = calculate_heat_code(path) | |
| # Dummy meta | |
| full_payload = b'\x00' * META_SIZE + payload | |
| atom = pack_atom(hc, full_payload, gap_id=i) | |
| atoms.append(atom) | |
| print(f"Packed {len(atoms)} atoms") | |
| # Decode (Simulating DSPBridge decode_wave) | |
| print("Decoding...") | |
| engine = LogosFractalEngine(min_bucket_size=1) | |
| for atom in atoms: | |
| hc, pl, _, _ = unpack_atom(atom) | |
| baker_payload = pl[META_SIZE:] | |
| hex_str = f"{hc:08x}" | |
| engine.process_atom(hex_str, baker_payload) | |
| # Render | |
| result = engine.draw_viewport((img_size, img_size)) | |
| # Verify | |
| mean_input = np.mean(img) | |
| mean_output = np.mean(result) | |
| print(f"Input Mean Brightness: {mean_input:.2f}") | |
| print(f"Output Mean Brightness: {mean_output:.2f}") | |
| if mean_output < 1.0: | |
| print("[FAIL] Output is essentially black.") | |
| print("Hypothesis: Nodes start at Heat 0. GF4 Multiply by 0 = 0.") | |
| return False | |
| else: | |
| print("[SUCCESS] Output has content.") | |
| return True | |
| if __name__ == "__main__": | |
| test_bake_cycle() | |