Skip to main content

R Python

PyPI Python Versions License: MIT Downloads Docs How to Cite

VisTopics

vistopics (Topic Visualization for Visuals) is a Python package for video and image processing, offering features such as:

  • Frame extraction from videos.
  • Caption generation for images using OpenAI or Anthropic (Claude).
  • Video scraping and organization.
  • Duplicate frame reduction with efficient algorithms.
  • Image scraping and captioning from article URLs.

This package is designed for developers, researchers, and data scientists working on media processing, visualization, or clustering tasks.



Installation

Install vistopics from PyPI using:

pip install vistopics

If you plan to use FastDup for duplicate frame detection, install with:

pip install vistopics[fastdup]

Alternatively, install it directly from the source:

git clone https://github.com/aysedeniz09/VisTopics
cd VisTopics
pip install .

Note: The repository name on GitHub is VisTopics (capitalized), but the package name and Python import name are lowercase vistopics.


Features

Option A: Video-Based Pipeline

  1. Scrape and download videos from URLs
  2. Extract frames from the downloaded videos
  3. Reduce duplicate frames with FastDup
  4. Generate captions for the cleaned set of frames

Option B: Image URL-Based Pipeline

  1. Download images from a CSV containing article or image URLs
  2. Generate captions for the images

Requirements

The following Python libraries are required:

  • openai>=1.50.0
  • opencv-python>=4.9.0,<4.10
  • opencv-python-headless>=4.9.0,<4.10
  • pandas>=2.0.3,<2.2
  • requests>=2.28.0
  • yt-dlp>=2024.12.6
  • gradio>=3.36.0
  • aiofiles>=23.0
  • pydantic>=2.8
  • urllib3>=1.26
  • beautifulsoup4>=4.12
  • tqdm>=4.66

Note: To use FastDup-based functionality (limiting_frames), you must additionally install:

pip install vistopics[fastdup]

Install base dependencies with:

pip install -r requirements.txt

Usage

Option A: Video-Based Pipeline

1. Video Scraping

from vistopics import video_download

video_download(
    input_df_path="test_data.csv",
    output_df_path="cleaned_videos.csv",
    output_dir="downloaded_videos",
    link_column="Link",
    title_column="Page Name"
)

2. Frame Extraction

from vistopics import extract_frames

extract_frames(
    videofolder="downloaded_videos",
    images_folder="images",
    frame_rate=1
)

3. Duplicate Frame Reduction

from vistopics import limiting_frames

limiting_frames(
    path="images",
    output_file="reduced_frame_list.csv",
    ccthreshold=0.8
)

This step requires the optional fastdup dependency:

pip install vistopics[fastdup]

4. Caption Generation

from vistopics import get_caption

get_caption(
    mykey="your-open-ai-api-key",
    path_in="images",
    captions_file="captions_file.csv",
    model="gpt-4o-mini"
)

See Option B, Step 2 below for full get_caption documentation, including custom prompts and Anthropic/Claude support.


Option B: Image URL-Based Pipeline

1. Download Images from URLs

from vistopics import download_images_from_url

