Skip to content

Commit 3841880

Browse files
committed
feat: add scene and frame describe
1 parent 125cf89 commit 3841880

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

videodb/_constants.py

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class SceneExtractionType:
2727
time_based = "time"
2828

2929

30+
class SceneModels:
31+
gpt4_o = "gpt4-o"
32+
33+
3034
class Workflows:
3135
add_subtitles = "add_subtitles"
3236

@@ -58,6 +62,8 @@ class ApiPath:
5862
invoices = "invoices"
5963
scenes = "scenes"
6064
scene = "scene"
65+
frame = "frame"
66+
describe = "describe"
6167

6268

6369
class Status:

videodb/image.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from videodb._constants import (
22
ApiPath,
3+
SceneModels,
34
)
45

56

@@ -61,3 +62,11 @@ def to_json(self):
6162
"frame_time": self.frame_time,
6263
"description": self.description,
6364
}
65+
66+
def describe(self, prompt: str = None, model_name=SceneModels.gpt4_o):
67+
description_data = self._connection.post(
68+
path=f"{ApiPath.video}/{self.video_id}/{ApiPath.frame}/{self.id}/{ApiPath.describe}",
69+
data={"prompt": prompt, "model_name": model_name},
70+
)
71+
self.description = description_data.get("description", None)
72+
return self.description

videodb/scene.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List
22

3-
from videodb._constants import ApiPath
3+
from videodb._constants import ApiPath, SceneModels
44

55
from videodb.image import Frame
66

@@ -14,13 +14,15 @@ def __init__(
1414
description: str,
1515
id: str = None,
1616
frames: List[Frame] = [],
17+
connection=None,
1718
):
1819
self.id = id
1920
self.video_id = video_id
2021
self.start = start
2122
self.end = end
2223
self.frames: List[Frame] = frames
2324
self.description = description
25+
self._connection = connection
2426

2527
def __repr__(self) -> str:
2628
return (
@@ -43,6 +45,16 @@ def to_json(self):
4345
"description": self.description,
4446
}
4547

48+
def describe(self, prompt: str = None, model_name=SceneModels.gpt4_o) -> None:
49+
if self._connection is None:
50+
raise ValueError("Connection is required to describe a scene")
51+
description_data = self._connection.post(
52+
path=f"{ApiPath.video}/{self.video_id}/{ApiPath.scene}/{self.id}/{ApiPath.describe}",
53+
data={"prompt": prompt, "model_name": model_name},
54+
)
55+
self.description = description_data.get("description", None)
56+
return self.description
57+
4658

4759
class SceneCollection:
4860
def __init__(

videodb/video.py

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def _format_scene_collection(self, scene_collection_data: dict) -> SceneCollecti
197197
description=scene.get("description"),
198198
id=scene.get("scene_id"),
199199
frames=frames,
200+
connection=self._connection,
200201
)
201202
scenes.append(scene)
202203

0 commit comments

Comments
 (0)