Spaces:
Runtime error
Runtime error
Commit
·
16957a4
1
Parent(s):
956a43b
Grant permission to write files
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import os
|
|
6 |
import subprocess
|
7 |
import whisper
|
8 |
from whisper.utils import write_vtt
|
|
|
9 |
#import openai
|
10 |
|
11 |
#from gtts import gTTS
|
@@ -141,10 +142,9 @@ remove_files(7)
|
|
141 |
|
142 |
|
143 |
|
144 |
-
#Download the model
|
145 |
-
model = whisper.load_model("
|
146 |
|
147 |
-
|
148 |
def video2mp3(video_file, output_ext="mp3"):
|
149 |
filename, ext = os.path.splitext(video_file)
|
150 |
subprocess.call(["ffmpeg", "-y", "-i", video_file, f"{filename}.{output_ext}"],
|
@@ -152,7 +152,6 @@ def video2mp3(video_file, output_ext="mp3"):
|
|
152 |
stderr=subprocess.STDOUT)
|
153 |
return f"{filename}.{output_ext}"
|
154 |
|
155 |
-
|
156 |
def translate(input_video):
|
157 |
audio_file = video2mp3(input_video)
|
158 |
|
@@ -163,7 +162,8 @@ def translate(input_video):
|
|
163 |
output_dir = '/content/'
|
164 |
audio_path = audio_file.split(".")[0]
|
165 |
|
166 |
-
|
|
|
167 |
write_vtt(result["segments"], file=vtt)
|
168 |
|
169 |
subtitle = audio_path + ".vtt"
|
@@ -171,8 +171,25 @@ def translate(input_video):
|
|
171 |
|
172 |
os.system(f"ffmpeg -i {input_video} -vf subtitles={subtitle} {output_video}")
|
173 |
|
|
|
|
|
|
|
|
|
|
|
174 |
return output_video
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
st.title("MultiLingual AI: Add Caption to Videos")
|
178 |
|
@@ -193,6 +210,7 @@ if uploaded_file is not None:
|
|
193 |
# Remove temporary files
|
194 |
os.remove("temp_video.mp4")
|
195 |
|
|
|
196 |
st.markdown(
|
197 |
'''
|
198 |
<style>
|
|
|
6 |
import subprocess
|
7 |
import whisper
|
8 |
from whisper.utils import write_vtt
|
9 |
+
import stat
|
10 |
#import openai
|
11 |
|
12 |
#from gtts import gTTS
|
|
|
142 |
|
143 |
|
144 |
|
145 |
+
# Download the model
|
146 |
+
model = whisper.load_model("tiny")
|
147 |
|
|
|
148 |
def video2mp3(video_file, output_ext="mp3"):
|
149 |
filename, ext = os.path.splitext(video_file)
|
150 |
subprocess.call(["ffmpeg", "-y", "-i", video_file, f"{filename}.{output_ext}"],
|
|
|
152 |
stderr=subprocess.STDOUT)
|
153 |
return f"{filename}.{output_ext}"
|
154 |
|
|
|
155 |
def translate(input_video):
|
156 |
audio_file = video2mp3(input_video)
|
157 |
|
|
|
162 |
output_dir = '/content/'
|
163 |
audio_path = audio_file.split(".")[0]
|
164 |
|
165 |
+
subtitle_file = os.path.join(output_dir, audio_path + ".vtt")
|
166 |
+
with open(subtitle_file, "w") as vtt:
|
167 |
write_vtt(result["segments"], file=vtt)
|
168 |
|
169 |
subtitle = audio_path + ".vtt"
|
|
|
171 |
|
172 |
os.system(f"ffmpeg -i {input_video} -vf subtitles={subtitle} {output_video}")
|
173 |
|
174 |
+
# Grant permissions to the temporary and output files
|
175 |
+
os.chmod("temp_video.mp4", stat.S_IRWXU) # Read, write, execute for the owner
|
176 |
+
os.chmod(subtitle_file, stat.S_IRWXU) # Read, write, execute for the owner
|
177 |
+
os.chmod(output_video, stat.S_IRWXU) # Read, write, execute for the owner
|
178 |
+
|
179 |
return output_video
|
180 |
|
181 |
+
# ...
|
182 |
+
In the code above, os.chmod() is used to modify the file permissions. stat.S_IRWXU sets the read, write, and execute permissions for the owner of the file. By granting these permissions, the app should have the necessary access to read the uploaded video file, write temporary files, and create the output files in the specified directory (/content/ in this case).
|
183 |
+
|
184 |
+
Make sure to apply the appropriate permissions for your specific use case, depending on the desired level of access and security requirements.
|
185 |
+
|
186 |
+
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
|
191 |
+
|
192 |
+
|
193 |
|
194 |
st.title("MultiLingual AI: Add Caption to Videos")
|
195 |
|
|
|
210 |
# Remove temporary files
|
211 |
os.remove("temp_video.mp4")
|
212 |
|
213 |
+
# Footer
|
214 |
st.markdown(
|
215 |
'''
|
216 |
<style>
|