MCPcopy Create free account
hub / github.com/AlayaLab/Hive / load_numpy

Function load_numpy

models/flowsep/diffusers/utils/testing_utils.py:228–252  ·  view source on GitHub ↗
(arry: Union[str, np.ndarray], local_path: Optional[str] = None)

Source from the content-addressed store, hash-verified

226
227
228def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray:
229 if isinstance(arry, str):
230 # local_path = "/home/patrick_huggingface_co/"
231 if local_path is not None:
232 # local_path can be passed to correct images of tests
233 return os.path.join(local_path, "/".join([arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]]))
234 elif arry.startswith("http://") or arry.startswith("https://"):
235 response = requests.get(arry)
236 response.raise_for_status()
237 arry = np.load(BytesIO(response.content))
238 elif os.path.isfile(arry):
239 arry = np.load(arry)
240 else:
241 raise ValueError(
242 f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path"
243 )
244 elif isinstance(arry, np.ndarray):
245 pass
246 else:
247 raise ValueError(
248 "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a"
249 " ndarray."
250 )
251
252 return arry
253
254
255def load_pt(url: str):

Callers 1

load_hf_numpyFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected