Skip to content
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Text Humanizer & AI Detection API

A FastAPI-based backend service for humanizing AI-generated text and detecting AI content.

Features

πŸ” AI Detection API

  • Analyzes text to detect AI-generated content
  • Classifies each sentence as:
    • AI-generated
    • AI-generated & AI-refined
    • Human-written
    • Human-written & AI-refined
  • Returns detailed percentages and classification results
  • Uses roberta-base-openai-detector model

✍️ Text Humanizer API

  • Humanizes AI-generated text while preserving APA citations
  • Expands contractions naturally
  • Replaces words with contextual synonyms using spaCy + WordNet
  • Adds academic transitions between sentences
  • NEW: Adds hedging language to sound more natural and academic
  • NEW: Intelligently combines short sentences with semantic analysis
  • Configurable transformation probabilities for fine control

Installation

Prerequisites

  • Python 3.9+
  • pip

Setup

  1. Clone the repository:
git clone <repository-url>
cd Text-Humanizer-Python-Fork
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
python -m spacy download en_core_web_sm
python -m nltk.downloader punkt punkt_tab wordnet averaged_perceptron_tagger
  1. Run the API:
uvicorn main:app --reload

The API will be available at: http://localhost:8000

API Endpoints

POST /humanize

Humanize AI-generated text while preserving citations.

Request Body:

{
  "text": "Your AI-generated text here...",
  "synonym_probability": 0.2,
  "transition_probability": 0.2,
  "hedging_probability": 0.15,
  "sentence_combine_probability": 0.3
}

Response:

{
  "original_text": "...",
  "humanized_text": "...",
  "original_word_count": 150,
  "humanized_word_count": 165,
  "original_sentence_count": 8,
  "humanized_sentence_count": 8
}

POST /detect

Detect AI-generated content in text.

Request Body:

{
  "text": "Your text to analyze..."
}

Response:

{
  "text": "...",
  "classification_results": {
    "First sentence.": "AI-generated",
    "Second sentence.": "Human-written"
  },
  "percentages": {
    "AI-generated": 45.5,
    "AI-generated & AI-refined": 10.2,
    "Human-written": 30.1,
    "Human-written & AI-refined": 14.2
  },
  "summary": { ... }
}

GET /

Root endpoint with API information.

GET /health

Health check endpoint.

GET /docs

Interactive API documentation (Swagger UI).

Usage Examples

Using cURL

Humanize Text:

curl -X POST "http://localhost:8000/humanize" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "AI is transforming industries. It is creating new opportunities.",
    "synonym_probability": 0.3,
    "transition_probability": 0.2,
    "hedging_probability": 0.15,
    "sentence_combine_probability": 0.3
  }'

Detect AI:

curl -X POST "http://localhost:8000/detect" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "The research methodology employed a quantitative approach."
  }'

Using Python

import requests

# Humanize text
response = requests.post(
    "http://localhost:8000/humanize",
    json={
        "text": "Your AI text here...",
        "synonym_probability": 0.2,
        "transition_probability": 0.2,
        "hedging_probability": 0.15,
        "sentence_combine_probability": 0.3
    }
)
result = response.json()
print(result['humanized_text'])

# Detect AI
response = requests.post(
    "http://localhost:8000/detect",
    json={"text": "Text to analyze..."}
)
result = response.json()
print(result['percentages'])

Using JavaScript/Fetch

// Humanize text
fetch("http://localhost:8000/humanize", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    text: "Your AI text here...",
    synonym_probability: 0.2,
    transition_probability: 0.2,
  }),
})
  .then((res) => res.json())
  .then((data) => console.log(data));

// Detect AI
fetch("http://localhost:8000/detect", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    text: "Text to analyze...",
  }),
})
  .then((res) => res.json())
  .then((data) => console.log(data));

Testing

Run the test script to verify everything works:

python test_api.py

Or visit the interactive documentation at: http://localhost:8000/docs

Project Structure

Text-Humanizer-Python-Fork/
β”œβ”€β”€ main.py                    # FastAPI application
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ ai_detection_utils.py  # AI detection logic
β”‚   β”œβ”€β”€ model_loaders.py       # Model caching
β”‚   └── text_humanizer.py      # Text humanization logic
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ test_api.py                # Test script
β”œβ”€β”€ .gitignore                 # Git ignore rules
└── README.md                  # This file

Technologies

  • FastAPI - Modern web framework for building APIs
  • Transformers - HuggingFace library for AI models
  • spaCy - Industrial-strength NLP
  • NLTK - Natural Language Toolkit
  • PyTorch - Deep learning framework
  • Uvicorn - ASGI server

API Parameters

Humanize Endpoint

Parameter Type Default Range Description
text string required - Text to humanize
synonym_probability float 0.2 0.0-1.0 Probability of replacing words with synonyms
transition_probability float 0.2 0.0-1.0 Probability of adding academic transitions
hedging_probability float 0.15 0.0-1.0 Probability of adding hedging language (e.g., "generally", "tends to")
sentence_combine_probability float 0.3 0.0-1.0 Probability of intelligently combining short sentences

Detect Endpoint

Parameter Type Default Description
text string required Text to analyze for AI detection

License

MIT License

Contributing

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

About

Scan pdf files to find AI detection and also humanize the text - This app is still WIP , scanning can be done.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages