Secure text summarization with local LLMs, with support for Python, Pandas, and PySpark workflows.
Project description
TextSage
TextSage is a Python library that sets up Ollama and local LLMs for users and provides simple functions to summarize text, with support for Python, Pandas, and PySpark workflows.
Features
-
Automated Ollama Setup:
- Checks if Ollama is installed and running
- Installs Ollama if not found
- Downloads specified LLM models for summarization
-
Multiple Integration Options:
- Pure Python text summarization
- Pandas DataFrame column summarization
- PySpark DataFrame column summarization
Installation
pip install textsage
Dependency
textsage uses Ollama to host a local LLM on your machine and perform summarization tasks. If Ollama is not already installed, the textsage package will attempt to install it on macOS and Linux using following commands.
# macOS (Please ensure Homebrew is installed on macOS)
brew install --cask ollama
# linux
curl -fsSL https://ollama.com/install.sh | sh
For Windows, please download Ollama directly from here.
The default quantized Mistral model (~4GB) will be downloaded and used for summarization. Ensure sufficient RAM is available for hosting the local LLM.
Note: Ollama and LLM installation is a one-time setup. Once installed, TextSage can be used directly without reinstallation.
Usage
Basic Text Summarization
from textsage import summarize_text
text = "This is a long text that needs summarization."
summary = summarize_text(text, model_name="mistral", word_count=10)
print(summary)
Pandas DataFrame Summarization
import pandas as pd
from textsage import summarize_dataframe
# Create a sample DataFrame
df = pd.DataFrame({
'text': ['This is a long text that needs summarization.']
})
# Summarize the 'text' column
result_df = summarize_dataframe(df, 'text', model_name='mistral')
print(result_df['summary'])
PySpark DataFrame Summarization
from pyspark.sql import SparkSession
from textsage import summarize_spark_dataframe
# Create a Spark session
spark = SparkSession.builder.getOrCreate()
# Create a sample DataFrame
data = [("This is a long text that needs summarization.",)]
spark_df = spark.createDataFrame(data, ["text"])
# Summarize the 'text' column
result_df = summarize_spark_dataframe(spark_df, 'text', model_name='mistral')
result_df.show()
Supported Models
By default, textsage uses the 'mistral' model, but you can specify any model supported by Ollama:
- mistral
- llama2
- codellama
- phi
- neural-chat
- And more...
Requirements
- Python 3.8+
- Ollama (automatically installed if missing)
- pandas (optional, for DataFrame support)
- pyspark (optional, for Spark support)
License
This project is licensed under the MIT License.
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
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 textsage-0.1.3.tar.gz.
File metadata
- Download URL: textsage-0.1.3.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92e0c00711b44e812ea705b09820e3b0d94565b78800d043580b78a3562a4bac
|
|
| MD5 |
4b279edd37a7cdceea5a3dfd1aaa5e27
|
|
| BLAKE2b-256 |
df460f676e4c0656c250eed726da8da9c26952280e1f1f123a6325595751ee1d
|
File details
Details for the file textsage-0.1.3-py3-none-any.whl.
File metadata
- Download URL: textsage-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98419abfb3e4417be6a74daecb0f48d1b38b07173ec4a02f3a106c786d877b5c
|
|
| MD5 |
2a463114192496e7df8aa88a63550dd1
|
|
| BLAKE2b-256 |
4a126023ded363db8ae8fe073841eac47b9350ecb1413dcbacda602113742f5f
|