Nipun Claude commited on
Commit
790ce09
·
1 Parent(s): 318ac03

Fix matplotlib high DPI configuration in code execution environment

Browse files

- Added explicit matplotlib DPI settings in run_safe_exec function
- Ensured 600 DPI configuration persists in dynamic code execution
- Fixed Streamlit image display to use full resolution without width limits
- Plots should now generate and display at true high resolution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

Files changed (2) hide show
  1. app.py +3 -3
  2. src.py +13 -0
app.py CHANGED
@@ -498,8 +498,8 @@ def show_custom_response(response):
498
  try:
499
  if isinstance(content, str) and (content.endswith('.png') or content.endswith('.jpg')):
500
  if os.path.exists(content):
501
- # Display image without showing filename
502
- st.image(content, width=800)
503
  return {"is_image": True}
504
  # Also handle case where content shows filename but we want to show image
505
  elif isinstance(content, str) and any(ext in content for ext in ['.png', '.jpg']):
@@ -509,7 +509,7 @@ def show_custom_response(response):
509
  if filename_match:
510
  filename = filename_match.group(1)
511
  if os.path.exists(filename):
512
- st.image(filename, width=800)
513
  return {"is_image": True}
514
  except:
515
  pass
 
498
  try:
499
  if isinstance(content, str) and (content.endswith('.png') or content.endswith('.jpg')):
500
  if os.path.exists(content):
501
+ # Display image at full resolution without width restriction
502
+ st.image(content, use_column_width=True)
503
  return {"is_image": True}
504
  # Also handle case where content shows filename but we want to show image
505
  elif isinstance(content, str) and any(ext in content for ext in ['.png', '.jpg']):
 
509
  if filename_match:
510
  filename = filename_match.group(1)
511
  if os.path.exists(filename):
512
+ st.image(filename, use_column_width=True)
513
  return {"is_image": True}
514
  except:
515
  pass
src.py CHANGED
@@ -144,6 +144,19 @@ def ask_question(model_name, question):
144
  def run_safe_exec(full_code, df=None, extra_globals=None):
145
  """Safely execute generated code and handle errors"""
146
  local_vars = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  global_vars = {
148
  'pd': pd, 'plt': plt, 'os': os,
149
  'sns': __import__('seaborn'),
 
144
  def run_safe_exec(full_code, df=None, extra_globals=None):
145
  """Safely execute generated code and handle errors"""
146
  local_vars = {}
147
+
148
+ # Force matplotlib to use high DPI settings in exec environment
149
+ plt.style.use('vayuchat.mplstyle')
150
+ plt.rcParams['figure.dpi'] = 600
151
+ plt.rcParams['savefig.dpi'] = 600
152
+ plt.rcParams['figure.figsize'] = [14, 8]
153
+ plt.rcParams['font.size'] = 14
154
+ plt.rcParams['axes.titlesize'] = 16
155
+ plt.rcParams['axes.labelsize'] = 14
156
+ plt.rcParams['xtick.labelsize'] = 12
157
+ plt.rcParams['ytick.labelsize'] = 12
158
+ plt.rcParams['legend.fontsize'] = 12
159
+
160
  global_vars = {
161
  'pd': pd, 'plt': plt, 'os': os,
162
  'sns': __import__('seaborn'),