Skip to main content

A simple library to set up Ollama and summarize text using local LLMs.

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. For Windows, please download Ollama directly from here.

# macOS (Please ensure brew is installed on macOS)
brew install --cask ollama
# linux
curl -fsSL https://ollama.com/install.sh | sh

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

textsage-0.1.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

textsage-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file textsage-0.1.2.tar.gz.

File metadata

  • Download URL: textsage-0.1.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for textsage-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1752be2c53bcb57d6a19d1f8c4d4ce5a0c8efe5d736786834f1fe9197ee911bb
MD5 bedcdd604de0639dc94ad727b50047e2
BLAKE2b-256 7c133ab0a3df90cb50233bcaa6108516aa9e7a453a25d476ee38f55d2c88722f

See more details on using hashes here.

File details

Details for the file textsage-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: textsage-0.1.2-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

Hashes for textsage-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8be0aa2f97ae999f10b86945a036258affcce2897443fff906b3c07508260ad0
MD5 4168797fa0ebd9d42ba7934d9824bb37
BLAKE2b-256 4c22caefa258097a0eaaff09cb1d4cb116be2d11982b8a4df5a699d4cd4ad37f

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