Spaces:
Runtime error
Runtime error
Download llm_parsing.py from PrecisionContent/DU: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/PrecisionContent/DU/resolve/main/llm_parsing.py
- Command line
-
hf download hf://spaces/PrecisionContent/DU/llm_parsing.py
-
curl -L -o llm_parsing.py https://huggingface.co/spaces/PrecisionContent/DU/resolve/main/llm_parsing.py
1.01 kB
| import re | |
| def parse_list(ret, what): | |
| lines = ret.splitlines() | |
| inlist = False | |
| retlist = [] | |
| for line in lines: | |
| line = line.strip() | |
| if line == "": | |
| inlist = False | |
| elif line[-1] == ":": | |
| if line[:-1].upper() == what.upper(): | |
| inlist = True | |
| else: | |
| inlist = False | |
| elif inlist: | |
| if line.startswith("- "): | |
| item = line[2:].strip() | |
| else: | |
| item = line | |
| retlist.append(item) | |
| print(f"===Parsed list {what}: {retlist}") | |
| return retlist | |
| def extract_document_from_response(ret): | |
| r = re.sub(r'^<derivative-document>(.*)</derivative-document>$', r'\1', ret, flags=re.DOTALL) | |
| r = re.sub(r'^<revised-document>(.*)</revised-document>$', r'\1', r, flags=re.DOTALL) | |
| r = re.sub(r'^<document>(.*)</document>$', r'\1', r, flags=re.DOTALL) | |
| return r | |