Spaces:
Running
Running
update fn save_json
Browse files- app/ultis.py +11 -5
app/ultis.py
CHANGED
|
@@ -25,20 +25,26 @@ def save_string_as_md(raw_string, save_dir, filename="report.md"):
|
|
| 25 |
with open(file_path, "w", encoding="utf-8") as f:
|
| 26 |
f.write(formatted_str)
|
| 27 |
|
| 28 |
-
print(f"β
Report saved to {file_path}")
|
| 29 |
except Exception as e:
|
| 30 |
-
print(f"β Failed to save report: {e}")
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def save_json(data, save_dir, filename="output.json"):
|
| 33 |
try:
|
| 34 |
file_path = os.path.join(save_dir, filename)
|
| 35 |
|
| 36 |
with open(file_path, "w", encoding="utf-8") as f:
|
| 37 |
-
json.dump(data, f, indent=2, ensure_ascii=False)
|
| 38 |
|
| 39 |
-
print(f"β
JSON saved to {file_path}")
|
| 40 |
except Exception as e:
|
| 41 |
-
print(f"β Failed to save json: {e}")
|
| 42 |
|
| 43 |
async def convert_keyframes_to_base64(ts_result):
|
| 44 |
print("[convert_keyframes_to_base64] start")
|
|
|
|
| 25 |
with open(file_path, "w", encoding="utf-8") as f:
|
| 26 |
f.write(formatted_str)
|
| 27 |
|
| 28 |
+
print(f"β
[{filename}] Report saved to {file_path}")
|
| 29 |
except Exception as e:
|
| 30 |
+
print(f"β [{filename}] Failed to save report: {e}")
|
| 31 |
|
| 32 |
+
def default_encoder(obj):
|
| 33 |
+
try:
|
| 34 |
+
return obj.__dict__
|
| 35 |
+
except Exception:
|
| 36 |
+
return str(obj)
|
| 37 |
+
|
| 38 |
def save_json(data, save_dir, filename="output.json"):
|
| 39 |
try:
|
| 40 |
file_path = os.path.join(save_dir, filename)
|
| 41 |
|
| 42 |
with open(file_path, "w", encoding="utf-8") as f:
|
| 43 |
+
json.dump(data, f, indent=2, ensure_ascii=False, default=default_encoder,)
|
| 44 |
|
| 45 |
+
print(f"β
[{filename}] JSON saved to {file_path}")
|
| 46 |
except Exception as e:
|
| 47 |
+
print(f"β [{filename}]Failed to save json: {e}")
|
| 48 |
|
| 49 |
async def convert_keyframes_to_base64(ts_result):
|
| 50 |
print("[convert_keyframes_to_base64] start")
|