Spaces:
Sleeping
Sleeping
Download gaia_agent/answer.py from TheJN/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 797 Bytes
-
https://huggingface.co/spaces/TheJN/Final_Assignment_Template/resolve/main/gaia_agent/answer.py
- Command line
-
hf download hf://spaces/TheJN/Final_Assignment_Template/gaia_agent/answer.py
-
curl -L -o answer.py https://huggingface.co/spaces/TheJN/Final_Assignment_Template/resolve/main/gaia_agent/answer.py
797 Bytes
| import re | |
| def normalize_answer(answer: str) -> str: | |
| """Apply minimal GAIA answer cleanup without changing meaning.""" | |
| cleaned = str(answer).strip() | |
| final_answer_match = re.search( | |
| r"FINAL\s+ANSWER\s*:\s*(.+)\s*$", | |
| cleaned, | |
| flags=re.IGNORECASE | re.DOTALL, | |
| ) | |
| if final_answer_match: | |
| cleaned = final_answer_match.group(1).strip() | |
| cleaned = cleaned.strip("` \n\t") | |
| cleaned = cleaned.strip() | |
| if ( | |
| len(cleaned) >= 2 | |
| and cleaned[0] == cleaned[-1] | |
| and cleaned[0] in {"'", '"'} | |
| ): | |
| cleaned = cleaned[1:-1].strip() | |
| cleaned = cleaned.removesuffix(".").strip() | |
| if re.fullmatch(r"\$?-?\d[\d,]*(?:\.\d+)?", cleaned): | |
| cleaned = cleaned.removeprefix("$").replace(",", "") | |
| return cleaned | |