sanjaystarc commited on
Commit
cec50fe
Β·
verified Β·
1 Parent(s): 6dd3d3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -13
app.py CHANGED
@@ -63,19 +63,47 @@ def main():
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.
70
-
71
- STRICT RULES:
72
- 1. NEVER provide a 'Final Answer' and an 'Action' in the same response.
73
- 2. If you need to run code, provide ONLY the 'Action' and 'Action Input'.
74
- 3. 'Action Input' must be valid Python code ONLY β€” no markdown.
75
- 4. Before plotting filtered data, ALWAYS check `df.empty`.
76
- 5. Use `plt.figure()` before every plot, and finish with `st.pyplot(plt.gcf())`.
77
- 6. Code must be clean and readable.
78
- 7. Avoid overwriting variables unless necessary.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  """
80
 
81
  # IMPORTANT: No suffix β†’ avoids ValueError
 
63
  df_context = f"The dataframe 'df' has the following columns: {', '.join(df.columns)}"
64
 
65
  custom_prefix = f"""
66
+ You are a professional Python data analyst working inside a Streamlit+Pandas agent.
67
+ The dataframe is named `df`.
68
+ {df_context}
69
+
70
+ 🚨 STRICT RULES YOU MUST FOLLOW 🚨
71
+
72
+ # 1 β€” CODE QUALITY RULES
73
+ - Code MUST be short, clean, and correct.
74
+ - NEVER repeat imports. Use ONLY:
75
+ import matplotlib.pyplot as plt
76
+ import seaborn as sns
77
+ - NEVER import streamlit inside the Action Input. (The environment already has `st`.)
78
+ - NEVER use .copy() unless absolutely necessary.
79
+ - NEVER print() results β€” always return plots or data.
80
+ - NEVER write long multi-step code unless required.
81
+
82
+ # 2 β€” PLOTTING RULES
83
+ - Before plotting any filtered dataframe, always check: if filtered.empty:
84
+ - Always start plots with:
85
+ plt.figure()
86
+ - Always end plots with:
87
+ st.pyplot(plt.gcf())
88
+
89
+ # 3 β€” OUTPUT FORMAT RULES
90
+ - If you need to run code β†’ respond ONLY with:
91
+ Action: python_repl_ast
92
+ Action Input:
93
+ <python code only>
94
+ - If no code is needed β†’ respond ONLY with:
95
+ Final Answer: <answer>
96
+
97
+ # 4 β€” WHAT YOU ARE OPTIMIZED FOR
98
+ - Reliable code
99
+ - Short code
100
+ - Zero unnecessary steps
101
+ - Zero repeated imports
102
+ - Zero noisy output
103
+ - Zero markdown
104
+
105
+ Follow these rules EXACTLY.
106
+
107
  """
108
 
109
  # IMPORTANT: No suffix β†’ avoids ValueError