Spaces:
Running
on
Zero
Running
on
Zero
added test for framing
Browse files- .gitignore +87 -0
- assets/test_video.mp4 +3 -0
- src/.gitignore +0 -1
- src/app.py +1 -1
- tests/__init__.py +1 -0
- tests/test_video.py +27 -0
.gitignore
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
*.egg-info/
|
24 |
+
.installed.cfg
|
25 |
+
*.egg
|
26 |
+
|
27 |
+
# Virtual environment
|
28 |
+
venv/
|
29 |
+
env/
|
30 |
+
ENV/
|
31 |
+
.venv/
|
32 |
+
.env/
|
33 |
+
pip-wheel-metadata/
|
34 |
+
|
35 |
+
# PyInstaller
|
36 |
+
*.manifest
|
37 |
+
*.spec
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
|
51 |
+
# Pytest
|
52 |
+
.pytest_cache/
|
53 |
+
|
54 |
+
# MyPy
|
55 |
+
.mypy_cache/
|
56 |
+
.dmypy.json
|
57 |
+
dmypy.json
|
58 |
+
|
59 |
+
# Pyre
|
60 |
+
.pyre/
|
61 |
+
|
62 |
+
# Pytype
|
63 |
+
.pytype/
|
64 |
+
|
65 |
+
# Cython debug symbols
|
66 |
+
cython_debug/
|
67 |
+
|
68 |
+
# VS Code settings
|
69 |
+
.vscode/
|
70 |
+
|
71 |
+
# Jupyter Notebook checkpoints
|
72 |
+
.ipynb_checkpoints/
|
73 |
+
|
74 |
+
# dotenv environment files
|
75 |
+
*.env
|
76 |
+
*.env.*
|
77 |
+
|
78 |
+
# IDEs
|
79 |
+
.idea/
|
80 |
+
*.sublime-project
|
81 |
+
*.sublime-workspace
|
82 |
+
|
83 |
+
# Logs
|
84 |
+
*.log
|
85 |
+
|
86 |
+
# macOS
|
87 |
+
.DS_Store
|
assets/test_video.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f831e2c34ef1167c7eea14e6673069c1a2b5b6c8e9ec9b360ef5bce6ef0ecbc0
|
3 |
+
size 1064736
|
src/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
.env
|
|
|
|
src/app.py
CHANGED
@@ -27,6 +27,7 @@ model = Gemma3ForConditionalGeneration.from_pretrained(
|
|
27 |
)
|
28 |
|
29 |
def get_frames(video_path: str, max_images: int) -> list[tuple[Image.Image, float]]:
|
|
|
30 |
capture = cv2.VideoCapture(video_path)
|
31 |
if not capture.isOpened():
|
32 |
raise ValueError(f"Could not open video file: {video_path}")
|
@@ -35,7 +36,6 @@ def get_frames(video_path: str, max_images: int) -> list[tuple[Image.Image, floa
|
|
35 |
total_frames = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
36 |
|
37 |
frame_interval = max(total_frames // max_images, 1)
|
38 |
-
frames: list[tuple[Image.Image, float]] = []
|
39 |
|
40 |
for i in range(0, min(total_frames, max_images * frame_interval), frame_interval):
|
41 |
if len(frames) >= max_images:
|
|
|
27 |
)
|
28 |
|
29 |
def get_frames(video_path: str, max_images: int) -> list[tuple[Image.Image, float]]:
|
30 |
+
frames: list[tuple[Image.Image, float]] = []
|
31 |
capture = cv2.VideoCapture(video_path)
|
32 |
if not capture.isOpened():
|
33 |
raise ValueError(f"Could not open video file: {video_path}")
|
|
|
36 |
total_frames = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
37 |
|
38 |
frame_interval = max(total_frames // max_images, 1)
|
|
|
39 |
|
40 |
for i in range(0, min(total_frames, max_images * frame_interval), frame_interval):
|
41 |
if len(frames) >= max_images:
|
tests/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
'''This file is intentionally left empty to mark the directory as a package.'''
|
tests/test_video.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytest
|
2 |
+
import os
|
3 |
+
import cv2
|
4 |
+
from PIL import Image
|
5 |
+
from pathlib import Path
|
6 |
+
|
7 |
+
from src.app import get_frames
|
8 |
+
|
9 |
+
# Get the project root directory
|
10 |
+
ROOT_DIR = Path(__file__).parent.parent
|
11 |
+
|
12 |
+
def test_correct_frame_return():
|
13 |
+
"""Test that get_frames returns a list of (Image, float) tuples."""
|
14 |
+
# Path to a test video file
|
15 |
+
video_path = os.path.join(ROOT_DIR, "assets", "test_video.mp4")
|
16 |
+
|
17 |
+
# Ensure the test video exists
|
18 |
+
assert os.path.exists(video_path), f"Test video not found at {video_path}"
|
19 |
+
|
20 |
+
# Test with a small number of frames
|
21 |
+
max_images = 3
|
22 |
+
frames = get_frames(video_path, max_images)
|
23 |
+
|
24 |
+
# Check return type
|
25 |
+
assert isinstance(frames, list)
|
26 |
+
assert all(isinstance(item, tuple) and len(item) == 2 for item in frames)
|
27 |
+
assert all(isinstance(img, Image.Image) and isinstance(ts, float) for img, ts in frames)
|