Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -254,39 +254,52 @@ Remember: Simpler is better. Only use advanced ffmpeg features if absolutely nec
|
|
254 |
max_tokens=2048,
|
255 |
)
|
256 |
content = completion.choices[0].message.content
|
|
|
|
|
257 |
# Extract command from code block if present
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
)
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
# Try to find a line that starts with ffmpeg
|
280 |
ffmpeg_lines = [
|
281 |
line.strip()
|
282 |
for line in content.split("\n")
|
283 |
-
if line.strip().startswith("ffmpeg")
|
284 |
]
|
285 |
if ffmpeg_lines:
|
286 |
command = ffmpeg_lines[0]
|
287 |
-
|
288 |
-
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
# remove output.mp4 with the actual output file path
|
291 |
command = command.replace("output.mp4", "")
|
292 |
|
|
|
254 |
max_tokens=2048,
|
255 |
)
|
256 |
content = completion.choices[0].message.content
|
257 |
+
print(f"\n=== RAW API RESPONSE ===\n{content}\n========================\n")
|
258 |
+
|
259 |
# Extract command from code block if present
|
260 |
+
import re
|
261 |
+
command = None
|
262 |
+
|
263 |
+
# Try multiple code block patterns
|
264 |
+
code_patterns = [
|
265 |
+
r"```(?:bash|sh|shell)?\n(.*?)\n```", # Standard code blocks
|
266 |
+
r"```\n(.*?)\n```", # Plain code blocks
|
267 |
+
r"`([^`]*ffmpeg[^`]*)`", # Inline code with ffmpeg
|
268 |
+
]
|
269 |
+
|
270 |
+
for pattern in code_patterns:
|
271 |
+
matches = re.findall(pattern, content, re.DOTALL | re.IGNORECASE)
|
272 |
+
for match in matches:
|
273 |
+
if "ffmpeg" in match.lower():
|
274 |
+
command = match.strip()
|
275 |
+
break
|
276 |
+
if command:
|
277 |
+
break
|
278 |
+
|
279 |
+
# If no code block found, try to find ffmpeg lines directly
|
280 |
+
if not command:
|
|
|
281 |
ffmpeg_lines = [
|
282 |
line.strip()
|
283 |
for line in content.split("\n")
|
284 |
+
if line.strip().lower().startswith("ffmpeg")
|
285 |
]
|
286 |
if ffmpeg_lines:
|
287 |
command = ffmpeg_lines[0]
|
288 |
+
|
289 |
+
# Last resort: look for any line containing ffmpeg
|
290 |
+
if not command:
|
291 |
+
for line in content.split("\n"):
|
292 |
+
line = line.strip()
|
293 |
+
if "ffmpeg" in line.lower() and len(line) > 10:
|
294 |
+
command = line
|
295 |
+
break
|
296 |
+
|
297 |
+
if not command:
|
298 |
+
print(f"ERROR: No ffmpeg command found in response")
|
299 |
+
command = content.replace("\n", " ").strip()
|
300 |
+
|
301 |
+
print(f"=== EXTRACTED COMMAND ===\n{command}\n========================\n")
|
302 |
+
|
303 |
# remove output.mp4 with the actual output file path
|
304 |
command = command.replace("output.mp4", "")
|
305 |
|