Spaces:
tester343
/
Configuration error

File size: 3,876 Bytes
83e35a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
"""
Fix to ensure frames are properly generated for the full story
"""

import os
import sys

sys.path.insert(0, '/workspace')

def diagnose_issue():
    """Diagnose why frames aren't being generated"""
    
    print("πŸ” Diagnosing Frame Generation Issue")
    print("=" * 50)
    
    # Check directories
    dirs_to_check = [
        'frames',
        'frames/final',
        'frames/cropped',
        'output',
        'audio'
    ]
    
    for dir_path in dirs_to_check:
        exists = os.path.exists(dir_path)
        print(f"πŸ“ {dir_path}: {'βœ… Exists' if exists else '❌ Missing'}")
        if exists and dir_path == 'frames/final':
            files = os.listdir(dir_path)
            print(f"   Files: {len(files)}")
    
    # Check subtitles
    if os.path.exists('test1.srt'):
        print("\nβœ… Subtitles file exists")
        with open('test1.srt', 'r') as f:
            content = f.read()
            subtitle_count = content.count('\n\n')
            print(f"   Subtitle segments: ~{subtitle_count}")
    else:
        print("\n❌ No subtitles file found")
    
    print("\nπŸ“‹ The Issue:")
    print("The system is:")
    print("1. βœ… Correctly finding 89 subtitles")
    print("2. βœ… Selecting 48 moments for full story")
    print("3. ❌ BUT then reverting to old 12-moment filtering")
    print("4. ❌ AND frames aren't being extracted")
    
    print("\nπŸ”§ Solution:")
    print("Need to ensure the full story extraction (48 frames) is used")
    print("throughout the entire pipeline.")

def create_fixed_generator():
    """Create a fixed version that properly generates all frames"""
    
    fixed_code = '''
# Fixed version that ensures 48 frames are generated

def generate_full_story_comic(video_path):
    """Generate comic with complete story (48 frames for 12 pages)"""
    
    import os
    import cv2
    import srt
    
    # 1. Read subtitles
    with open('test1.srt', 'r') as f:
        all_subs = list(srt.parse(f.read()))
    
    print(f"πŸ“š Found {len(all_subs)} subtitles")
    
    # 2. Select 48 evenly distributed moments
    target_frames = 48
    if len(all_subs) <= target_frames:
        selected_subs = all_subs
    else:
        step = len(all_subs) / target_frames
        selected_subs = []
        for i in range(target_frames):
            idx = int(i * step)
            selected_subs.append(all_subs[idx])
    
    print(f"βœ… Selected {len(selected_subs)} moments for complete story")
    
    # 3. Extract frames
    os.makedirs('frames/final', exist_ok=True)
    
    cap = cv2.VideoCapture(video_path)
    fps = cap.get(cv2.CAP_PROP_FPS)
    
    for i, sub in enumerate(selected_subs):
        timestamp = (sub.start.total_seconds() + sub.end.total_seconds()) / 2
        frame_num = int(timestamp * fps)
        
        cap.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
        ret, frame = cap.read()
        
        if ret:
            output_path = f'frames/final/frame{i:03d}.png'
            cv2.imwrite(output_path, frame)
            print(f"βœ… Frame {i+1}/{len(selected_subs)}: {sub.content[:30]}...")
    
    cap.release()
    print(f"βœ… Generated {len(selected_subs)} frames for full story")
    
    return len(selected_subs)
'''
    
    with open('/workspace/generate_full_story_frames.py', 'w') as f:
        f.write(fixed_code)
    
    print("\nβœ… Created: generate_full_story_frames.py")
    print("This will properly extract 48 frames for the complete story")

if __name__ == "__main__":
    diagnose_issue()
    create_fixed_generator()
    
    print("\nπŸš€ To fix your comic generation:")
    print("1. The system needs to consistently use 48 frames")
    print("2. Not revert to 12 frames in bubble generation")
    print("3. Actually extract the frames from video")
    print("\nThe issue is the pipeline is inconsistent about frame count.")