Commit ·
65ab047
1
Parent(s): 77620f6
Fix TTS call (async), add HF Hub cloud upload for art_reels
Browse files- modules/art_reels/router.py +30 -8
modules/art_reels/router.py
CHANGED
|
@@ -173,13 +173,16 @@ async def generate_stick_figure_video(job_id: str, script: str, voice: str):
|
|
| 173 |
|
| 174 |
# Step 1: Generate TTS audio from script
|
| 175 |
logger.info(f"Generating TTS audio for job {job_id}")
|
| 176 |
-
audio_path = os.path.join(temp_dir, "voice.
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
)
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
if not os.path.exists(audio_path):
|
| 185 |
raise Exception("TTS audio generation failed")
|
|
@@ -241,12 +244,31 @@ async def generate_stick_figure_video(job_id: str, script: str, voice: str):
|
|
| 241 |
|
| 242 |
update_job(job_id, "processing", 95)
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
# Cleanup
|
| 245 |
video_composer.cleanup_frames(frame_paths)
|
| 246 |
if os.path.exists(temp_dir):
|
| 247 |
shutil.rmtree(temp_dir)
|
| 248 |
|
| 249 |
-
|
|
|
|
|
|
|
| 250 |
logger.info(f"Stick figure video with TTS ready: {job_id}")
|
| 251 |
|
| 252 |
except Exception as e:
|
|
|
|
| 173 |
|
| 174 |
# Step 1: Generate TTS audio from script
|
| 175 |
logger.info(f"Generating TTS audio for job {job_id}")
|
| 176 |
+
audio_path = os.path.join(temp_dir, "voice.wav")
|
| 177 |
+
|
| 178 |
+
# TTS generate is async and returns (audio_bytes, duration)
|
| 179 |
+
audio_bytes, audio_duration = await tts_client.generate(text=script, voice=voice)
|
| 180 |
+
|
| 181 |
+
# Save audio to file
|
| 182 |
+
with open(audio_path, "wb") as f:
|
| 183 |
+
f.write(audio_bytes)
|
| 184 |
+
|
| 185 |
+
logger.info(f"TTS audio saved: {audio_path}, duration: {audio_duration:.2f}s")
|
| 186 |
|
| 187 |
if not os.path.exists(audio_path):
|
| 188 |
raise Exception("TTS audio generation failed")
|
|
|
|
| 244 |
|
| 245 |
update_job(job_id, "processing", 95)
|
| 246 |
|
| 247 |
+
# Step 7: Upload to HF Hub (if enabled)
|
| 248 |
+
from pathlib import Path
|
| 249 |
+
from modules.shared.services.hf_storage import get_hf_storage
|
| 250 |
+
|
| 251 |
+
hf_storage = get_hf_storage()
|
| 252 |
+
cloud_url = None
|
| 253 |
+
|
| 254 |
+
if hf_storage and hf_storage.enabled:
|
| 255 |
+
logger.info(f"Uploading to HF Hub for job {job_id}")
|
| 256 |
+
cloud_url = hf_storage.upload_video(
|
| 257 |
+
local_path=Path(video_path),
|
| 258 |
+
video_id=job_id,
|
| 259 |
+
folder="art_reels"
|
| 260 |
+
)
|
| 261 |
+
if cloud_url:
|
| 262 |
+
logger.info(f"Uploaded to cloud: {cloud_url}")
|
| 263 |
+
|
| 264 |
# Cleanup
|
| 265 |
video_composer.cleanup_frames(frame_paths)
|
| 266 |
if os.path.exists(temp_dir):
|
| 267 |
shutil.rmtree(temp_dir)
|
| 268 |
|
| 269 |
+
# Set video URL (cloud if available, otherwise local)
|
| 270 |
+
video_url = cloud_url or f"/api/art/video/{job_id}"
|
| 271 |
+
update_job(job_id, "ready", 100, video_url=video_url)
|
| 272 |
logger.info(f"Stick figure video with TTS ready: {job_id}")
|
| 273 |
|
| 274 |
except Exception as e:
|