Download python_lora_dataset_builder/pipeline/code_extractor.py from api-relay/sadASDasd: direct link, hf CLI and curl.
- Browser
- Download file 449 Bytes
-
https://huggingface.co/datasets/api-relay/sadASDasd/resolve/main/python_lora_dataset_builder/pipeline/code_extractor.py
- Command line
-
hf download hf://datasets/api-relay/sadASDasd/python_lora_dataset_builder/pipeline/code_extractor.py
-
curl -L -o code_extractor.py https://huggingface.co/datasets/api-relay/sadASDasd/resolve/main/python_lora_dataset_builder/pipeline/code_extractor.py
449 Bytes
| import re | |
| def _norm(x): return "\n".join(line.rstrip() for line in x.replace("\r\n","\n").splitlines()).strip() | |
| def extract_code(output): | |
| blocks=[_norm(x) for x in re.findall(r"```(?:python|py)?\s*\n?(.*?)```",output or "",re.I|re.S) if _norm(x)] | |
| if blocks: return max(blocks,key=len) | |
| text=_norm(output or "") | |
| return text if any(x in text for x in ("def ","class ","import ","from ","for ","while ","if ","try:","async ")) else None | |