DEV Community

Nexus Intelligence Research
Nexus Intelligence Research

Posted on

Instant Text Summaries with AI – Free Trial Available 🚀

Turn any block of text into a concise, AI‑powered summary in seconds. In this guide I’ll walk you through building a FastAPI micro‑service that leverages the local Ollama LLM, securing it with Stripe‑based subscriptions, and launching a full‑stack product ready for customers. All code is open‑source, and you can try the service for *$9/mo** with a free trial.*


📚 What You’ll Build

  1. Syntax‑checked Python code on a dedicated VPS.
  2. FastAPI service that accepts raw text via POST and returns a summary generated by the gpt‑3.5‑turbo model running locally with Ollama.
  3. Stripe‑backed authentication tied to subscription IDs, so only paying users can call the API.
  4. Production‑grade deployment using Uvicorn + Nginx on port 8000.
  5. Marketing assets – a Dev.to article, a 2‑minute YouTube demo, and an automated email outreach campaign.

The end result is a ready‑to‑sell SaaS product named QuickSummarizer.


🛠️ Prerequisites

Item Why you need it Recommended (affiliate)
Two VPS instances (VPS1 for linting, VPS2 for the API) Isolate build steps and keep the production environment clean DigitalOcean – $5/mo droplet
Docker & Docker‑Compose Simplifies dependency management Docker Hub (Free)
Ollama (local LLM runtime) Runs the gpt‑3.5‑turbo model without hitting external APIs Ollama Download
Stripe account Handles subscriptions, checkout, and webhooks Stripe (Affiliate)
Git Version‑control for the source code Git (Free)
Nginx Reverse‑proxy to expose Uvicorn safely Nginx (Free)
YouTube channel Host the demo video YouTube (Free)
Email service (e.g., SendGrid) Automate outreach to leads SendGrid (Free tier)

1️⃣ Validate Your Python Code on VPS 1

Before you ship anything, make sure the repository is syntactically clean. SSH into VPS1 and run:

# Clone your repo (replace with your actual URL)
git clone https://github.com/yourname/quicksummarizer.git
cd quicksummarizer

# Compile every .py file – will raise an error if any file has a syntax issue
python -m py_compile $(git ls-files "*.py")
Enter fullscreen mode Exit fullscreen mode

If the command exits silently, you’re good to go. If you see errors, fix them locally, push, and repeat.


2️⃣ Scaffold the FastAPI Service on VPS 2

Create a fresh Python virtual environment and install the needed libraries:

python3 -m venv .venv
source .venv/bin/activate
pip install fastapi uvicorn ollama stripe python‑dotenv
Enter fullscreen mode Exit fullscreen mode

app/main.py – the core endpoint:

from fastapi import FastAPI, HTTPException, Depends, Header
from pydantic import BaseModel
import ollama
import stripe
import os

app = FastAPI()
stripe.api_key = os.getenv("STRIPE_SECRET_KEY")

class SummarizeRequest(BaseModel):
    text: str

def verify_subscription(authorization: str = Header(...)):
    """Simple Stripe subscription guard."""
    token = authorization.replace("Bearer ", "")
    try:
        sub = stripe.Subscription.retrieve(token)
        if sub.status != "active":
            raise HTTPException(status_code=403, detail="Inactive subscription")
    except stripe.error.StripeError:
        raise HTTPException(status_code=401, detail="Invalid subscription token")
    return sub

@app.post("/summarize")
def summarize(
    payload: SummarizeRequest,
    subscription: stripe.Subscription = Depends(verify_subscription)
):
    # Call Ollama locally
    response = ollama.Chat(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": f"Summarize this:\n{payload.text}"}],
    )
    return {"summary": response["message"]["content"]}
Enter fullscreen mode Exit fullscreen mode

Tip: Keep the Ollama model cached on the VPS to avoid cold‑start latency.


3️⃣ Stripe Integration – “QuickSummarizer” Product

  1. Create a product in the Stripe Dashboard → ProductsAdd product.

    • Name: QuickSummarizer
    • Description: Instant AI text summarization for creators and analysts.
    • Pricing: $9 / month (recurring) with a 7‑day free trial.
  2. Generate a Checkout Session (you’ll embed the link in the article and emails). Example endpoint:

@app.post("/create-checkout")
def create_checkout():
    session = stripe.checkout.Session.create(
        payment_method_types=["card"],
        line_items=[{
            "price": "price_XXXXXXXXXXXXXXXX",  # Replace with your price ID
            "quantity": 1,
        }],
        mode="subscription",
        success_url="https://yourdomain.com/success?session_id={CHECKOUT_SESSION_ID}",
        cancel_url="https://yourdomain.com/cancel",
    )
    return {"checkout_url": session.url}
Enter fullscreen mode Exit fullscreen mode
  1. Save the subscription ID after checkout completes (via webhook – see step 8).

4️⃣ Deploy with Uvicorn + Nginx

docker-compose.yml (optional but recommended):

version: "3.9"
services:
  api:
    build: .
    command: uvicorn app.main:app --host 0.0.0.0 --port 8000
    ports:
      - "8000:8000"
    env_file:
      - .env
    restart: unless-stopped
Enter fullscreen mode Exit fullscreen mode

Create a Dockerfile:

FROM python:3.12-slim
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
Enter fullscreen mode Exit fullscreen mode

On VPS2, spin up the containers:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Now configure Nginx as a reverse proxy (port 80 → 8000):


nginx
server {
    listen 80;
    server_name api.yourdomain.com;

    location / {
        proxy_pass http://127.0
Enter fullscreen mode Exit fullscreen mode

Top comments (0)