Download utils.py from DeepSeekOracle/LYGO-Resonance-Engine: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/DeepSeekOracle/LYGO-Resonance-Engine/resolve/main/utils.py
- Command line
-
hf download hf://spaces/DeepSeekOracle/LYGO-Resonance-Engine/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/DeepSeekOracle/LYGO-Resonance-Engine/resolve/main/utils.py
1.37 kB
| #!/usr/bin/env python3 | |
| """ | |
| Utils for LYGO Factory Suite | |
| Shared helpers: logging, safe file handling, error wrapping. | |
| """ | |
| import logging | |
| import soundfile as sf | |
| from pathlib import Path | |
| # Setup global logger | |
| logger = logging.getLogger("LYGO_Factory") | |
| if not logger.handlers: | |
| handler = logging.StreamHandler() | |
| formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') | |
| handler.setFormatter(formatter) | |
| logger.addHandler(handler) | |
| logger.setLevel(logging.INFO) | |
| def safe_sf_write(filepath, data, samplerate): | |
| """Bulletproof soundfile write: forces string path.""" | |
| sf.write(str(filepath), data, samplerate) | |
| def safe_save_json(data, filepath): | |
| """Safely save JSON with UTF-8 encoding.""" | |
| import json | |
| with open(str(filepath), 'w', encoding='utf-8') as f: | |
| json.dump(data, f, indent=2) | |
| def ui_wrapper(fn): | |
| """Decorator to handle errors gracefully in Gradio.""" | |
| def wrapped(*args, **kwargs): | |
| try: | |
| return fn(*args, **kwargs) | |
| except Exception as e: | |
| logger.error(f"UI Error: {str(e)}", exc_info=True) | |
| return f"❌ System Error: {str(e)}", None, None | |
| return wrapped | |
| def cleanup_temp_files(file_list): | |
| """Remove temporary files after use.""" | |
| for f in file_list: | |
| try: | |
| Path(f).unlink() | |
| except: | |
| pass | |