Spaces:
Runtime error
Runtime error
Fix: save outputs to separate dir before cleaning workdir
Browse files126 unmodified lines1271281291301311321331311341351361371351381391401413 unmodified lines145146147148149150151152153154155156157158151152153154155156157159160161126 unmodified lines cleaned.simplify(0.4) )
# Save outputs to a Gradio-friendly temp dir (not cleaned up immediately) out_dir = tempfile.mkdtemp(prefix="dtr2_out_")
# save vector gpkg_path = os.path.join(workdir, "crowns_out.gpkg") gpkg_path = os.path.join(out_dir, "crowns_out.gpkg") cleaned.to_file(gpkg_path, driver="GPKG")
# save overlay overlay_path = os.path.join(workdir, "crowns_out.png") overlay_path = os.path.join(out_dir, "crowns_out.png") with rasterio.open(infile) as src: fig, ax = plt.subplots(figsize=(10, 10)) show(src, ax=ax)3 unmodified lines plt.savefig(overlay_path, dpi=220, bbox_inches="tight", pad_inches=0) plt.close(fig)
# Clean up the large working directory (tiles, predictions, etc.) shutil.rmtree(workdir, ignore_errors=True)
stats = {"total_trees": int(len(cleaned))} return overlay_path, gpkg_path, stats, ""
except Exception as e: # Clean up on error too shutil.rmtree(workdir, ignore_errors=True) return None, None, None, f"Error: {e}"
finally: # Clean up temp files to avoid filling disk try: shutil.rmtree(workdir, ignore_errors=True) except Exception: pass
def infer(file_path, environment, confidence): if file_path is None: return None, None, None, "Error: No file uploaded. Please upload a GeoTIFF (.tif) file first."app.py+10-9