Update app.py
Browse files
app.py
CHANGED
|
@@ -178,7 +178,7 @@ def safe_exec_code(code, df, capture_charts=True, interactive=False, extra_globa
|
|
| 178 |
return (f"Generated code references missing columns: {missing_cols}\nPlease adjust your prompt or data.",
|
| 179 |
[])
|
| 180 |
|
| 181 |
-
# Expanded safe built-ins.
|
| 182 |
safe_builtins = {
|
| 183 |
"abs": abs,
|
| 184 |
"min": min,
|
|
@@ -197,6 +197,11 @@ def safe_exec_code(code, df, capture_charts=True, interactive=False, extra_globa
|
|
| 197 |
"pd": pd,
|
| 198 |
"plt": plt,
|
| 199 |
"str": str,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
"__import__": __import__,
|
| 201 |
}
|
| 202 |
safe_globals = {"__builtins__": safe_builtins, "df": df, "plt": plt, "charts": []}
|
|
@@ -234,6 +239,8 @@ def safe_exec_code(code, df, capture_charts=True, interactive=False, extra_globa
|
|
| 234 |
error_details += "\nHint: The generated code might be using a fixed datetime format. Consider using pd.to_datetime() without a fixed format or with dayfirst=True."
|
| 235 |
if "KeyError" in error_details:
|
| 236 |
error_details += "\nHint: The generated code might be referencing columns that do not exist in your DataFrame."
|
|
|
|
|
|
|
| 237 |
return f"An error occurred during code execution:\n{error_details}", safe_globals["charts"]
|
| 238 |
|
| 239 |
if capture_charts and not safe_globals["charts"]:
|
|
|
|
| 178 |
return (f"Generated code references missing columns: {missing_cols}\nPlease adjust your prompt or data.",
|
| 179 |
[])
|
| 180 |
|
| 181 |
+
# Expanded safe built-ins. Including float, int, bool, etc.
|
| 182 |
safe_builtins = {
|
| 183 |
"abs": abs,
|
| 184 |
"min": min,
|
|
|
|
| 197 |
"pd": pd,
|
| 198 |
"plt": plt,
|
| 199 |
"str": str,
|
| 200 |
+
"float": float,
|
| 201 |
+
"int": int,
|
| 202 |
+
"bool": bool,
|
| 203 |
+
"complex": complex,
|
| 204 |
+
"round": round,
|
| 205 |
"__import__": __import__,
|
| 206 |
}
|
| 207 |
safe_globals = {"__builtins__": safe_builtins, "df": df, "plt": plt, "charts": []}
|
|
|
|
| 239 |
error_details += "\nHint: The generated code might be using a fixed datetime format. Consider using pd.to_datetime() without a fixed format or with dayfirst=True."
|
| 240 |
if "KeyError" in error_details:
|
| 241 |
error_details += "\nHint: The generated code might be referencing columns that do not exist in your DataFrame."
|
| 242 |
+
if "NameError" in error_details:
|
| 243 |
+
error_details += "\nHint: Ensure that all required built-in types and libraries (like float, int, etc.) are included in the safe built-ins."
|
| 244 |
return f"An error occurred during code execution:\n{error_details}", safe_globals["charts"]
|
| 245 |
|
| 246 |
if capture_charts and not safe_globals["charts"]:
|