Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -133,7 +133,7 @@ def main():
|
|
133 |
st.title("GPT4V AI Voiceover 🎥🔮")
|
134 |
st.text("Explore how GPT4V changes the way we voiceover videos.")
|
135 |
|
136 |
-
|
137 |
if not check_password():
|
138 |
return # Exit the function if the password check fails
|
139 |
|
@@ -144,7 +144,7 @@ def main():
|
|
144 |
return # or handle the error as you see fit
|
145 |
|
146 |
uploaded_file = st.file_uploader("Select a video file", type=["mp4", "avi"])
|
147 |
-
|
148 |
option = st.selectbox(
|
149 |
'Choose the voice you want',
|
150 |
('Female Voice', 'Male Voice'))
|
@@ -157,32 +157,35 @@ def main():
|
|
157 |
if uploaded_file is not None:
|
158 |
st.video(uploaded_file)
|
159 |
p = 'Generate a short voiceover script for the video, matching the content with the video scenes. The style should be...'
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
186 |
|
187 |
if __name__ == "__main__":
|
188 |
-
main()
|
|
|
133 |
st.title("GPT4V AI Voiceover 🎥🔮")
|
134 |
st.text("Explore how GPT4V changes the way we voiceover videos.")
|
135 |
|
136 |
+
# Check password before proceeding
|
137 |
if not check_password():
|
138 |
return # Exit the function if the password check fails
|
139 |
|
|
|
144 |
return # or handle the error as you see fit
|
145 |
|
146 |
uploaded_file = st.file_uploader("Select a video file", type=["mp4", "avi"])
|
147 |
+
|
148 |
option = st.selectbox(
|
149 |
'Choose the voice you want',
|
150 |
('Female Voice', 'Male Voice'))
|
|
|
157 |
if uploaded_file is not None:
|
158 |
st.video(uploaded_file)
|
159 |
p = 'Generate a short voiceover script for the video, matching the content with the video scenes. The style should be...'
|
160 |
+
prompt = st.text_area("Prompt", value=p)
|
161 |
+
|
162 |
+
if st.button("START PROCESSING", type="primary"):
|
163 |
+
with st.spinner("Video is being processed..."):
|
164 |
+
base64Frame, video_filename, video_duration = video_to_frames(uploaded_file)
|
165 |
+
|
166 |
+
# Check if the video duration exceeds 30 seconds
|
167 |
+
if video_duration > 30:
|
168 |
+
st.error("The video exceeds the maximum allowed duration of 30 seconds.")
|
169 |
+
return # Stop processing further
|
170 |
+
|
171 |
+
est_word_count = video_duration * 4
|
172 |
+
final_prompt = prompt + f"(This video is ONLY {video_duration} seconds long. So make sure the voiceover MUST be able to be explained in less than {est_word_count} words. Ignore and don't generate anything else than the script that you'll use to voice over the video.)"
|
173 |
+
text = frames_to_story(base64Frame, final_prompt, openai_key)
|
174 |
+
st.write(text)
|
175 |
+
# Generate audio from text
|
176 |
+
audio_filename, audio_bytes_io = text_to_audio(text, openai_key, classify)
|
177 |
+
# Merge audio and video
|
178 |
+
output_video_filename = os.path.splitext(video_filename)[0] + "_output.mp4"
|
179 |
+
|
180 |
+
final_video_filename = merge_audio_video(video_filename, audio_filename, output_video_filename)
|
181 |
+
|
182 |
+
# Display the result
|
183 |
+
st.video(final_video_filename)
|
184 |
+
|
185 |
+
# Clean up the temporary files
|
186 |
+
os.unlink(video_filename)
|
187 |
+
os.unlink(audio_filename)
|
188 |
+
os.unlink(final_video_filename)
|
189 |
|
190 |
if __name__ == "__main__":
|
191 |
+
main()
|