NeoLUS-AI / weights_tools.py
Ryonaly's picture
Create weights_tools.py
7474ab2 verified
raw
history blame contribute delete
782 Bytes
import os, zipfile, shutil
BASE = "models"
def ensure_dir(path: str):
os.makedirs(path, exist_ok=True)
def save_and_unpack(files, target: str):
"""files: list of temp file paths from Gradio; target: rtlucassen/medivlad/segmentation"""
dst = os.path.join(BASE, target)
ensure_dir(dst)
saved = []
for f in files or []:
name = os.path.basename(f.name if hasattr(f, "name") else str(f))
dst_path = os.path.join(dst, name)
shutil.copyfile(f.name if hasattr(f, "name") else f, dst_path)
saved.append(dst_path)
if name.lower().endswith(".zip"):
with zipfile.ZipFile(dst_path, "r") as z:
z.extractall(dst)
return {"target": target, "saved": [os.path.basename(s) for s in saved], "dst": dst}