Spaces:
Sleeping
Sleeping
Update pipeline/pipeline.py
Browse files- pipeline/pipeline.py +37 -28
pipeline/pipeline.py
CHANGED
|
@@ -1,9 +1,5 @@
|
|
| 1 |
-
# pipeline.py
|
| 2 |
import asyncio
|
| 3 |
import logging
|
| 4 |
-
from api.server import pending_confirmations # Access the confirmation events
|
| 5 |
-
|
| 6 |
-
# Import your modules
|
| 7 |
import core.script_gen as script_gen
|
| 8 |
import core.story_script as story_script
|
| 9 |
import core.image_generator as image_gen
|
|
@@ -16,35 +12,48 @@ logging.basicConfig(
|
|
| 16 |
format="%(asctime)s [%(levelname)s] %(message)s"
|
| 17 |
)
|
| 18 |
|
| 19 |
-
async def run_pipeline(task: dict):
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
idea = task["idea"]
|
| 22 |
|
| 23 |
logging.info(f"[Pipeline] Starting script generation for task {task_id}")
|
| 24 |
-
script = await script_gen.generate_script(idea)
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
story = await story_script.generate_story(script)
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
logging.info(f"[Pipeline] Generating images for task {task_id}")
|
| 37 |
images = await image_gen.generate_images(story)
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
# logging.info(f"[Pipeline] Generating video for task {task_id}")
|
| 41 |
-
# video = await video_gen.generate_video(images)
|
| 42 |
-
|
| 43 |
-
# logging.info(f"[Pipeline] Generating music/audio for task {task_id}")
|
| 44 |
-
# audio = await music_gen.generate_music(story)
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
#
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import logging
|
|
|
|
|
|
|
|
|
|
| 3 |
import core.script_gen as script_gen
|
| 4 |
import core.story_script as story_script
|
| 5 |
import core.image_generator as image_gen
|
|
|
|
| 12 |
format="%(asctime)s [%(levelname)s] %(message)s"
|
| 13 |
)
|
| 14 |
|
| 15 |
+
async def run_pipeline(task: dict, confirmation_event: asyncio.Event):
|
| 16 |
+
"""
|
| 17 |
+
Executes the full workflow:
|
| 18 |
+
1. Script generation
|
| 19 |
+
2. Wait for user confirmation
|
| 20 |
+
3. Story generation
|
| 21 |
+
4. Image generation
|
| 22 |
+
Video/music/assemble placeholders for now
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
task_id = task["id"]
|
| 26 |
idea = task["idea"]
|
| 27 |
|
| 28 |
logging.info(f"[Pipeline] Starting script generation for task {task_id}")
|
| 29 |
+
script = await script_gen.generate_script(idea)
|
| 30 |
+
task["result"]["script"] = script
|
| 31 |
+
task["status"] = "waiting_for_confirmation"
|
| 32 |
+
task["confirmation_required"] = True
|
| 33 |
+
logging.info(f"[Pipeline] Script ready for task {task_id}, waiting confirmation...")
|
| 34 |
+
|
| 35 |
+
# Wait for user confirmation
|
| 36 |
+
await confirmation_event.wait()
|
| 37 |
+
task["status"] = "confirmed"
|
| 38 |
+
task["confirmation_required"] = False
|
| 39 |
+
logging.info(f"[Pipeline] Task {task_id} confirmed. Continuing pipeline...")
|
| 40 |
+
|
| 41 |
+
# Story generation
|
| 42 |
+
logging.info(f"[Pipeline] Generating story for task {task_id}")
|
| 43 |
story = await story_script.generate_story(script)
|
| 44 |
+
task["result"]["story_script"] = story
|
| 45 |
+
|
| 46 |
+
# Image generation
|
| 47 |
logging.info(f"[Pipeline] Generating images for task {task_id}")
|
| 48 |
images = await image_gen.generate_images(story)
|
| 49 |
+
task["result"]["images"] = images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Placeholder for future stages
|
| 52 |
+
# logging.info(f"[Pipeline] Generating video/music/assembling for task {task_id}")
|
| 53 |
+
# task["result"]["video"] = None
|
| 54 |
+
# task["result"]["music"] = None
|
| 55 |
+
# task["result"]["final_output"] = None
|
| 56 |
|
| 57 |
+
task["status"] = "completed"
|
| 58 |
+
logging.info(f"[Pipeline] Task {task_id} completed. Output: {images}")
|
| 59 |
+
return task["result"]
|