Spaces:
Sleeping
Sleeping
Download structured_text.py from dellweb3/workos-office: direct link, hf CLI and curl.
- Browser
- Download file 578 Bytes
-
https://huggingface.co/spaces/dellweb3/workos-office/resolve/main/structured_text.py
- Command line
-
hf download hf://spaces/dellweb3/workos-office/structured_text.py
-
curl -L -o structured_text.py https://huggingface.co/spaces/dellweb3/workos-office/resolve/main/structured_text.py
578 Bytes
| """Decode model JSON wrappers without changing, inventing or dropping document fields.""" | |
| import json | |
| import re | |
| def json_object(content): | |
| value=content | |
| for _ in range(5): | |
| if isinstance(value,dict):return value | |
| if isinstance(value,list) and len(value)==1: | |
| value=value[0] | |
| elif isinstance(value,str): | |
| text=re.sub(r'^```(?:json)?\s*|\s*```$','',value.strip(),flags=re.I) | |
| value=json.loads(text,strict=False) | |
| else:raise ValueError('Expected one JSON object') | |
| raise ValueError('Too many JSON wrappers') | |