Spaces:
Running
on
Zero
Running
on
Zero
feat: Add GPU-accelerated FFmpeg command execution and refactor command handling
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
from PIL import Image
|
4 |
from moviepy.editor import VideoFileClip, AudioFileClip
|
@@ -215,6 +216,17 @@ YOUR RESPONSE:
|
|
215 |
raise Exception("API Error")
|
216 |
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
def update(
|
219 |
files,
|
220 |
prompt,
|
@@ -276,11 +288,7 @@ def update(
|
|
276 |
|
277 |
output_file_name = f"output_{uuid.uuid4()}.mp4"
|
278 |
output_file_path = str((Path(temp_dir) / output_file_name).resolve())
|
279 |
-
|
280 |
-
print(
|
281 |
-
f"\n=== EXECUTING FFMPEG COMMAND ===\nffmpeg {' '.join(final_command[1:])}\n"
|
282 |
-
)
|
283 |
-
subprocess.run(final_command, cwd=temp_dir)
|
284 |
# Extract just the command for display
|
285 |
command_for_display = f"ffmpeg {' '.join(args[1:])} -y output.mp4"
|
286 |
generated_command = f"### Generated Command\n```bash\n{command_for_display}\n```"
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces
|
3 |
|
4 |
from PIL import Image
|
5 |
from moviepy.editor import VideoFileClip, AudioFileClip
|
|
|
216 |
raise Exception("API Error")
|
217 |
|
218 |
|
219 |
+
@spaces.GPU(duration=120)
|
220 |
+
def execute_ffmpeg_command(args, temp_dir, output_file_path):
|
221 |
+
"""Execute FFmpeg command with GPU acceleration"""
|
222 |
+
final_command = args + ["-y", output_file_path]
|
223 |
+
print(
|
224 |
+
f"\n=== EXECUTING FFMPEG COMMAND ===\nffmpeg {' '.join(final_command[1:])}\n"
|
225 |
+
)
|
226 |
+
subprocess.run(final_command, cwd=temp_dir)
|
227 |
+
return output_file_path
|
228 |
+
|
229 |
+
|
230 |
def update(
|
231 |
files,
|
232 |
prompt,
|
|
|
288 |
|
289 |
output_file_name = f"output_{uuid.uuid4()}.mp4"
|
290 |
output_file_path = str((Path(temp_dir) / output_file_name).resolve())
|
291 |
+
execute_ffmpeg_command(args, temp_dir, output_file_path)
|
|
|
|
|
|
|
|
|
292 |
# Extract just the command for display
|
293 |
command_for_display = f"ffmpeg {' '.join(args[1:])} -y output.mp4"
|
294 |
generated_command = f"### Generated Command\n```bash\n{command_for_display}\n```"
|