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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file semantic_title_generator-0.1.1.tar.gz.
File metadata
- Download URL: semantic_title_generator-0.1.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
361cc321f289081d78d33ab79ec8dea6206a97062fe04709fe36e5564eba49ac
|
|
| MD5 |
3d1dd07cd27f2ac64de25db71832dfdb
|
|
| BLAKE2b-256 |
a0d2aac0a7a3eee889959eb3198aebcd3d7022a776f63cc4008113dca4c6f7cc
|
File details
Details for the file semantic_title_generator-0.1.1-py3-none-any.whl.
File metadata
- Download URL: semantic_title_generator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78a970f926aeb4244fcfa15dbb7efcba9f37b9495f66369a629960ff38545901
|
|
| MD5 |
20d92159ca776563bd9a6ded828785be
|
|
| BLAKE2b-256 |
26c2c5f5ad1071d70cdb7d1a0025c2ff5762de2e7a2294c8afd2a74c7982c01a
|