Skip to content

Commit

Permalink
polish based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan committed Nov 22, 2024
1 parent b372d30 commit bb868dd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions camel/toolkits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .retrieval_toolkit import RetrievalToolkit
from .notion_toolkit import NotionToolkit
from .human_toolkit import HumanToolkit
from .video_toolkit import VideoDownloaderToolkit

__all__ = [
'BaseToolkit',
Expand Down Expand Up @@ -66,4 +67,5 @@
'NotionToolkit',
'ArxivToolkit',
'HumanToolkit',
'VideoDownloaderToolkit',
]
15 changes: 10 additions & 5 deletions camel/toolkits/video_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(
download_directory or tempfile.mkdtemp()
).resolve()

print(f"self._download_directory: {self._download_directory}")
logger.info(f"self._download_directory: {self._download_directory}")

try:
self._download_directory.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -141,10 +141,11 @@ def _download_video(self, url: str) -> str:
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
# Download the video and get the filename
logger.info(f"Downloading video from {url}...")
info = ydl.extract_info(url, download=True)
return ydl.prepare_filename(info)
except yt_dlp.utils.DownloadError as e:
raise RuntimeError(f"Failed to download video: {e}")
raise RuntimeError(f"Failed to download video from {url}: {e}")

def get_video_bytes(
self,
Expand Down Expand Up @@ -194,8 +195,12 @@ def get_video_screenshots(
raise RuntimeError(f"Failed to determine video length: {e.stderr}")

if isinstance(timestamps, int):
if timestamps <= 0:
raise ValueError(
"Number of screenshots must be greater than zero."
)
interval = video_length // (timestamps + 1)
tss = [int((i + 1) * interval) for i in range(timestamps)]
tss = [round((i + 1) * interval) for i in range(timestamps)]
else:
tss = [ts for ts in timestamps if 0 <= ts <= video_length]

Expand All @@ -204,11 +209,11 @@ def get_video_screenshots(
return images

def get_tools(self) -> List[FunctionTool]:
r"""Returns a list of OpenAIFunction objects representing the
r"""Returns a list of FunctionTool objects representing the
functions in the toolkit.
Returns:
List[OpenAIFunction]: A list of OpenAIFunction objects representing
List[FunctionTool]: A list of FunctionTool objects representing
the functions in the toolkit.
"""
return [
Expand Down
15 changes: 7 additions & 8 deletions examples/vision/duckduckgo_video_object_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents.chat_agent import ChatAgent
from camel.configs.openai_config import ChatGPTConfig
from camel.messages.base import BaseMessage
from camel.models.model_factory import ModelFactory
from camel.prompts.prompt_templates import PromptTemplateGenerator
from camel.toolkits.search_toolkit import SearchToolkit
from camel.toolkits.video_toolkit import VideoDownloaderToolkit
from camel.types.enums import ModelPlatformType, ModelType, RoleType, TaskType
from camel.agents import ChatAgent
from camel.configs import ChatGPTConfig
from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.prompts import PromptTemplateGenerator
from camel.toolkits import SearchToolkit, VideoDownloaderToolkit
from camel.types import ModelPlatformType, ModelType, RoleType, TaskType


def detect_image_obj(image_list) -> None:
Expand Down
9 changes: 4 additions & 5 deletions examples/vision/web_video_description_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
from camel.configs.openai_config import ChatGPTConfig
from camel.configs import ChatGPTConfig
from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.prompts.prompt_templates import PromptTemplateGenerator
from camel.toolkits.video_toolkit import VideoDownloaderToolkit
from camel.types import ModelPlatformType, ModelType
from camel.types.enums import RoleType, TaskType
from camel.prompts import PromptTemplateGenerator
from camel.toolkits import VideoDownloaderToolkit
from camel.types import ModelPlatformType, ModelType, RoleType, TaskType

video_url = (
'https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4'
Expand Down

0 comments on commit bb868dd

Please sign in to comment.