reab5555 commited on
Commit
991636c
·
verified ·
1 Parent(s): 62a24bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -29,8 +29,17 @@ def transcribe(video_file, transcribe_to_text, transcribe_to_srt, language):
29
  )
30
 
31
  # Handle the video file input
 
 
 
 
32
  video_path = video_file.name if hasattr(video_file, 'name') else video_file
33
- video = VideoFileClip(video_path)
 
 
 
 
 
34
  audio = video.audio
35
  duration = video.duration
36
  n_chunks = math.ceil(duration / 30)
@@ -50,11 +59,16 @@ def transcribe(video_file, transcribe_to_text, transcribe_to_srt, language):
50
  if transcribe_to_srt:
51
  for chunk in result["chunks"]:
52
  start_time, end_time = chunk["timestamp"]
53
- transcription_srt.append({
54
- "start": start_time + i * 30,
55
- "end": end_time + i * 30,
56
- "text": chunk["text"]
57
- })
 
 
 
 
 
58
  os.remove(temp_file_path)
59
  yield f"Progress: {int(((i + 1) / n_chunks) * 100)}%", None
60
 
 
29
  )
30
 
31
  # Handle the video file input
32
+ if video_file is None:
33
+ yield "Error: No video file provided.", None
34
+ return
35
+
36
  video_path = video_file.name if hasattr(video_file, 'name') else video_file
37
+ try:
38
+ video = VideoFileClip(video_path)
39
+ except Exception as e:
40
+ yield f"Error processing video file: {str(e)}", None
41
+ return
42
+
43
  audio = video.audio
44
  duration = video.duration
45
  n_chunks = math.ceil(duration / 30)
 
59
  if transcribe_to_srt:
60
  for chunk in result["chunks"]:
61
  start_time, end_time = chunk["timestamp"]
62
+ # Handle potential None values
63
+ if start_time is not None and end_time is not None:
64
+ transcription_srt.append({
65
+ "start": start_time + i * 30,
66
+ "end": end_time + i * 30,
67
+ "text": chunk["text"]
68
+ })
69
+ else:
70
+ # Log or handle the case where timestamps are None
71
+ print(f"Warning: Invalid timestamp for chunk: {chunk}")
72
  os.remove(temp_file_path)
73
  yield f"Progress: {int(((i + 1) / n_chunks) * 100)}%", None
74