download_images_from_url(
    input_csv="output/urls_cvs.csv",
    output_csv="output/download_log.csv",
    image_dir="images",
    url_column="image_link",
    index_column="uuid",
    use_referer=True,
)
  • url_column (default "url") — column containing the URL to download. Works with either a direct image link or an article page URL (the function scrapes the page's og:image if needed).
  • index_column (optional) — column to use as each row's filename identifier. Falls back to an "index"/"index_number" column, or auto-generates one.
  • use_referer (default False) — if True, sets the Referer header to the image's own domain, helping with CDNs that use hotlink protection.
  • Direct image URLs are correctly recognized even with a query string after the extension (e.g. .../photo.jpg?quality=75&width=1024).

2. Caption Generation

from vistopics import get_caption

get_caption(
    mykey="your-open-ai-api-key",
    path_in="images",
    captions_file="captions_file.csv",
    model="gpt-4o-mini"
)

By default, get_caption uses a prompt validated in Lokmanoglu & Walter (2025), which instructs the model to describe the scene briefly, note (but not transcribe) any visible text, and name recognizable public figures without background context. This keeps captions consistent for downstream topic modeling.

Supports both OpenAI and Anthropic vision models, auto-detected from the model name:

# OpenAI
get_caption(mykey=os.environ["OPENAI_API_KEY"], path_in="images",
            captions_file="captions.csv", model="gpt-4o-mini")

# Anthropic (Claude)
get_caption(mykey=os.environ["ANTHROPIC_API_KEY"], path_in="images",
            captions_file="captions.csv", model="claude-haiku-4-5-20251001")

To override auto-detection, pass provider="openai" or provider="anthropic" explicitly.

To adapt captioning to a different domain or model, pass your own prompt:

get_caption(
    mykey="your-api-key",
    path_in="images",
    captions_file="captions_file.csv",
    model="gpt-4o-mini",
    prompt="Describe any protest signage, crowd size, and police presence visible in this image."
)

Note: different models can interpret the same instructions differently. If you switch models or providers, it's worth re-piloting your prompt on a small sample first.

get_caption is resumable — it skips images already listed in captions_file (and skips hidden system files like .DS_Store), so an interrupted run can just be rerun to pick up where it left off.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing

We welcome contributions! If you'd like to contribute:

  1. Fork the repository
  2. Create a feature branch:
git checkout -b feature-name
  1. Commit your changes:
git commit -m "Add new feature"
  1. Push to the branch:
git push origin feature-name
  1. Open a pull request

Repository Structure

vistopics/           # Python package
  __init__.py
  captioning.py
  extract_frames.py
  image_download.py
  reduce_frame.py
  video_scrape.py

paper/               # Paper replication code
  python/
    study1_videos.py       # Video processing for Study 1
    study2_images.py       # Image processing for Study 2
  R/
    study1_videos_lda.R    # LDA on video frame captions (Study 1)
    study1_transcripts_lda.R # LDA on transcripts (Study 1)
    study2_images_lda.R    # LDA on image captions (Study 2)

LICENSE
README.md

Paper Replication Code:

APA citation:
Lokmanoglu, A. D., & Walter, D. (2025). Topic modeling of video and image data: A visual semantic unsupervised approach. Communication Methods and Measures. https://www.tandfonline.com/doi/abs/10.1080/19312458.2025.2549707

BibTeX citation:

@article{lokmanogluwalter2025topic,
  author       = {Lokmanoglu, A. D. and Walter, D.},
  title        = {Topic modeling of video and image data: A visual semantic unsupervised approach},
  journal      = {Communication Methods and Measures},
  year         = {2025},
  doi          = {10.1080/19312458.2025.2549707},
  url          = {https://www.tandfonline.com/doi/abs/10.1080/19312458.2025.2549707},
}

The paper/ folder contains all code and workflows for replicating the analyses in our studies.

Note: The paper code is a mix of R (for topic modeling, statistical analysis) and Python (for preprocessing and caption generation).
You will need R ≥ 4.2 and see individual script headers for full package requirements.

Study 1 — Videos

  • Preprocessing & Captioning (Python)
    paper/python/study1_videos.py
    Samples videos, extracts frames, reduces duplicates with FastDup, and generates captions using vistopics.

  • Topic Modeling (R)
    paper/R/study1_videos_lda.R
    Runs LDA on video-level frame captions from the Study 1 dataset.

Study 1 — Transcripts (LDA)

Study 2 — News Images

Data Availability

All datasets and additional materials needed to run the LDA analyses are available on OSF:
https://osf.io/vhdaj/ (view-only)


Contact

If you have any questions or feedback, feel free to contact:

Ayse Lokmanoglu & Dror Walter

GitHub: https://github.com/aysedeniz09/VisTopics


Acknowledgments

The vistopics package incorporates and builds upon the work of the following projects and resources:

  • OpenAI – Provided API access used in the image captioning feature and support through the Researcher Access Program.
  • Anthropic – Provided API access used in the image captioning feature.
  • FastDup – Enabled efficient duplicate frame detection within the video frame processing workflow.
  • OpenCV – Supplied core video and image processing functionality used throughout the package.

We thank the developers and maintainers of these tools for making their work publicly available and for their contributions to the open-source community.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vistopics-0.1.10.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vistopics-0.1.10-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file vistopics-0.1.10.tar.gz.

File metadata

  • Download URL: vistopics-0.1.10.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.11

File hashes

Hashes for vistopics-0.1.10.tar.gz
Algorithm Hash digest
SHA256 30b7c63d57cac5e0574cfc6da59e08b6f5dc95364a596310e407ca7c3797d681
MD5 c6e39e4603e322d47603ee59e1d5ad0b
BLAKE2b-256 6ee776e3486229bba4cbc3d5db31591a0b89bbd8155041ee70199956c89adc6a

See more details on using hashes here.

File details

Details for the file vistopics-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: vistopics-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.11

File hashes

Hashes for vistopics-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d80d0dea976f6f56ab22ace290eb1e3478d94eff399c2b3f9f362dd7b7321e
MD5 e3abc0a405954427e1f56709ac1ed34f
BLAKE2b-256 7b10c6a6b50548560964c9f19f420ca113d0a1cb4166a80321699b2f9eea21f0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page