Spaces:
Sleeping
Sleeping
Download utils.py from rohan131/Deep_Research: direct link, hf CLI and curl.
- Browser
- Download file 581 Bytes
-
https://huggingface.co/spaces/rohan131/Deep_Research/resolve/main/utils.py
- Command line
-
hf download hf://spaces/rohan131/Deep_Research/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/rohan131/Deep_Research/resolve/main/utils.py
581 Bytes
| import re | |
| def extract_json(text: str) -> str: | |
| """ | |
| Extracts JSON from LLM output, removing markdown triple backticks. | |
| Falls back to grabbing first {...} block if no fenced block detected. | |
| """ | |
| # Try triple backticks with optional 'json' | |
| match = re.search(r"``````", text, re.DOTALL) | |
| if match: | |
| return match.group(1).strip() | |
| # Fallback: Try to find first JSON object in text without triple backticks | |
| match = re.search(r"(\{.*\})", text, re.DOTALL) | |
| if match: | |
| return match.group(1).strip() | |
| return text.strip() | |