Spaces:
Sleeping
Sleeping
File size: 3,025 Bytes
daf9410 ce2e62e f226296 ce2e62e 10e7ad9 ce2e62e 10e7ad9 ce2e62e 813764f 10e7ad9 ce2e62e 10e7ad9 ce2e62e 10e7ad9 ce2e62e 10e7ad9 |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import os
from pathlib import Path
# CACHE PATCH BLOCK: place FIRST in pipeline.py!
HF_CACHE_DIR = Path("/tmp/hf_cache")
HF_CACHE_DIR.mkdir(parents=True, exist_ok=True)
os.environ.update({
"HF_HOME": str(HF_CACHE_DIR),
"HF_HUB_CACHE": str(HF_CACHE_DIR),
"DIFFUSERS_CACHE": str(HF_CACHE_DIR),
"TRANSFORMERS_CACHE": str(HF_CACHE_DIR),
"XDG_CACHE_HOME": str(HF_CACHE_DIR),
"HF_DATASETS_CACHE": str(HF_CACHE_DIR),
"HF_MODULES_CACHE": str(HF_CACHE_DIR),
"TMPDIR": str(HF_CACHE_DIR),
"CACHE_DIR": str(HF_CACHE_DIR),
"TORCH_HOME": str(HF_CACHE_DIR),
"HOME": str(HF_CACHE_DIR)
})
import os.path
if not hasattr(os.path, "expanduser_original"):
os.path.expanduser_original = os.path.expanduser
def safe_expanduser(path):
if (
path.startswith("~") or
path.startswith("/.cache") or
path.startswith("/root/.cache")
):
return str(HF_CACHE_DIR)
return os.path.expanduser_original(path)
os.path.expanduser = safe_expanduser
import asyncio
import logging
import core.script_gen as script_gen
import core.story_script as story_script
import core.image_generator as image_gen
# import core.video_gen as video_gen
# import core.music_gen as music_gen
# import core.assemble as assemble
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s"
)
async def run_pipeline(task: dict, confirmation_event: asyncio.Event):
"""
Executes the full workflow:
1. Script generation
2. Wait for user confirmation
3. Story generation
4. Image generation
Video/music/assemble placeholders for now
"""
task_id = task["id"]
idea = task["idea"]
logging.info(f"[Pipeline] Starting script generation for task {task_id}")
script = await script_gen.generate_script(idea)
task["result"]["script"] = script
task["status"] = "waiting_for_confirmation"
task["confirmation_required"] = True
logging.info(f"[Pipeline] Script ready for task {task_id}, waiting confirmation...")
# Wait for user confirmation
await confirmation_event.wait()
task["status"] = "confirmed"
task["confirmation_required"] = False
logging.info(f"[Pipeline] Task {task_id} confirmed. Continuing pipeline...")
# Story generation
logging.info(f"[Pipeline] Generating story for task {task_id}")
story = await story_script.generate_story(script)
print(story)
task["result"]["story_script"] = story
# Image generation
logging.info(f"[Pipeline] Generating images for task {task_id}")
images = await image_gen.generate_images(story)
task["result"]["images"] = images
# Placeholder for future stages
# logging.info(f"[Pipeline] Generating video/music/assembling for task {task_id}")
# task["result"]["video"] = None
# task["result"]["music"] = None
# task["result"]["final_output"] = None
task["status"] = "completed"
logging.info(f"[Pipeline] Task {task_id} completed. Output: {images}")
return task["result"]
|