Spaces:
Running
on
Zero
Running
on
Zero
import os | |
import uuid | |
import torch | |
from gradio.utils import get_upload_folder | |
def save_tensor_to_file(tensor, prefix="tensor"): | |
upload_dir = get_upload_folder() | |
os.makedirs(upload_dir, exist_ok=True) | |
path = os.path.join(upload_dir, f"{prefix}_{uuid.uuid4().hex}.pt") | |
torch.save(tensor, path) | |
return path | |
def load_tensor_from_file(path, map_location=None): | |
# Use weights_only=True for security and to suppress FutureWarning (only tensors are loaded in this app) | |
return torch.load(path, map_location=map_location, weights_only=True) |