derektan commited on
Commit
e5efc3c
·
1 Parent(s): 0c5b121

Attempt to remove flickering

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. env.py +4 -1
app.py CHANGED
@@ -315,7 +315,7 @@ with gr.Blocks(title="Search-TTA (Simplified)", theme=gr.themes.Base()) as demo:
315
  with gr.Column():
316
  gr.Markdown("### Live Heatmap Output")
317
  # gr.Markdown("### Live Heatmap (with TTA)")
318
- display_img_tta = gr.Image(label="Heatmap (TTA)", type="filepath", height=400) # 512
319
  status_tta = gr.Markdown("")
320
  # gr.Markdown("### Live Heatmap (without TTA)")
321
  display_img_no_tta = gr.Image(label="Heatmap (no TTA)", type="filepath", height=400) # 512
 
315
  with gr.Column():
316
  gr.Markdown("### Live Heatmap Output")
317
  # gr.Markdown("### Live Heatmap (with TTA)")
318
+ display_img_tta = gr.Image(label="Heatmap (TTA per 20 steps)", type="filepath", height=400) # 512
319
  status_tta = gr.Markdown("")
320
  # gr.Markdown("### Live Heatmap (without TTA)")
321
  display_img_no_tta = gr.Image(label="Heatmap (no TTA)", type="filepath", height=400) # 512
env.py CHANGED
@@ -843,7 +843,10 @@ class Env():
843
  plt.tight_layout()
844
  os.makedirs(save_dir, exist_ok=True)
845
  out_path = os.path.join(save_dir, f"{step}.png")
846
- fig.savefig(out_path, dpi=100)
 
 
 
847
  plt.close(fig)
848
  return out_path
849
 
 
843
  plt.tight_layout()
844
  os.makedirs(save_dir, exist_ok=True)
845
  out_path = os.path.join(save_dir, f"{step}.png")
846
+ # Save atomically: write to temp file then move into place so the poller never sees a partial file.
847
+ tmp_path = out_path + ".tmp"
848
+ fig.savefig(tmp_path, dpi=100, format='png')
849
+ os.replace(tmp_path, out_path) # atomic on same filesystem
850
  plt.close(fig)
851
  return out_path
852