victor HF Staff commited on
Commit
e45b39f
·
1 Parent(s): 2357f67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -26
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
- if "```" in content:
259
- # Find content between ```sh or ```bash and the next ```
260
- import re
261
-
262
- command_match = re.search(
263
- r"```(?:sh|bash)?\n(.*?)\n```", content, re.DOTALL
264
- )
265
- if command_match:
266
- command = command_match.group(1).strip()
267
- else:
268
- # Try to find a line that starts with ffmpeg
269
- ffmpeg_lines = [
270
- line.strip()
271
- for line in content.split("\n")
272
- if line.strip().startswith("ffmpeg")
273
- ]
274
- if ffmpeg_lines:
275
- command = ffmpeg_lines[0]
276
- else:
277
- command = content.replace("\n", "")
278
- else:
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
- else:
288
- command = content.replace("\n", "")
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