codelion commited on
Commit
99b4eed
·
verified ·
1 Parent(s): 80f741f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -79,9 +79,16 @@ def extract_key_frames(video_file: str, key_frames_response: str) -> list:
79
  print("Error: Could not open video file.")
80
  return extracted_frames
81
 
 
 
 
 
 
 
 
82
  try:
83
  # Try parsing as JSON
84
- key_frames = json.loads(key_frames_response)
85
  if not isinstance(key_frames, list):
86
  raise ValueError("Response is not a list.")
87
  except json.JSONDecodeError as e:
 
79
  print("Error: Could not open video file.")
80
  return extracted_frames
81
 
82
+ # Strip Markdown code block if present
83
+ cleaned_response = key_frames_response.strip()
84
+ if cleaned_response.startswith("```json") and cleaned_response.endswith("```"):
85
+ cleaned_response = cleaned_response[7:-3].strip() # Remove ```json and ```
86
+ elif cleaned_response.startswith("```") and cleaned_response.endswith("```"):
87
+ cleaned_response = cleaned_response[3:-3].strip() # Remove generic ```
88
+
89
  try:
90
  # Try parsing as JSON
91
+ key_frames = json.loads(cleaned_response)
92
  if not isinstance(key_frames, list):
93
  raise ValueError("Response is not a list.")
94
  except json.JSONDecodeError as e: