new
Browse files
app.py
CHANGED
@@ -100,7 +100,9 @@ def get_completion(prompt, files_info, top_p, temperature):
|
|
100 |
"role": "system",
|
101 |
# "content": f"""Act as a FFMPEG expert. Create a valid FFMPEG command that will be directly pasted in the terminal. Using those files: {files_info} create the FFMPEG command to achieve this: "{prompt}". Make sure it's a valid command that will not do any error. Always name the output of the FFMPEG command "output.mp4". Always use the FFMPEG overwrite option (-y). Don't produce video longer than 1 minute. Think step by step but never give any explanation, only the shell command.""",
|
102 |
# "content": f"""You'll need to create a valid FFMPEG command that will be directly pasted in the terminal. You have those files (images, videos, and audio) at your disposal: {files_info} and you need to compose a new video using FFMPEG and following those instructions: "{prompt}". You'll need to use as many assets as you can. Make sure it's a valid command that will not do any error. Always name the output of the FFMPEG command "output.mp4". Always use the FFMPEG overwrite option (-y). Try to avoid using -filter_complex option. Don't produce video longer than 1 minute. Think step by step but never give any explanation, only the shell command.""",
|
103 |
-
"content": """
|
|
|
|
|
104 |
|
105 |
You are given:
|
106 |
(1) a set of video, audio and/or image assets. Including their name, duration, dimensions and file size
|
@@ -153,61 +155,60 @@ def update(files, prompt, top_p=1, temperature=1):
|
|
153 |
)
|
154 |
if file_info["size"] > 10000000:
|
155 |
raise gr.Error("Please make sure all files are less than 10MB in size.")
|
156 |
-
try:
|
157 |
-
command_string = get_completion(prompt, files_info, top_p, temperature)
|
158 |
-
print(
|
159 |
-
f"""///PROMTP {prompt} \n\n/// START OF COMMAND ///:\n\n{command_string}\n\n/// END OF COMMAND ///\n\n"""
|
160 |
-
)
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
shutil.copy(file_path, temp_dir)
|
171 |
|
172 |
-
|
173 |
-
|
174 |
-
args
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
raise Exception("FFMPEG generated command is not valid. Please try again.")
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
-
css = """
|
194 |
-
# #header {
|
195 |
-
# padding: 1.5rem 0 0.8rem;
|
196 |
-
# }
|
197 |
-
# #header h1 {
|
198 |
-
# font-size: 1.5rem; margin-bottom: 0.3rem;
|
199 |
-
# }
|
200 |
-
# .boundedheight, .unpadded_box {
|
201 |
-
# height: 30vh !important;
|
202 |
-
# max-height: 50vh !important;
|
203 |
-
# }
|
204 |
-
"""
|
205 |
|
206 |
-
with gr.Blocks(
|
207 |
gr.Markdown(
|
208 |
"""
|
209 |
-
#
|
210 |
Add video, image and audio assets and ask ChatGPT to compose a new video.
|
|
|
211 |
""",
|
212 |
elem_id="header",
|
213 |
)
|
@@ -279,7 +280,7 @@ with gr.Blocks(css=css) as demo:
|
|
279 |
],
|
280 |
[
|
281 |
["./examples/heat-wave.mp3", "./examples/square-image.png"],
|
282 |
-
"Make a 720x720 video, a white waveform of the audio
|
283 |
0,
|
284 |
0,
|
285 |
],
|
|
|
100 |
"role": "system",
|
101 |
# "content": f"""Act as a FFMPEG expert. Create a valid FFMPEG command that will be directly pasted in the terminal. Using those files: {files_info} create the FFMPEG command to achieve this: "{prompt}". Make sure it's a valid command that will not do any error. Always name the output of the FFMPEG command "output.mp4". Always use the FFMPEG overwrite option (-y). Don't produce video longer than 1 minute. Think step by step but never give any explanation, only the shell command.""",
|
102 |
# "content": f"""You'll need to create a valid FFMPEG command that will be directly pasted in the terminal. You have those files (images, videos, and audio) at your disposal: {files_info} and you need to compose a new video using FFMPEG and following those instructions: "{prompt}". You'll need to use as many assets as you can. Make sure it's a valid command that will not do any error. Always name the output of the FFMPEG command "output.mp4". Always use the FFMPEG overwrite option (-y). Try to avoid using -filter_complex option. Don't produce video longer than 1 minute. Think step by step but never give any explanation, only the shell command.""",
|
103 |
+
"content": """
|
104 |
+
You are a very experienced media engineer, controlling a UNIX terminal.
|
105 |
+
You are an FFMPEG expert with years of experience and multiple contributions to the FFMPEG project.
|
106 |
|
107 |
You are given:
|
108 |
(1) a set of video, audio and/or image assets. Including their name, duration, dimensions and file size
|
|
|
155 |
)
|
156 |
if file_info["size"] > 10000000:
|
157 |
raise gr.Error("Please make sure all files are less than 10MB in size.")
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
+
attempts = 0
|
160 |
+
while attempts < 2:
|
161 |
+
print("ATTEMPT", attempts)
|
162 |
+
try:
|
163 |
+
command_string = get_completion(prompt, files_info, top_p, temperature)
|
164 |
+
print(
|
165 |
+
f"""///PROMTP {prompt} \n\n/// START OF COMMAND ///:\n\n{command_string}\n\n/// END OF COMMAND ///\n\n"""
|
166 |
+
)
|
|
|
167 |
|
168 |
+
# split command string into list of arguments
|
169 |
+
args = shlex.split(command_string)
|
170 |
+
if args[0] != "ffmpeg":
|
171 |
+
raise Exception("Command does not start with ffmpeg")
|
172 |
+
temp_dir = tempfile.mkdtemp()
|
173 |
+
# copy files to temp dir
|
174 |
+
for file in files:
|
175 |
+
file_path = Path(file.name)
|
176 |
+
shutil.copy(file_path, temp_dir)
|
|
|
177 |
|
178 |
+
# test if ffmpeg command is valid dry run
|
179 |
+
ffmpg_dry_run = subprocess.run(
|
180 |
+
args + ["-f", "null", "-"],
|
181 |
+
stderr=subprocess.PIPE,
|
182 |
+
text=True,
|
183 |
+
cwd=temp_dir,
|
184 |
+
)
|
185 |
+
if ffmpg_dry_run.returncode == 0:
|
186 |
+
print("Command is valid.")
|
187 |
+
else:
|
188 |
+
print("Command is not valid. Error output:")
|
189 |
+
print(ffmpg_dry_run.stderr)
|
190 |
+
raise Exception(
|
191 |
+
"FFMPEG generated command is not valid. Please try again."
|
192 |
+
)
|
193 |
|
194 |
+
output_file_name = f"output_{uuid.uuid4()}.mp4"
|
195 |
+
output_file_path = str((Path(temp_dir) / output_file_name).resolve())
|
196 |
+
subprocess.run(args + ["-y", output_file_path], cwd=temp_dir)
|
197 |
+
generated_command = f"### Generated Command\n```bash\n{format_bash_command(args)}\n -y output.mp4\n```"
|
198 |
+
return output_file_path, gr.update(value=generated_command)
|
199 |
+
except Exception as e:
|
200 |
+
attempts += 1
|
201 |
+
if attempts >= 2:
|
202 |
+
print("FROM UPDATE", e)
|
203 |
+
raise gr.Error(e)
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
+
with gr.Blocks() as demo:
|
207 |
gr.Markdown(
|
208 |
"""
|
209 |
+
# 🏞 GPT-4 Video Composer
|
210 |
Add video, image and audio assets and ask ChatGPT to compose a new video.
|
211 |
+
**Please note: This demo is not a generative AI model, it only uses GPT-4 to generate a valid FFMPEG command based on the input files and the prompt.**
|
212 |
""",
|
213 |
elem_id="header",
|
214 |
)
|
|
|
280 |
],
|
281 |
[
|
282 |
["./examples/heat-wave.mp3", "./examples/square-image.png"],
|
283 |
+
"Make a 720x720 video, a white waveform of the audio, and finally add add the input image as the background all along the video.",
|
284 |
0,
|
285 |
0,
|
286 |
],
|