Download calculator/utils.py from PrashanthB461/Arithematical_Operations: direct link, hf CLI and curl.
- Browser
- Download file 529 Bytes
-
https://huggingface.co/spaces/PrashanthB461/Arithematical_Operations/resolve/main/calculator/utils.py
- Command line
-
hf download hf://spaces/PrashanthB461/Arithematical_Operations/calculator/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/PrashanthB461/Arithematical_Operations/resolve/main/calculator/utils.py
529 Bytes
| import re | |
| def extract_operation(question): | |
| ops = { | |
| "add": "add", "plus": "add", "+": "add", | |
| "subtract": "subtract", "minus": "subtract", "-": "subtract", | |
| "multiply": "multiply", "times": "multiply", "*": "multiply", | |
| "divide": "divide", "over": "divide", "/": "divide" | |
| } | |
| for word in question.lower().split(): | |
| if word in ops: | |
| return ops[word] | |
| return None | |
| def extract_numbers(question): | |
| return [float(n) for n in re.findall(r"[-+]?\d*\.\d+|\d+", question)] | |