Spaces:
Runtime error
Runtime error
persistant upload
Browse files32 unmodified lines33343536373839404142434490 unmodified lines13513613713813914014114214314414532 unmodified lines# configWEIGHTS = {"Forest": os.path.join(WEIGHT_DIR, "230103_randresize_full.pth"),# "Urban": os.path.join(WEIGHT_DIR, "urban_trees_Cambridge_20230630.pth"),# "Flexi": os.path.join(WEIGHT_DIR, "250312_flexi.pth"),}DEFAULT_ENV = "Forest"DEVICE = "cuda" if torch.cuda.is_available() else "cpu"# Keep PyTorch from oversubscribing CPU90 unmodified linesdef infer(file_path, environment, confidence):return run_detectree2(file_path, environment, confidence)def save_to_persistent(uploaded_file):os.makedirs(WEIGHT_DIR, exist_ok=True)dest = os.path.join(WEIGHT_DIR, uploaded_file.orig_name)shutil.copy2(uploaded_file.name, dest)return f"✅ Saved {uploaded_file.orig_name} to {WEIGHT_DIR}"def list_persistent():out = []32 unmodified lines33343536373839404142434490 unmodified lines13513613713813914014114214314414514614714814915015115215315415515615715832 unmodified lines# configWEIGHTS = {"Flexible": os.path.join(WEIGHT_DIR, "250312_flexi.pth"),"Forest": os.path.join(WEIGHT_DIR, "230103_randresize_full.pth"),"Urban": os.path.join(WEIGHT_DIR, "urban_trees_Cambridge_20230630.pth"),}DEFAULT_ENV = "Flexible"DEVICE = "cuda" if torch.cuda.is_available() else "cpu"# Keep PyTorch from oversubscribing CPU90 unmodified linesdef infer(file_path, environment, confidence):return run_detectree2(file_path, environment, confidence)def save_to_persistent(path):import tracebacktry:os.makedirs(WEIGHT_DIR, exist_ok=True)fname = os.path.basename(path)dest = os.path.join(WEIGHT_DIR, fname)# optional: space check so we fail gracefullytotal, used, free = shutil.disk_usage("/data")need = os.path.getsize(path)if need > free:return f"❌ Not enough space: need {need/1024**2:.2f} MB, free {free/1024**2:.2f} MB."shutil.copy2(path, dest)return f"✅ Saved {fname} to {WEIGHT_DIR}"except Exception as e:return "❌ Upload failed:\n" + traceback.format_exc()def list_persistent():out = []
app.py+21-8