Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
| 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:
|