Skip to main content

Generate concise titles and keywords from long documents via Google’s Gemini API.

Project description

Semantic Title Generator

Generate concise titles and keywords from long documents using Google’s Gemini API. This library chunks long input texts, summarizes each chunk, aggregates the summaries with a hierarchical map‑reduce approach, then produces a final title and a list of keywords.

Features

  • Supports plain text, PDF, DOCX and HTML inputs.
  • Uses configurable chunk sizes with overlap to preserve context across boundaries.
  • Summarises text hierarchically to handle long inputs efficiently.
  • Generates a title and a list of keywords in one API call.
  • Flexible configuration of the Gemini model and temperature.
  • Comes with a command‑line interface (CLI) for quick use.

Installation

Install the package from PyPI (replace <version> with the latest release):

pip install semantic-title-generator

Alternatively, clone the repository and install locally:

git clone https://github.com/yourusername/semantic-title-generator.git
cd semantic-title-generator
pip install .

Usage

Python API

Import the helper function Semantic_title_generator to quickly produce a title and keywords. You will need a Gemini API key with access to the specified model.

from semantic_title_generator import Semantic_title_generator

title, keywords = Semantic_title_generator(
    path_document="path/to/file.pdf",  # can also be a raw text string
    Gemini_API_KEY="YOUR_GEMINI_API_KEY",
    model="gemini-2.5-pro",    # or another supported model like "gemini-1.5-flash"
    chunkSize=512,              # number of words per chunk (default 512)
    temperature=0.3             # sampling temperature (default 0.3)
)

print("Title:", title)
print("Keywords:", keywords)

Command‑line interface

After installation the package exposes a CLI entry point stg. You can call it on a file or raw text. Set your API key via the --api_key argument or the GEMINI_API_KEY environment variable.

export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"

# generate a title and keywords for a PDF
stg path/to/document.pdf --model gemini-2.5-pro --chunk 512

# generate for a plain text file and override the temperature
stg path/to/text.txt --temperature 0.2

Use stg --help to see all options.

License

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

Project details


Download files

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

Source Distribution

semantic_title_generator-0.1.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

semantic_title_generator-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file semantic_title_generator-0.1.1.tar.gz.

File metadata

File hashes

Hashes for semantic_title_generator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 361cc321f289081d78d33ab79ec8dea6206a97062fe04709fe36e5564eba49ac
MD5 3d1dd07cd27f2ac64de25db71832dfdb
BLAKE2b-256 a0d2aac0a7a3eee889959eb3198aebcd3d7022a776f63cc4008113dca4c6f7cc

See more details on using hashes here.

File details

Details for the file semantic_title_generator-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_title_generator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78a970f926aeb4244fcfa15dbb7efcba9f37b9495f66369a629960ff38545901
MD5 20d92159ca776563bd9a6ded828785be
BLAKE2b-256 26c2c5f5ad1071d70cdb7d1a0025c2ff5762de2e7a2294c8afd2a74c7982c01a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page