Spaces:
Configuration error
Configuration error
oremaz
commited on
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -349,95 +349,95 @@ research_tool = FunctionTool.from_defaults(
|
|
| 349 |
|
| 350 |
def execute_python_code(code: str) -> str:
|
| 351 |
try:
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
|
|
|
|
|
|
|
|
|
| 433 |
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
return str(exec_locals['result'])
|
| 439 |
-
else:
|
| 440 |
-
return "Code executed successfully"
|
| 441 |
|
| 442 |
except Exception as e:
|
| 443 |
return f"Code execution failed: {str(e)}"
|
|
|
|
| 349 |
|
| 350 |
def execute_python_code(code: str) -> str:
|
| 351 |
try:
|
| 352 |
+
safe_globals = {
|
| 353 |
+
"__builtins__": {
|
| 354 |
+
"len": len, "str": str, "int": int, "float": float,
|
| 355 |
+
"list": list, "dict": dict, "sum": sum, "max": max, "min": min,
|
| 356 |
+
"round": round, "abs": abs, "sorted": sorted, "enumerate": enumerate,
|
| 357 |
+
"range": range, "zip": zip, "map": map, "filter": filter,
|
| 358 |
+
"any": any, "all": all, "type": type, "isinstance": isinstance,
|
| 359 |
+
"print": print, "open": open, "bool": bool, "set": set, "tuple": tuple
|
| 360 |
+
},
|
| 361 |
+
# Core Python modules
|
| 362 |
+
"math": __import__("math"),
|
| 363 |
+
"datetime": __import__("datetime"),
|
| 364 |
+
"re": __import__("re"),
|
| 365 |
+
"os": __import__("os"),
|
| 366 |
+
"sys": __import__("sys"),
|
| 367 |
+
"json": __import__("json"),
|
| 368 |
+
"csv": __import__("csv"),
|
| 369 |
+
"random": __import__("random"),
|
| 370 |
+
"itertools": __import__("itertools"),
|
| 371 |
+
"collections": __import__("collections"),
|
| 372 |
+
"functools": __import__("functools"),
|
| 373 |
+
|
| 374 |
+
# Data Science and Numerical Computing
|
| 375 |
+
"numpy": __import__("numpy"),
|
| 376 |
+
"np": __import__("numpy"),
|
| 377 |
+
"pandas": __import__("pandas"),
|
| 378 |
+
"pd": __import__("pandas"),
|
| 379 |
+
"scipy": __import__("scipy"),
|
| 380 |
+
|
| 381 |
+
# Visualization
|
| 382 |
+
"matplotlib": __import__("matplotlib"),
|
| 383 |
+
"plt": __import__("matplotlib.pyplot"),
|
| 384 |
+
"seaborn": __import__("seaborn"),
|
| 385 |
+
"sns": __import__("seaborn"),
|
| 386 |
+
"plotly": __import__("plotly"),
|
| 387 |
+
|
| 388 |
+
# Machine Learning
|
| 389 |
+
"sklearn": __import__("sklearn"),
|
| 390 |
+
"xgboost": __import__("xgboost"),
|
| 391 |
+
"lightgbm": __import__("lightgbm"),
|
| 392 |
+
|
| 393 |
+
# Statistics
|
| 394 |
+
"statistics": __import__("statistics"),
|
| 395 |
+
"statsmodels": __import__("statsmodels"),
|
| 396 |
+
|
| 397 |
+
# Image Processing
|
| 398 |
+
"PIL": __import__("PIL"),
|
| 399 |
+
"cv2": __import__("cv2"),
|
| 400 |
+
"skimage": __import__("skimage"),
|
| 401 |
+
|
| 402 |
+
# Network and Web
|
| 403 |
+
"requests": __import__("requests"),
|
| 404 |
+
"urllib": __import__("urllib"),
|
| 405 |
+
|
| 406 |
+
# Text Processing
|
| 407 |
+
"nltk": __import__("nltk"),
|
| 408 |
+
"spacy": __import__("spacy"),
|
| 409 |
+
|
| 410 |
+
# Time Series
|
| 411 |
+
"pytz": __import__("pytz"),
|
| 412 |
+
|
| 413 |
+
# Utilities
|
| 414 |
+
"tqdm": __import__("tqdm"),
|
| 415 |
+
"pickle": __import__("pickle"),
|
| 416 |
+
"gzip": __import__("gzip"),
|
| 417 |
+
"base64": __import__("base64"),
|
| 418 |
+
"hashlib": __import__("hashlib"),
|
| 419 |
+
"uuid": __import__("uuid"),
|
| 420 |
+
|
| 421 |
+
# Scientific Computing
|
| 422 |
+
"sympy": __import__("sympy"),
|
| 423 |
+
"networkx": __import__("networkx"),
|
| 424 |
+
|
| 425 |
+
# Database
|
| 426 |
+
"sqlite3": __import__("sqlite3"),
|
| 427 |
+
|
| 428 |
+
# Parallel Processing
|
| 429 |
+
"multiprocessing": __import__("multiprocessing"),
|
| 430 |
+
"threading": __import__("threading"),
|
| 431 |
+
"concurrent": __import__("concurrent"),
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
exec_locals = {}
|
| 435 |
+
exec(code, safe_globals, exec_locals)
|
| 436 |
|
| 437 |
+
if 'result' in exec_locals:
|
| 438 |
+
return str(exec_locals['result'])
|
| 439 |
+
else:
|
| 440 |
+
return "Code executed successfully"
|
|
|
|
|
|
|
|
|
|
| 441 |
|
| 442 |
except Exception as e:
|
| 443 |
return f"Code execution failed: {str(e)}"
|