Update app.py
Browse files
app.py
CHANGED
|
@@ -80,6 +80,9 @@ def translate_text(transcription_json, target_language):
|
|
| 80 |
"translated": translated_text,
|
| 81 |
"end": entry["end"]
|
| 82 |
})
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Return the translated timestamps as a JSON string
|
| 85 |
return json.dumps(translated_json, indent=4)
|
|
@@ -90,17 +93,17 @@ def add_transcript_to_video(video_path, timestamps, output_path):
|
|
| 90 |
|
| 91 |
# Create text clips based on timestamps
|
| 92 |
text_clips = []
|
| 93 |
-
|
| 94 |
-
for entry in timestamps:
|
| 95 |
-
# Create a text clip for each sentence
|
| 96 |
-
txt_clip = TextClip(entry["translated"], fontsize=24, color='white', bg_color='black', size=video.size)
|
| 97 |
-
|
| 98 |
-
# Set the start time and duration for each text clip
|
| 99 |
-
txt_clip = txt_clip.set_start(entry["start"]).set_duration(entry["end"] - entry["start"]).set_position(('bottom')).set_opacity(0.7) # Display each sentence for 3 seconds
|
| 100 |
-
|
| 101 |
-
# Append the text clip to the list
|
| 102 |
-
text_clips.append(txt_clip)
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
# Overlay all text clips on the original video
|
| 105 |
final_video = CompositeVideoClip([video] + text_clips)
|
| 106 |
|
|
|
|
| 80 |
"translated": translated_text,
|
| 81 |
"end": entry["end"]
|
| 82 |
})
|
| 83 |
+
# Log the components being added to translated_json
|
| 84 |
+
logger.debug("Adding to translated_json: start=%s, original=%s, translated=%s, end=%s",
|
| 85 |
+
entry["start"], original_text, translated_text, entry["end"])
|
| 86 |
|
| 87 |
# Return the translated timestamps as a JSON string
|
| 88 |
return json.dumps(translated_json, indent=4)
|
|
|
|
| 93 |
|
| 94 |
# Create text clips based on timestamps
|
| 95 |
text_clips = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
for entry in translated_json:
|
| 98 |
+
# Ensure `entry` is a dictionary with keys "start", "end", and "translated"
|
| 99 |
+
if isinstance(entry, dict) and "translated" in entry:
|
| 100 |
+
txt_clip = TextClip(
|
| 101 |
+
entry["translated"], fontsize=24, color='white', bg_color='black', size=video.size
|
| 102 |
+
).set_start(entry["start"]).set_duration(entry["end"] - entry["start"]).set_position(('bottom')).set_opacity(0.7)
|
| 103 |
+
text_clips.append(txt_clip)
|
| 104 |
+
else:
|
| 105 |
+
raise ValueError(f"Invalid entry format: {entry}")
|
| 106 |
+
|
| 107 |
# Overlay all text clips on the original video
|
| 108 |
final_video = CompositeVideoClip([video] + text_clips)
|
| 109 |
|