Spaces:
Sleeping
Sleeping
Update Milestone5API.py
Browse files- Milestone5API.py +5 -5
Milestone5API.py
CHANGED
|
@@ -11,7 +11,7 @@ from pydub import AudioSegment
|
|
| 11 |
from moviepy.editor import VideoFileClip, AudioFileClip, TextClip, CompositeVideoClip
|
| 12 |
import subprocess
|
| 13 |
|
| 14 |
-
def add_text_to_video(input_video_path, output_video_path, text):
|
| 15 |
try:
|
| 16 |
subprocess.run([
|
| 17 |
'ffmpeg',
|
|
@@ -25,7 +25,7 @@ def add_text_to_video(input_video_path, output_video_path, text):
|
|
| 25 |
except subprocess.CalledProcessError as e:
|
| 26 |
print("Error adding text to video:", e)
|
| 27 |
|
| 28 |
-
def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_path, translated_text):
|
| 29 |
print("Loading video...")
|
| 30 |
video = VideoFileClip(video_file_path)
|
| 31 |
print("Video loaded successfully.")
|
|
@@ -44,7 +44,7 @@ def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_
|
|
| 44 |
|
| 45 |
try:
|
| 46 |
video.write_videofile(output_video_file_path, codec="libx264", audio_codec="aac", remove_temp=True)
|
| 47 |
-
add_text_to_video(output_video_file_path, output_video_file_path, translated_text)
|
| 48 |
print("Video file written successfully.")
|
| 49 |
except Exception as e:
|
| 50 |
print("Error writing video file:", e)
|
|
@@ -66,10 +66,10 @@ def text_to_speech(translated_text_file_path, video_path):
|
|
| 66 |
tts.tts_to_file(text=translated_text, file_path=output_file_path)
|
| 67 |
|
| 68 |
output_video_path = f"CS370_Milestone5/videos/{file_name_only}_new.mp4"
|
| 69 |
-
|
| 70 |
|
| 71 |
replace_video_audio(video_path, output_file_path, output_video_path,translated_text)
|
| 72 |
-
return
|
| 73 |
|
| 74 |
def translate_text_file(input_text_path, output_text_path, source_lang='en', target_lang='fr', model_name="Helsinki-NLP/opus-mt-en-fr", batch_size=8):
|
| 75 |
model = MarianMTModel.from_pretrained(model_name)
|
|
|
|
| 11 |
from moviepy.editor import VideoFileClip, AudioFileClip, TextClip, CompositeVideoClip
|
| 12 |
import subprocess
|
| 13 |
|
| 14 |
+
def add_text_to_video(input_video_path, output_video_path, text, new_video_path):
|
| 15 |
try:
|
| 16 |
subprocess.run([
|
| 17 |
'ffmpeg',
|
|
|
|
| 25 |
except subprocess.CalledProcessError as e:
|
| 26 |
print("Error adding text to video:", e)
|
| 27 |
|
| 28 |
+
def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_path, translated_text,new_video_path):
|
| 29 |
print("Loading video...")
|
| 30 |
video = VideoFileClip(video_file_path)
|
| 31 |
print("Video loaded successfully.")
|
|
|
|
| 44 |
|
| 45 |
try:
|
| 46 |
video.write_videofile(output_video_file_path, codec="libx264", audio_codec="aac", remove_temp=True)
|
| 47 |
+
add_text_to_video(output_video_file_path, output_video_file_path, translated_text, new_video_path)
|
| 48 |
print("Video file written successfully.")
|
| 49 |
except Exception as e:
|
| 50 |
print("Error writing video file:", e)
|
|
|
|
| 66 |
tts.tts_to_file(text=translated_text, file_path=output_file_path)
|
| 67 |
|
| 68 |
output_video_path = f"CS370_Milestone5/videos/{file_name_only}_new.mp4"
|
| 69 |
+
new_video_path = f"CS370_Milestone5/videos/{file_name_only}_new2.mp4"
|
| 70 |
|
| 71 |
replace_video_audio(video_path, output_file_path, output_video_path,translated_text)
|
| 72 |
+
return new_video_path
|
| 73 |
|
| 74 |
def translate_text_file(input_text_path, output_text_path, source_lang='en', target_lang='fr', model_name="Helsinki-NLP/opus-mt-en-fr", batch_size=8):
|
| 75 |
model = MarianMTModel.from_pretrained(model_name)
|