rairo commited on
Commit
e57bec9
·
verified ·
1 Parent(s): 5eb415f

Update sozo_gen.py

Browse files
Files changed (1) hide show
  1. sozo_gen.py +25 -0
sozo_gen.py CHANGED
@@ -258,6 +258,31 @@ def concat_media(file_paths: List[str], output_path: Path):
258
  finally:
259
  list_file.unlink(missing_ok=True)
260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  # --- Main Business Logic Functions for Flask ---
262
 
263
  # ADD THIS NEW HELPER FUNCTION SOMEWHERE NEAR THE TOP OF THE FILE
 
258
  finally:
259
  list_file.unlink(missing_ok=True)
260
 
261
+ # Backward-compatible fix: Override json.dumps to handle non-serializable types
262
+ import json as _json
263
+
264
+ def safe_json_dumps(obj, indent=2, **kwargs):
265
+ """Safely serialize object to JSON, handling non-serializable types."""
266
+ def json_serializer(obj):
267
+ if isinstance(obj, (bool, int, float, str, type(None))):
268
+ return obj
269
+ elif isinstance(obj, (list, tuple)):
270
+ return [json_serializer(item) for item in obj]
271
+ elif isinstance(obj, dict):
272
+ return {key: json_serializer(value) for key, value in obj.items()}
273
+ else:
274
+ # Convert non-serializable objects to string representation
275
+ return str(obj)
276
+
277
+ try:
278
+ return _json.dumps(json_serializer(obj), indent=indent, **kwargs)
279
+ except Exception as e:
280
+ logging.warning(f"JSON serialization failed: {e}")
281
+ return str(obj)
282
+
283
+ # Monkey patch json.dumps to use our safe version
284
+ json.dumps = safe_json_dumps
285
+
286
  # --- Main Business Logic Functions for Flask ---
287
 
288
  # ADD THIS NEW HELPER FUNCTION SOMEWHERE NEAR THE TOP OF THE FILE