Textpress is a Python script that compresses text content within files using AI models. It processes files like JavaScript, JSON, YAML, etc., extracts text strings, and compresses them to be more concise while retaining their original meaning. The script is interactive and allows customization to tailor the compression process to your needs.
Textpress follows these steps:
- File Processing: "Reads" (using AI) the input file and detects its format (JSON, YAML, JS, etc).
- String Extraction: Extracts text strings suitable for compression. No need to compress parameters' names, for example.
- AI Compression: Uses an AI model to generate compressed versions of the strings while preserving their meaning.
- Content Replacement: Replaces the original strings with the compressed ones in the content.
- Output Generation: Writes the compressed content to an output file.
- Statistics Display: Provides compression statistics and sample comparisons.
- AI Model Selection:
- Claude (default)
- ChatGPT
- Llama (for local processing)
- Creativity Level (1-5):
- Adjusts the AI's creativity and variability.
- Higher levels increase creativity but may reduce consistency.
- Compression Level (1-5):
- Defines how aggressively to compress text.
- Higher levels attempt more aggressive compression.
- Field of Expertise:
- Tailors the compression to use language appropriate for a specific domain (e.g., psychology, medicine).
- Style Guidelines:
- Provide instructions like "formal", "technical", or "use metaphors".
- Emoji Inclusion:
- Choose to include emojis for added expressiveness.
-
Run the script:
python textpress.py <input_file> [output_file]
<input_file>: Path to the file you want to compress.[output_file](optional): Path for the output file. Defaults to<input_name>_output<extension>.
-
Follow the interactive prompts:
- AI Model: Choose between available AI models.
- Creativity Level: Enter a value between 1 (least creative) to 5 (most creative).
- Compression Level: Set the aggressiveness of compression attempts.
- Field of Expertise: Specify the domain for tailored language.
- Style Guidelines: (Optional) Add specific style preferences.
- Emoji Usage: Decide whether to include emojis in the compressed text.
-
Review the Output:
- The script processes the file and saves the compressed content to the output file.
- Displays compression statistics and sample comparisons.
Running the script with an input JavaScript file (output file name is optional):
python textpress.py input.js [output.js]- If
output.jsis not provided, the script defaults toinput_output.js.
Interactive Prompts Example:
- Choose AI model: Press Enter to use the default (Claude).
- Enter creativity level (1-5):
3 - Enter compression level (1-5):
3 - Enter the field:
psychology - Style guide:
formal - Want emojis in compressed text? (y/N):
N
Result:
- Processes
input.jsand saves the compressed content inoutput.js(if specified) orinput_output.jsby default. - Displays compression statistics and sample comparisons in the terminal.
-
Install required packages:
pip install -r requirements.txt
Alternatively:
pip install json5 ell colorama pyyaml esprima
- AI Model Credentials:
- Ensure the
elllibrary is configured with necessary credentials.
- Ensure the
- Review Output:
- Always review the compressed content to ensure accuracy.
- Compatibility:
- Supports multiple file formats; some complex structures may have limitations.
This project is licensed under the MIT License.
