Skip to content

AdiistheGoat/ShortNExact

Repository files navigation

ShortNExact

License:  MIT Python ![Docker](https://img.shields.io/badge/Docker-Ready-2496ED? logo=docker&logoColor=white)

We've all been there… it's midnight, your essay's due, and the word limit is 500. You ask ChatGPT to concise it, and it spits out 490… or 512. Then you waste half an hour going back and forth trying to hit the exact count.

That's exactly why I built ShortNExact πŸ‘‰ an agentic AI tool that trims or expands your text to hit the exact word count you need. No more stress, no more guesswork.

Just plug in your OpenAI key, paste your text, and boom β€” deadline saved πŸ™Œ.


🌟 Features

  • Exact Word Count Matching: Uses an intelligent LLM orchestrator to iteratively adjust text until the precise word count is achieved
  • Two Processing Modes:
    • Concisely Present Ideas: Aggressively condense large texts while preserving key concepts
    • Shorten Text: Gently reduce word count with minimal structural changes
  • Agentic AI Architecture: Autonomous tool selection and execution using OpenAI function calling
  • Scalable Backend: HAProxy load balancing with multiple FastAPI instances
  • Rate Limiting: Redis-based rate limiting to prevent abuse
  • API Key Management: PostgreSQL-backed authentication system with time-limited keys
  • Modern UI: Clean Gradio interface for easy interaction
  • Production-Ready: Dockerized microservices with health checks and auto-restart

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend  β”‚  (Gradio UI on port 80/443)
β”‚  (Gradio)   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   HAProxy   β”‚  (Load Balancer on port 4000)
β”‚     (LB)    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β–Ό          β–Ό          β–Ό
   β”Œβ”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”
   β”‚API-1β”‚   β”‚API-2β”‚   β”‚API-3β”‚  (FastAPI instances)
   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜
      β”‚         β”‚         β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”
       β–Ό                 β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  Redis  β”‚      β”‚ Postgres β”‚
  β”‚ (Cache) β”‚      β”‚   (DB)   β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

1. Clone the repository

git clone https://github.com/AdiistheGoat/ShortNExact
cd ShortNExact

2. Create and activate a virtual environment

python3 -m venv venv
source ./venv/bin/activate

4. Run starting script

bash start.sh

Running with Docker Images from Docker Hub

1. Ensure you have the following files in your project directory.

haproxy.cfg
init.sql
pgbouncer.ini 
compose.yml 
userlist.txt 

2. Pull the pre-built images from Docker Hub:

docker pull adityagoyal333/short_n_exact:api_img
docker pull adityagoyal333/short_n_exact:lb_img
docker pull adityagoyal333/short_n_exact:frontend_img

3. Change the tag names of the image

docker tag adityagoyal333/short_n_exact:api_img api_img:latest
docker tag adityagoyal333/short_n_exact:lb_img  lb_img:latest
docker tag adityagoyal333/short_n_exact:frontend_img frontend_img:latest

3. Start all services using Docker Compose:

docker compose down
docker system prune
docker compose up -d

πŸ“– Usage

Web Interface

  1. Generate an API Key (first-time users):

    • Navigate to the API Key Generation tab
    • Enter your name, email, and desired validity period (max 31 days)
    • Save your generated key
  2. Process Your Text:

    • Enter your OpenAI API key
    • Paste your ShortNExact app key (generated in step 1)
    • Input your text
    • Set your target word count
    • Select processing mode:
      • Concisely present ideas: For aggressive summarization
      • Shorten text: For gentle reduction
    • Click submit and get your perfectly sized text!

API Endpoints

Main Processing Endpoint

curl -X GET http://localhost:4000/ \
  -H "Content-Type: application/json" \
  -H "ip_address: YOUR_IP" \
  -d '{
    "llm_api_key": "YOUR_OPENAI_KEY",
    "app_key": "YOUR_APP_KEY",
    "option": 1,
    "input_text": "Your text here.. .",
    "no_of_words": 500
  }'

API Key Generation

curl -X GET http://localhost:4000/api_key \
  -H "Content-Type: application/json" \
  -H "X-Forwarded-For: YOUR_IP" \
  -d '{
    "name": "Your Name",
    "email": "your.email@example.com",
    "validity": 30
  }'

πŸ”§ Technical Stack

Component Technology
Frontend Gradio
Backend API FastAPI
Load Balancer HAProxy
Database PostgreSQL
Cache Redis
LLM Provider OpenAI API
NLP NLTK
Containerization Docker & Docker Compose

πŸ“ Project Structure

ShortNExact/
β”œβ”€β”€ api. py                    # FastAPI backend with rate limiting
β”œβ”€β”€ ml_layer.py              # LLM orchestrator and agentic processing
β”œβ”€β”€ frontend. py              # Gradio UI components
β”œβ”€β”€ compose.yml              # Docker Compose configuration
β”œβ”€β”€ haproxy.cfg              # Load balancer configuration
β”œβ”€β”€ init. sql                 # Database schema initialization
β”œβ”€β”€ start.sh                 # Build and deployment script
β”œβ”€β”€ Dockerfile. api           # API service container
β”œβ”€β”€ Dockerfile.frontend      # Frontend service container
β”œβ”€β”€ Dockerfile.lb            # Load balancer container
β”œβ”€β”€ api_requirements.txt     # Python dependencies for API
β”œβ”€β”€ frontend_requirements.txt # Python dependencies for frontend
└── README.md

🧠 How It Works

ShortNExact uses an agentic LLM orchestrator that:

  1. Analyzes the current word count vs. target
  2. Selects the appropriate tool:
    • process_concisely: Aggressive restructuring
    • process_short: Gentle trimming
    • increase_words: Expand content
    • decrease_words: Minor reduction
  3. Executes the selected tool via OpenAI function calling
  4. Iterates until the exact word count is achieved

The system uses regex-based word counting with Unicode support for accurate results across languages.


πŸ›‘οΈ Rate Limiting & Security

  • Redis-based rate limiting: 10,000 API key generations per 24 hours
  • IP-based tracking: Prevents abuse from single sources
  • Time-limited API keys: Maximum 31-day validity
  • Health checks: All services monitored with automatic restart
  • Database persistence: PostgreSQL with volume mounting

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

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


πŸ™ Acknowledgments

  • OpenAI for the powerful GPT models
  • The open-source community for the amazing tools
  • All contributors who help improve this project

⭐ Show Your Support

If this project helped you, please consider giving it a star! It helps others discover the tool.

GitHub stars GitHub forks

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors