Sanchayt commited on
Commit
7abe680
·
1 Parent(s): f86362b
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +35 -22
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ env
app.py CHANGED
@@ -12,20 +12,19 @@ from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
12
  import os
13
  from elevenlabs import set_api_key
14
 
15
- set_api_key("6d5e981fbb2643b06459981da55c4ae7")
16
 
17
 
18
  def shorten_audio(filename):
19
- cut_filename = "AutoDub/dub/cut_audio.mp4"
20
  audio = AudioSegment.from_file(filename)
21
- cut_audio = audio[:60 * 1000]
22
  cut_audio.export(cut_filename, format="mp4")
23
  return cut_filename
24
 
25
 
26
  def generate_translation(original_text, destination_language):
27
- anthropic = Anthropic(
28
- api_key="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")
29
 
30
  prompt = (
31
  f"{HUMAN_PROMPT} Please translate this video transcript into {destination_language}. You will get "
@@ -47,18 +46,14 @@ def generate_translation(original_text, destination_language):
47
 
48
 
49
  def generate_dubs(text):
50
- filename = "AutoDub/dub/output.mp3"
51
 
52
- set_api_key(st.secrets['xi_api_key'])
53
 
54
- audio = generate(
55
- text=text,
56
- voice="Sanchay",
57
- model='eleven_multilingual_v1'
58
- )
59
 
60
  audio_io = io.BytesIO(audio)
61
- insert_audio = AudioSegment.from_file(audio_io, format='mp3')
62
  insert_audio.export(filename, format="mp3")
63
 
64
  return filename
@@ -67,10 +62,21 @@ def generate_dubs(text):
67
  def combine_video(video_filename, audio_filename):
68
  ffmpeg_extract_subclip(video_filename, 0, 60, targetname="cut_video.mp4")
69
 
70
- output_filename = "AutoDub/dub/output.mp4"
71
-
72
- command = ["ffmpeg", "-y", "-i", "cut_video.mp4", "-i", audio_filename, "-c:v", "copy", "-c:a", "aac",
73
- output_filename]
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  subprocess.run(command)
76
 
@@ -81,7 +87,10 @@ st.title("AutoDubs 📺🎵")
81
 
82
  link = st.text_input("Link to Youtube Video", key="link")
83
 
84
- language = st.selectbox("Translate to", ("French", "German", "Hindi", "Italian", "Polish", "Portuguese", "Spanish"))
 
 
 
85
 
86
  if st.button("Transcribe!"):
87
  print(f"downloading from link: {link}")
@@ -105,11 +114,13 @@ if st.button("Transcribe!"):
105
  print(transcription)
106
 
107
  if transcription:
108
- df = pd.DataFrame(transcription['segments'], columns=['start', 'end', 'text'])
 
 
109
  st.dataframe(df)
110
- print(transcription['text'])
111
  dubbing_caption = st.caption("Dubbing...")
112
- translation = generate_translation(transcription['text'], language)
113
  dubbing_caption = st.caption("Begin dubbing...")
114
  dubs_audio = generate_dubs(translation)
115
  dubbing_caption.caption("Dubs generated! combining with the video...")
@@ -118,7 +129,9 @@ if st.button("Transcribe!"):
118
  video_filename = video_streams.first().download()
119
 
120
  if video_filename:
121
- dubbing_caption.caption("Video downloaded! combining the video and the dubs...")
 
 
122
  output_filename = combine_video(video_filename, dubs_audio)
123
 
124
  if os.path.exists(output_filename):
 
12
  import os
13
  from elevenlabs import set_api_key
14
 
15
+ set_api_key(st.secrets["xi_api_key"])
16
 
17
 
18
  def shorten_audio(filename):
19
+ cut_filename = "cut_audio.mp4"
20
  audio = AudioSegment.from_file(filename)
21
+ cut_audio = audio[: 60 * 1000]
22
  cut_audio.export(cut_filename, format="mp4")
23
  return cut_filename
24
 
25
 
26
  def generate_translation(original_text, destination_language):
27
+ anthropic = Anthropic(api_key=st.secrets["anthropic"])
 
28
 
29
  prompt = (
30
  f"{HUMAN_PROMPT} Please translate this video transcript into {destination_language}. You will get "
 
46
 
47
 
48
  def generate_dubs(text):
49
+ filename = "output.mp3"
50
 
51
+ set_api_key(st.secrets["xi_api_key"])
52
 
53
+ audio = generate(text=text, voice="Sanchay", model="eleven_multilingual_v1")
 
 
 
 
54
 
55
  audio_io = io.BytesIO(audio)
56
+ insert_audio = AudioSegment.from_file(audio_io, format="mp3")
57
  insert_audio.export(filename, format="mp3")
58
 
59
  return filename
 
62
  def combine_video(video_filename, audio_filename):
63
  ffmpeg_extract_subclip(video_filename, 0, 60, targetname="cut_video.mp4")
64
 
65
+ output_filename = "output.mp4"
66
+
67
+ command = [
68
+ "ffmpeg",
69
+ "-y",
70
+ "-i",
71
+ "cut_video.mp4",
72
+ "-i",
73
+ audio_filename,
74
+ "-c:v",
75
+ "copy",
76
+ "-c:a",
77
+ "aac",
78
+ output_filename,
79
+ ]
80
 
81
  subprocess.run(command)
82
 
 
87
 
88
  link = st.text_input("Link to Youtube Video", key="link")
89
 
90
+ language = st.selectbox(
91
+ "Translate to",
92
+ ("French", "German", "Hindi", "Italian", "Polish", "Portuguese", "Spanish"),
93
+ )
94
 
95
  if st.button("Transcribe!"):
96
  print(f"downloading from link: {link}")
 
114
  print(transcription)
115
 
116
  if transcription:
117
+ df = pd.DataFrame(
118
+ transcription["segments"], columns=["start", "end", "text"]
119
+ )
120
  st.dataframe(df)
121
+ print(transcription["text"])
122
  dubbing_caption = st.caption("Dubbing...")
123
+ translation = generate_translation(transcription["text"], language)
124
  dubbing_caption = st.caption("Begin dubbing...")
125
  dubs_audio = generate_dubs(translation)
126
  dubbing_caption.caption("Dubs generated! combining with the video...")
 
129
  video_filename = video_streams.first().download()
130
 
131
  if video_filename:
132
+ dubbing_caption.caption(
133
+ "Video downloaded! combining the video and the dubs..."
134
+ )
135
  output_filename = combine_video(video_filename, dubs_audio)
136
 
137
  if os.path.exists(output_filename):