Spaces:
Sleeping
Sleeping
| import os | |
| import uuid | |
| import zipfile | |
| import shutil | |
| from beat_generator.riffusion_cpu import generate_audio_loop | |
| from content_generator.hooks import generate_hooks | |
| from content_generator.captions import generate_captions | |
| from content_generator.ideas import generate_content_ideas | |
| from content_generator.scripts import generate_short_scripts | |
| def build_creator_pack(niche, style, bpm, tone, goal): | |
| # Create temp folder | |
| pack_id = uuid.uuid4().hex | |
| folder = f"assets/temp/{pack_id}" | |
| os.makedirs(folder, exist_ok=True) | |
| # ----------------------------------- | |
| # 1. Generate beats & copy correctly | |
| # ----------------------------------- | |
| for i in range(3): | |
| beat_path = generate_audio_loop(style, bpm) | |
| # Copy safely using Python, NOT shell commands | |
| shutil.copy(beat_path, f"{folder}/beat_{i+1}.wav") | |
| # ----------------------------------- | |
| # 2. Generate text files | |
| # ----------------------------------- | |
| with open(f"{folder}/hooks.txt", "w") as f: | |
| f.write("\n".join(generate_hooks(niche, tone))) | |
| with open(f"{folder}/captions.txt", "w") as f: | |
| f.write("\n".join(generate_captions(niche, tone))) | |
| with open(f"{folder}/ideas.txt", "w") as f: | |
| f.write("\n".join(generate_content_ideas(niche, goal))) | |
| with open(f"{folder}/scripts.txt", "w") as f: | |
| f.write("\n".join(generate_short_scripts(niche, tone))) | |
| # ----------------------------------- | |
| # 3. Build ZIP file safely | |
| # ----------------------------------- | |
| zip_path = f"{folder}.zip" | |
| with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf: | |
| for root, _, files in os.walk(folder): | |
| for file in files: | |
| file_path = os.path.join(root, file) | |
| arc_path = os.path.relpath(file_path, folder) | |
| zipf.write(file_path, arc_path) | |
| return zip_path | |