malleswar commited on
Commit
f072d9b
·
verified ·
1 Parent(s): bc35a70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -107,24 +107,30 @@ def process_video(video_file, language="hindi", progress=gr.Progress()):
107
  print(f"Creating SRT at: {srt_path}")
108
  print(f"Total chunks to process: {len(transcription_result['chunks'])}")
109
 
110
- # Use the exact approach from your working code
111
- with open(srt_path, 'w', encoding='utf-8-sig') as f:
112
- if 'chunks' in transcription_result:
113
- for i, chunk in enumerate(transcription_result['chunks'], start=1):
114
- start, end = chunk['timestamp']
115
- text = chunk['text'].strip()
116
-
117
- if text: # Only write if there's actual text
118
  f.write(f"{i}\n")
119
  f.write(f"{format_srt_time(start)} --> {format_srt_time(end)}\n")
120
  f.write(f"{text}\n\n")
121
- else:
122
- # Fallback if no chunks
123
- f.write("1\n")
124
- f.write("00:00:00,000 --> 00:00:10,000\n")
125
- f.write(f"{transcription_result.get('text', '')}\n\n")
126
-
127
- print(f"SRT file created")
 
 
 
 
 
 
128
 
129
  # Verify SRT was created and show preview
130
  if not os.path.exists(srt_path):
 
107
  print(f"Creating SRT at: {srt_path}")
108
  print(f"Total chunks to process: {len(transcription_result['chunks'])}")
109
 
110
+ # Use EXACT approach from your working code - NO modifications
111
+ try:
112
+ with open(srt_path, 'w', encoding='utf-8-sig') as f:
113
+ if 'chunks' in transcription_result:
114
+ for i, chunk in enumerate(transcription_result['chunks'], start=1):
115
+ start, end = chunk['timestamp']
116
+ text = chunk['text'].strip()
117
+
118
  f.write(f"{i}\n")
119
  f.write(f"{format_srt_time(start)} --> {format_srt_time(end)}\n")
120
  f.write(f"{text}\n\n")
121
+ else:
122
+ # Fallback if no chunks
123
+ f.write("1\n")
124
+ f.write("00:00:00,000 --> 00:00:10,000\n")
125
+ f.write(f"{transcription_result.get('text', '')}\n\n")
126
+
127
+ print(f"SRT file created with {len(transcription_result['chunks'])} entries")
128
+
129
+ except Exception as e:
130
+ print(f"Error creating SRT: {e}")
131
+ import traceback
132
+ print(traceback.format_exc())
133
+ raise
134
 
135
  # Verify SRT was created and show preview
136
  if not os.path.exists(srt_path):