defdownload_assets(asset_name:Union[VideoAssets,str])->str:""" Download a specified asset if it doesn't already exist or is corrupted. Parameters: asset_name (Union[VideoAssets, str]): The name or type of the asset to be downloaded. Returns: str: The filename of the downloaded asset. Example: ```python from supervision.assets import download_assets, VideoAssets download_assets(VideoAssets.VEHICLES) "vehicles.mp4" ``` """filename=asset_name.valueifisinstance(asset_name,VideoAssets)elseasset_nameifnotPath(filename).exists()andfilenameinVIDEO_ASSETS:print(f"Downloading {filename} assets \n")response=get(VIDEO_ASSETS[filename][0],stream=True,allow_redirects=True)response.raise_for_status()file_size=int(response.headers.get("Content-Length",0))folder_path=Path(filename).expanduser().resolve()folder_path.parent.mkdir(parents=True,exist_ok=True)withtqdm.wrapattr(response.raw,"read",total=file_size,desc="",colour="#a351fb")asraw_resp:withfolder_path.open("wb")asfile:copyfileobj(raw_resp,file)elifPath(filename).exists():ifnotis_md5_hash_matching(filename,VIDEO_ASSETS[filename][1]):print("File corrupted. Re-downloading... \n")os.remove(filename)returndownload_assets(filename)print(f"{filename} asset download complete. \n")else:valid_assets=", ".join(asset.valueforassetinVideoAssets)raiseValueError(f"Invalid asset. It should be one of the following: {valid_assets}.")returnfilename
VideoAssets
Bases: Enum
Each member of this enum represents a video asset. The value associated with each
member is the filename of the video.
classVideoAssets(Enum):""" Each member of this enum represents a video asset. The value associated with each member is the filename of the video. | Enum Member | Video Filename | Video URL | |------------------------|----------------------------|---------------------------------------------------------------------------------------| | `VEHICLES` | `vehicles.mp4` | [Link](https://media.roboflow.com/supervision/video-examples/vehicles.mp4) | | `MILK_BOTTLING_PLANT` | `milk-bottling-plant.mp4` | [Link](https://media.roboflow.com/supervision/video-examples/milk-bottling-plant.mp4) | | `VEHICLES_2` | `vehicles-2.mp4` | [Link](https://media.roboflow.com/supervision/video-examples/vehicles-2.mp4) | | `GROCERY_STORE` | `grocery-store.mp4` | [Link](https://media.roboflow.com/supervision/video-examples/grocery-store.mp4) | | `SUBWAY` | `subway.mp4` | [Link](https://media.roboflow.com/supervision/video-examples/subway.mp4) | | `MARKET_SQUARE` | `market-square.mp4` | [Link](https://media.roboflow.com/supervision/video-examples/market-square.mp4) | | `PEOPLE_WALKING` | `people-walking.mp4` | [Link](https://media.roboflow.com/supervision/video-examples/people-walking.mp4) | """# noqa: E501 // docsVEHICLES="vehicles.mp4"MILK_BOTTLING_PLANT="milk-bottling-plant.mp4"VEHICLES_2="vehicles-2.mp4"GROCERY_STORE="grocery-store.mp4"SUBWAY="subway.mp4"MARKET_SQUARE="market-square.mp4"PEOPLE_WALKING="people-walking.mp4"@classmethoddeflist(cls):returnlist(map(lambdac:c.value,cls))