Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,9 +58,14 @@ def main():
|
|
| 58 |
max_retries=6,
|
| 59 |
)
|
| 60 |
|
| 61 |
-
# Updated Prefix
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
You are working with a pandas dataframe in Python. The name of the dataframe is `df`.
|
|
|
|
|
|
|
| 64 |
You should use the tools below to answer the question posed of you.
|
| 65 |
|
| 66 |
STRICT FORMATTING RULES:
|
|
@@ -69,7 +74,7 @@ def main():
|
|
| 69 |
3. Your 'Action Input' must be valid Python code and ONLY Python code. No markdown backticks.
|
| 70 |
4. Before creating a visualization for filtered data, always check if the filtered dataframe is empty.
|
| 71 |
5. For plots, use `plt.figure()` and end with `st.pyplot(plt.gcf())`.
|
| 72 |
-
6. The
|
| 73 |
7. Avoide over writing .
|
| 74 |
"""
|
| 75 |
|
|
@@ -81,6 +86,7 @@ def main():
|
|
| 81 |
"""
|
| 82 |
|
| 83 |
# Create the Pandas Agent
|
|
|
|
| 84 |
agent = create_pandas_dataframe_agent(
|
| 85 |
llm,
|
| 86 |
df,
|
|
@@ -89,6 +95,7 @@ def main():
|
|
| 89 |
allow_dangerous_code=True,
|
| 90 |
prefix=custom_prefix,
|
| 91 |
suffix=custom_suffix,
|
|
|
|
| 92 |
handle_parsing_errors=True,
|
| 93 |
agent_executor_kwargs={
|
| 94 |
"handle_parsing_errors": True
|
|
|
|
| 58 |
max_retries=6,
|
| 59 |
)
|
| 60 |
|
| 61 |
+
# Updated Prefix: We manually include the DF context here since we are using a custom suffix
|
| 62 |
+
# This satisfies the requirement to have DF info without triggering the ValueError
|
| 63 |
+
df_context = f"The dataframe 'df' has the following columns: {', '.join(df.columns)}"
|
| 64 |
+
|
| 65 |
+
custom_prefix = f"""
|
| 66 |
You are working with a pandas dataframe in Python. The name of the dataframe is `df`.
|
| 67 |
+
{df_context}
|
| 68 |
+
|
| 69 |
You should use the tools below to answer the question posed of you.
|
| 70 |
|
| 71 |
STRICT FORMATTING RULES:
|
|
|
|
| 74 |
3. Your 'Action Input' must be valid Python code and ONLY Python code. No markdown backticks.
|
| 75 |
4. Before creating a visualization for filtered data, always check if the filtered dataframe is empty.
|
| 76 |
5. For plots, use `plt.figure()` and end with `st.pyplot(plt.gcf())`.
|
| 77 |
+
6. The visual and code must be clear and beautiful.
|
| 78 |
7. Avoide over writing .
|
| 79 |
"""
|
| 80 |
|
|
|
|
| 86 |
"""
|
| 87 |
|
| 88 |
# Create the Pandas Agent
|
| 89 |
+
# FIX: Set include_df_in_prompt=False to allow the use of a custom suffix
|
| 90 |
agent = create_pandas_dataframe_agent(
|
| 91 |
llm,
|
| 92 |
df,
|
|
|
|
| 95 |
allow_dangerous_code=True,
|
| 96 |
prefix=custom_prefix,
|
| 97 |
suffix=custom_suffix,
|
| 98 |
+
include_df_in_prompt=False, # Mandatory when using custom suffix
|
| 99 |
handle_parsing_errors=True,
|
| 100 |
agent_executor_kwargs={
|
| 101 |
"handle_parsing_errors": True
|