Spaces:
Configuration error
Configuration error
Download space/src/utils/json_cleaner.py from lifedebugger/cs-ai-sakura-dev: direct link, hf CLI and curl.
- Browser
- Download file 401 Bytes
-
https://huggingface.co/spaces/lifedebugger/cs-ai-sakura-dev/resolve/main/space/src/utils/json_cleaner.py
- Command line
-
hf download hf://spaces/lifedebugger/cs-ai-sakura-dev/space/src/utils/json_cleaner.py
-
curl -L -o json_cleaner.py https://huggingface.co/spaces/lifedebugger/cs-ai-sakura-dev/resolve/main/space/src/utils/json_cleaner.py
401 Bytes
| import json | |
| from typing import Dict | |
| def clean_response(res:str): | |
| try: | |
| raw = res.strip() | |
| # bersihin block fencing kalau ada | |
| if raw.startswith("```"): | |
| import re | |
| raw = re.sub(r"^```[a-zA-Z]*\n?", "", raw) | |
| raw = re.sub(r"\n?```$", "", raw) | |
| j_res = json.loads(raw) | |
| return j_res | |
| except Exception as e: | |
| return None |