File size: 782 Bytes
7474ab2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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}