Spaces:
Sleeping
Sleeping
Download iris/storage/files.py from NextNeural/IRIS: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/NextNeural/IRIS/resolve/main/iris/storage/files.py
- Command line
-
hf download hf://spaces/NextNeural/IRIS/iris/storage/files.py
-
curl -L -o files.py https://huggingface.co/spaces/NextNeural/IRIS/resolve/main/iris/storage/files.py
1.49 kB
| from __future__ import annotations | |
| import shutil | |
| from pathlib import Path | |
| from uuid import uuid4 | |
| from fastapi import UploadFile | |
| from iris.config import Settings | |
| from iris.pipeline.video import validate_video_filename | |
| class FileStore: | |
| def __init__(self, settings: Settings) -> None: | |
| self.settings = settings | |
| def video_dir(self, video_id: str) -> Path: | |
| return self.settings.data_dir / "videos" / video_id | |
| def video_path(self, video_id: str, filename: str) -> Path: | |
| return self.video_dir(video_id) / "source" / filename | |
| def audio_path(self, video_id: str) -> Path: | |
| return self.video_dir(video_id) / "audio" / "audio.wav" | |
| def transcript_path(self, video_id: str) -> Path: | |
| return self.video_dir(video_id) / "transcript" / "transcript.json" | |
| def embeddings_path(self, video_id: str) -> Path: | |
| return self.video_dir(video_id) / "embeddings" / "speech.npy" | |
| def frames_dir(self, video_id: str) -> Path: | |
| return self.video_dir(video_id) / "frames" | |
| def save_upload(self, upload: UploadFile) -> tuple[str, Path]: | |
| filename = Path(upload.filename or "video").name | |
| validate_video_filename(filename) | |
| video_id = str(uuid4()) | |
| destination = self.video_path(video_id, filename) | |
| destination.parent.mkdir(parents=True, exist_ok=True) | |
| with destination.open("wb") as output: | |
| shutil.copyfileobj(upload.file, output) | |
| return video_id, destination | |