Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -103,6 +103,7 @@ def get_completion(
|
|
103 |
top_p,
|
104 |
temperature,
|
105 |
model_choice,
|
|
|
106 |
previous_error=None,
|
107 |
previous_command=None,
|
108 |
):
|
@@ -164,10 +165,12 @@ FORMAT DETECTION KEYWORDS:
|
|
164 |
|
165 |
user_content += "\n\nYOUR RESPONSE:"
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
|
|
171 |
You are a very experienced media engineer, controlling a UNIX terminal.
|
172 |
You are an FFMPEG expert with years of experience and multiple contributions to the FFMPEG project.
|
173 |
|
@@ -224,12 +227,53 @@ When creating slideshows from multiple images with different dimensions, ALWAYS
|
|
224 |
|
225 |
Remember: Simpler is better. Only use advanced ffmpeg features if absolutely necessary for the requested output.
|
226 |
""",
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
try:
|
234 |
# Print the complete prompt
|
235 |
print("\n=== COMPLETE PROMPT ===")
|
@@ -303,7 +347,13 @@ Remember: Simpler is better. Only use advanced ffmpeg features if absolutely nec
|
|
303 |
# remove output.mp4 with the actual output file path
|
304 |
command = command.replace("output.mp4", "")
|
305 |
|
306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
except Exception as e:
|
308 |
raise Exception("API Error")
|
309 |
|
@@ -371,16 +421,18 @@ def update(
|
|
371 |
command_attempts = []
|
372 |
previous_error = None
|
373 |
previous_command = None
|
|
|
374 |
|
375 |
while attempts < 2:
|
376 |
print("ATTEMPT", attempts + 1)
|
377 |
try:
|
378 |
-
command_string = get_completion(
|
379 |
prompt,
|
380 |
files_info,
|
381 |
top_p,
|
382 |
temperature,
|
383 |
model_choice,
|
|
|
384 |
previous_error,
|
385 |
previous_command,
|
386 |
)
|
|
|
103 |
top_p,
|
104 |
temperature,
|
105 |
model_choice,
|
106 |
+
conversation_history=None,
|
107 |
previous_error=None,
|
108 |
previous_command=None,
|
109 |
):
|
|
|
165 |
|
166 |
user_content += "\n\nYOUR RESPONSE:"
|
167 |
|
168 |
+
# Initialize conversation with system message and first user message
|
169 |
+
if conversation_history is None:
|
170 |
+
messages = [
|
171 |
+
{
|
172 |
+
"role": "system",
|
173 |
+
"content": """
|
174 |
You are a very experienced media engineer, controlling a UNIX terminal.
|
175 |
You are an FFMPEG expert with years of experience and multiple contributions to the FFMPEG project.
|
176 |
|
|
|
227 |
|
228 |
Remember: Simpler is better. Only use advanced ffmpeg features if absolutely necessary for the requested output.
|
229 |
""",
|
230 |
+
},
|
231 |
+
{
|
232 |
+
"role": "user",
|
233 |
+
"content": user_content,
|
234 |
+
},
|
235 |
+
]
|
236 |
+
else:
|
237 |
+
# Use existing conversation history
|
238 |
+
messages = conversation_history[:]
|
239 |
+
|
240 |
+
# If there's a previous error, add it as a separate message exchange
|
241 |
+
if previous_error and previous_command:
|
242 |
+
# Add the failed command as assistant response
|
243 |
+
messages.append({
|
244 |
+
"role": "assistant",
|
245 |
+
"content": f"I'll execute this FFmpeg command:\n\n```bash\n{previous_command}\n```"
|
246 |
+
})
|
247 |
+
|
248 |
+
# Add the error as user feedback
|
249 |
+
messages.append({
|
250 |
+
"role": "user",
|
251 |
+
"content": f"""The command failed with the following error:
|
252 |
+
|
253 |
+
ERROR MESSAGE:
|
254 |
+
{previous_error}
|
255 |
+
|
256 |
+
Please analyze the error and generate a corrected command that addresses the specific issue.
|
257 |
+
|
258 |
+
COMMON SLIDESHOW ERROR FIXES:
|
259 |
+
- If you see "do not match the corresponding output link" β Images have different dimensions, use scale+pad approach
|
260 |
+
- If you see "Padded dimensions cannot be smaller than input dimensions" β Fix pad calculation or use standard resolution (1920x1080 or 1080x1920)
|
261 |
+
- If you see "Failed to configure input pad" β Check scale and pad syntax, ensure proper filter chain
|
262 |
+
- If you see "Invalid argument" in filters β Simplify filter_complex syntax and check parentheses
|
263 |
+
|
264 |
+
FORMAT DETECTION KEYWORDS:
|
265 |
+
- "vertical", "portrait", "9:16", "TikTok", "Instagram Stories", "phone" β Use 1080x1920
|
266 |
+
- "horizontal", "landscape", "16:9", "YouTube", "TV" β Use 1920x1080 (default)
|
267 |
+
- "square", "1:1", "Instagram post" β Use 1080x1080
|
268 |
+
|
269 |
+
Please provide a corrected FFmpeg command."""
|
270 |
+
})
|
271 |
+
else:
|
272 |
+
# Add new user request to existing conversation
|
273 |
+
messages.append({
|
274 |
+
"role": "user",
|
275 |
+
"content": user_content,
|
276 |
+
})
|
277 |
try:
|
278 |
# Print the complete prompt
|
279 |
print("\n=== COMPLETE PROMPT ===")
|
|
|
347 |
# remove output.mp4 with the actual output file path
|
348 |
command = command.replace("output.mp4", "")
|
349 |
|
350 |
+
# Add the assistant's response to conversation history
|
351 |
+
messages.append({
|
352 |
+
"role": "assistant",
|
353 |
+
"content": content
|
354 |
+
})
|
355 |
+
|
356 |
+
return command, messages
|
357 |
except Exception as e:
|
358 |
raise Exception("API Error")
|
359 |
|
|
|
421 |
command_attempts = []
|
422 |
previous_error = None
|
423 |
previous_command = None
|
424 |
+
conversation_history = None
|
425 |
|
426 |
while attempts < 2:
|
427 |
print("ATTEMPT", attempts + 1)
|
428 |
try:
|
429 |
+
command_string, conversation_history = get_completion(
|
430 |
prompt,
|
431 |
files_info,
|
432 |
top_p,
|
433 |
temperature,
|
434 |
model_choice,
|
435 |
+
conversation_history,
|
436 |
previous_error,
|
437 |
previous_command,
|
438 |
)
|