sanjaystarc commited on
Commit
55d1d72
·
verified ·
1 Parent(s): 18b02aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -43,7 +43,7 @@ SYSTEM_INSTRUCTION = (
43
  "2. **Code:** If the question requires calculation, aggregation, or visualization, you MUST generate Python code to execute against the 'df' DataFrame. "
44
  " - The DataFrame is already loaded as a variable named 'df'. Do NOT redefine it. "
45
  " - Use Streamlit functions for simple outputs: `st.dataframe(...)`, `st.bar_chart()`, `st.line_chart()`. "
46
- " - For custom, complex plots, you MUST use Matplotlib: start with `plt.figure()`, then use `plt.` commands (like `plt.hist()`), and finish with `st.pyplot(plt)` to display the plot. "
47
  " - Ensure the code is self-contained and ready to execute."
48
  )
49
 
@@ -162,8 +162,12 @@ if uploaded:
162
  'np': np,
163
  'plt': plt, # Explicitly include pyplot here
164
  }
 
 
 
 
165
  # Executing the code within the local scope
166
- exec(code, globals(), local_scope)
167
 
168
  # FIX: Explicitly close all Matplotlib figures to prevent cross-run contamination
169
  plt.close('all')
 
43
  "2. **Code:** If the question requires calculation, aggregation, or visualization, you MUST generate Python code to execute against the 'df' DataFrame. "
44
  " - The DataFrame is already loaded as a variable named 'df'. Do NOT redefine it. "
45
  " - Use Streamlit functions for simple outputs: `st.dataframe(...)`, `st.bar_chart()`, `st.line_chart()`. "
46
+ " - For **ALL** custom, complex plots, you MUST follow this strict Matplotlib sequence: **Start with `plt.figure()`, use `plt.` commands for plotting, and explicitly end with `st.pyplot(plt)`** to display the output. "
47
  " - Ensure the code is self-contained and ready to execute."
48
  )
49
 
 
162
  'np': np,
163
  'plt': plt, # Explicitly include pyplot here
164
  }
165
+
166
+ # Append a neutral statement to the code to prevent implicit Streamlit display of the last value
167
+ final_code = code + "\nNone"
168
+
169
  # Executing the code within the local scope
170
+ exec(final_code, globals(), local_scope)
171
 
172
  # FIX: Explicitly close all Matplotlib figures to prevent cross-run contamination
173
  plt.close('all')