Spaces:
Runtime error
Runtime error
| import math, os, json, subprocess | |
| from typing import Any, Dict | |
| def calc(expression: str) -> str: | |
| try: | |
| allowed = {k: getattr(math, k) for k in dir(math) if not k.startswith('_')} | |
| allowed['abs'] = abs | |
| res = eval(expression, {'__builtins__': {}}, allowed) | |
| return str(res) | |
| except Exception as e: | |
| return f"Calculator error: {e}" | |
| def read_file(path: str, max_chars: int = 4000) -> str: | |
| try: | |
| with open(path, 'r', encoding='utf-8', errors='ignore') as f: | |
| return f.read()[:max_chars] | |
| except Exception as e: | |
| return f"File read error: {e}" | |