XA7 commited on
Commit
51224b6
·
1 Parent(s): fe64b6c
Files changed (1) hide show
  1. 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
- pass
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
- # @log_execution
447
- # def load_narration_from_file(comic_image_path):
448
- # """
449
- # Load narration from the saved narration.txt file for a given comic image.
450
- #
451
- # Args:
452
- # comic_image_path: Path to the comic image
453
- #
454
- # Returns:
455
- # str: Loaded narration text or empty string if not found
456
- # """
457
- # try:
458
- # if not comic_image_path:
459
- # return ""
460
- #
461
- # image_dir = os.path.dirname(comic_image_path)
462
- # narration_path = os.path.join(image_dir, "narration.txt")
463
- #
464
- # if os.path.exists(narration_path):
465
- # with open(narration_path, "r", encoding="utf-8") as f:
466
- # narration = f.read().strip()
467
- # return narration
468
- # except Exception as e:
469
- # print(f"⚠️ Could not load narration: {e}")
470
- #
471
- # return ""
 
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 ""