First
Browse files- utils/story_management.py +34 -27
utils/story_management.py
CHANGED
|
@@ -23,6 +23,13 @@ def log_execution(func):
|
|
| 23 |
end_str = datetime.fromtimestamp(end_time).strftime('%Y-%m-%d %H:%M:%S')
|
| 24 |
duration = end_time - start_time
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return result
|
| 27 |
|
| 28 |
return wrapper
|
|
@@ -224,7 +231,7 @@ def generate_direct_comic(
|
|
| 224 |
error_details = traceback.format_exc()
|
| 225 |
print(f"❌ Error generating story scenes: {e}")
|
| 226 |
print(f"Full error details: {error_details}")
|
| 227 |
-
|
| 228 |
return None, "", f"❌ Error generating story scenes: {str(e)}", ""
|
| 229 |
|
| 230 |
|
|
@@ -443,29 +450,29 @@ def generate_image_narration(image_path, narration_length=3, age_group: str | No
|
|
| 443 |
return ""
|
| 444 |
|
| 445 |
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
|
|
|
| 23 |
end_str = datetime.fromtimestamp(end_time).strftime('%Y-%m-%d %H:%M:%S')
|
| 24 |
duration = end_time - start_time
|
| 25 |
|
| 26 |
+
# Write to file (works in Colab)
|
| 27 |
+
with open('content/logs.txt', 'a') as f:
|
| 28 |
+
f.write(f"{func.__name__}, start: {start_str}, end: {end_str}, duration: {duration:.4f}s\n")
|
| 29 |
+
|
| 30 |
+
# Also print to see output immediately
|
| 31 |
+
print(f"{func.__name__}, start: {start_str}, end: {end_str}, duration: {duration:.4f}s")
|
| 32 |
+
|
| 33 |
return result
|
| 34 |
|
| 35 |
return wrapper
|
|
|
|
| 231 |
error_details = traceback.format_exc()
|
| 232 |
print(f"❌ Error generating story scenes: {e}")
|
| 233 |
print(f"Full error details: {error_details}")
|
| 234 |
+
|
| 235 |
return None, "", f"❌ Error generating story scenes: {str(e)}", ""
|
| 236 |
|
| 237 |
|
|
|
|
| 450 |
return ""
|
| 451 |
|
| 452 |
|
| 453 |
+
@log_execution
|
| 454 |
+
def load_narration_from_file(comic_image_path):
|
| 455 |
+
"""
|
| 456 |
+
Load narration from the saved narration.txt file for a given comic image.
|
| 457 |
+
|
| 458 |
+
Args:
|
| 459 |
+
comic_image_path: Path to the comic image
|
| 460 |
+
|
| 461 |
+
Returns:
|
| 462 |
+
str: Loaded narration text or empty string if not found
|
| 463 |
+
"""
|
| 464 |
+
try:
|
| 465 |
+
if not comic_image_path:
|
| 466 |
+
return ""
|
| 467 |
+
|
| 468 |
+
image_dir = os.path.dirname(comic_image_path)
|
| 469 |
+
narration_path = os.path.join(image_dir, "narration.txt")
|
| 470 |
+
|
| 471 |
+
if os.path.exists(narration_path):
|
| 472 |
+
with open(narration_path, "r", encoding="utf-8") as f:
|
| 473 |
+
narration = f.read().strip()
|
| 474 |
+
return narration
|
| 475 |
+
except Exception as e:
|
| 476 |
+
print(f"⚠️ Could not load narration: {e}")
|
| 477 |
+
|
| 478 |
+
return ""
|