Skip to content

Fix extractor and gating tests#47

Open
LemurPwned wants to merge 2 commits into
mainfrom
codex/propose-resolutions-for-repo-issues-rx7cjv
Open

Fix extractor and gating tests#47
LemurPwned wants to merge 2 commits into
mainfrom
codex/propose-resolutions-for-repo-issues-rx7cjv

Conversation

@LemurPwned

@LemurPwned LemurPwned commented May 17, 2025

Copy link
Copy Markdown
Owner

Summary

  • restore generate_segments in KeywordExtractor
  • ensure ClipGate dependencies raise ImportError
  • fix test using monkeypatch.setitem

Testing

  • black tests/test_audio_extractor.py video_sampler/language/keyword_capture.py video_sampler/gating.py
  • isort tests/test_audio_extractor.py video_sampler/language/keyword_capture.py video_sampler/gating.py

Summary by Sourcery

Introduce audio-powered keyword extraction using Whisper, enforce dependency checks for the Clip gate, and update documentation and tests accordingly.

New Features:

  • Add AudioKeywordExtractor for audio-based keyword extraction via Whisper
  • Extend create_extractor to support the new audio_keyword extractor type

Bug Fixes:

  • Ensure gating create_model raises ImportError when open_clip or torch are missing

Enhancements:

  • Simplify KeywordExtractor.generate_segments docstring
  • Re-export KeywordExtractor and AudioKeywordExtractor in language package init

Documentation:

  • Document audio-based keyword extraction usage in README

Tests:

  • Add test to verify ImportError when Whisper is unavailable for AudioKeywordExtractor

@sourcery-ai

sourcery-ai Bot commented May 17, 2025

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Extends KeywordExtractor with an audio-based subclass using Whisper (with ImportError guards), simplifies the generate_segments docstring, updates the extractor factory and exports, enforces missing dependency errors in gating, refreshes the README CLI example, and adds a test for the Whisper import dependency.

File-Level Changes

Change Details Files
Simplify generate_segments docstring
  • Replace verbose multiline docstring with concise one
video_sampler/language/keyword_capture.py
Add AudioKeywordExtractor subclass with Whisper support
  • Import Whisper with ImportError guard in init
  • Load Whisper model via whisper.load_model
  • Implement transcribe method converting segments to subtitle list
  • Add generate_segments_from_audio delegating to base generate_segments
video_sampler/language/keyword_capture.py
video_sampler/language/__init__.py
Extend extractor factory for audio_keyword
  • Add audio_keyword branch in create_extractor to return AudioKeywordExtractor
video_sampler/language/keyword_capture.py
Enforce dependency errors in gating.create_model
  • Check for open_clip and torch in globals
  • Raise ImportError when dependencies are missing
video_sampler/gating.py
Update README with audio extractor usage
  • Insert CLI example for segmenting based on audio transcription
README.md
Add test for Whisper dependency in AudioKeywordExtractor
  • Simulate missing whisper module via monkeypatch.setitem
  • Assert ImportError is raised on initialization
tests/test_audio_extractor.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @LemurPwned - I've reviewed your changes - here's some feedback:

  • Rather than checking for open_clip and torch in globals(), wrap their imports in a try/except to more reliably detect missing dependencies.
  • Consider refactoring create_extractor to use a dict mapping types to classes instead of chained if-statements, making it easier to add new extractors in the future.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟡 Testing: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread video_sampler/language/keyword_capture.py
Comment on lines +113 to +116
for seg in result.get("segments", []):
subtitle_list.append(
((int(seg["start"] * 1000), int(seg["end"] * 1000)), seg["text"])
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Trim whitespace from Whisper segment text

Call .strip() on seg['text'] to remove extra whitespace and prevent matching issues.

Suggested change
for seg in result.get("segments", []):
subtitle_list.append(
((int(seg["start"] * 1000), int(seg["end"] * 1000)), seg["text"])
)
for seg in result.get("segments", []):
subtitle_list.append(
((int(seg["start"] * 1000), int(seg["end"] * 1000)), seg["text"].strip())
)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not change the indents

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point—let’s keep the existing indent structure and just call .strip() on the text. For example, if your current code looks like this:

for seg in result.get("segments", []):
    subtitle_list.append(
        ((int(seg["start"] * 1000), int(seg["end"] * 1000)),
         seg["text"])
    )

you can change it to:

for seg in result.get("segments", []):
    subtitle_list.append(
        ((int(seg["start"] * 1000), int(seg["end"] * 1000)),
         seg["text"].strip())
    )

This way you only trim the whitespace and don’t alter the indentation levels. Let me know if that aligns with your style rules!

Comment thread video_sampler/gating.py Outdated
Comment thread tests/test_audio_extractor.py
Comment on lines +112 to +116
subtitle_list: list[tuple[tuple[int, int], str]] = []
for seg in result.get("segments", []):
subtitle_list.append(
((int(seg["start"] * 1000), int(seg["end"] * 1000)), seg["text"])
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Convert for loop into list comprehension (list-comprehension)

Suggested change
subtitle_list: list[tuple[tuple[int, int], str]] = []
for seg in result.get("segments", []):
subtitle_list.append(
((int(seg["start"] * 1000), int(seg["end"] * 1000)), seg["text"])
)
subtitle_list: list[tuple[tuple[int, int], str]] = [
((int(seg["start"] * 1000), int(seg["end"] * 1000)), seg["text"])
for seg in result.get("segments", [])
]

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant