Skip to content

CipherSingularity/ai-email-refiner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ง AI Email Rewriter

Python Flask Hugging Face License Status

Transform casual emails into professional, context-appropriate communication powered by AI

Features โ€ข Demo โ€ข Installation โ€ข Usage โ€ข API Documentation โ€ข Contributing


๐Ÿ” Health & Status

The backend exposes a simple health endpoint you can use to check whether the server and (optionally) the local model are ready:

GET /health

Example response (JSON):

{
  "status": "healthy",
  "model": "google/flan-t5-base"
}

If you're using a large local model, the first run will download weights and the endpoint may show the server as running while the model is still loading. Monitor the server logs or use this endpoint [...]

๐ŸŽฏ Overview

The AI Email Rewriter is an intelligent tool that leverages Large Language Models (LLMs) to automatically convert informal or poorly structured emails into professional, business-appropriate commu[...]

โœจ Example Transformation

Before After (Formal Tone)
"Hey, can you send me the file?" "Could you please share the document at your earliest convenience?"

๐Ÿš€ Features

๐ŸŽจ Multiple Tone Options

  • Formal: Professional and polite, suitable for business or official communication
  • Friendly: Warm yet professional, ideal for colleagues or informal business settings
  • Assertive: Direct and confident, useful for urgent or firm requests

๐Ÿ”ฅ Core Capabilities

  • โšก Real-Time Processing: Instant email rewriting with efficient LLM inference
  • ๐Ÿ“‹ One-Click Copy: Seamless clipboard integration for quick email drafting
  • ๐ŸŽฏ Context-Aware: Intelligent tone adjustment based on communication needs
  • ๐Ÿ“ฑ Responsive Design: Works flawlessly on desktop and mobile devices
  • ๐Ÿ”’ Secure: Input sanitization and HTTPS-enabled communication

๐Ÿ—๏ธ Technology Stack

Layer Technology Purpose
Frontend HTML/CSS/JavaScript + Bootstrap 5 User interface and interaction handling (responsive Tone Lab UI)
Backend Flask (Python) RESTful API and business logic
AI Model Hugging Face Transformers Email rewriting using LLMs (T5/BART)

๐Ÿค– Supported Models

  • T5 (Text-to-Text Transfer Transformer) - Ideal for paraphrasing and tone adjustment
  • BART - Excellent for text generation and rewriting tasks
  • DistilBART - Lightweight version for faster inference

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Python 3.8 or higher
  • pip (Python package manager)
  • Node.js (optional, for frontend development)
  • Git

๐Ÿ–ผ๏ธ Demo

Demo Preview


๐Ÿ”ง Installation

1. Clone the Repository

git clone https://github.com/CipherSingularity/ai-email-refiner.git
cd ai-email-refiner

2. Set Up Virtual Environment

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate

3. Install Dependencies

# Install backend dependencies
pip install -r requirements.txt

# Install frontend dependencies (if applicable)
npm install

4. Configure Environment Variables

Create a .env file in the root directory:

# Backend entrypoint (this project uses `backend.py`)
HF_TOKEN=            # (optional) Hugging Face inference API token (e.g. hf_xxx)
HF_MODEL=google/flan-t5-base  # optional default HF model
USE_LOCAL_MODEL=1    # 1 to prefer local model, 0 to prefer HF API
LOCAL_MODEL=google/flan-t5-small  # local model name (small for dev, base for higher quality)
SECRET_KEY=your_secret_key_here

5. Run the Application

This project uses `backend.py` as the Flask entrypoint. You can run it directly.

# On Windows PowerShell (recommended for development)
$env:USE_LOCAL_MODEL='1'
$env:LOCAL_MODEL='google/flan-t5-small'  # or google/flan-t5-base
python backend.py

# To prefer the Hugging Face hosted inference API instead of a local model:
$env:USE_LOCAL_MODEL='0'
$env:HF_TOKEN='hf_YourTokenHere'
python backend.py

# For production, use a WSGI server such as Gunicorn (on Linux/macOS) or a process manager on Windows.
gunicorn -w 4 -b 0.0.0.0:5000 backend:app

The application will be available at http://localhost:5000


๐Ÿ’ป Usage

Web Interface

  1. Navigate to the application URL
  2. Enter your casual email text in the input area
  3. Select your desired tone (Formal, Friendly, or Assertive)
  4. Click "Rewrite Email"
  5. Copy the professional output with one click

Example Transformations

Input: "Can you get this done?"

Tone Output
Formal "Would you kindly complete this task at your earliest opportunity?"
Friendly "Could you help get this done soon? Thanks!"
Assertive "Please ensure this task is completed promptly."

๐Ÿ“ก API Documentation

Endpoint: Rewrite Email

POST /rewrite

Request Body

{
  "text": "Hey, can you send me the file?",
  "tone": "formal"
}

Parameters

Parameter Type Required Description
text string Yes The casual email text to rewrite
tone string Yes Desired tone: formal, friendly, or assertive

Response

{
  "rewritten": "Could you please share the document at your earliest convenience?"
}

Error Response

{
  "error": "Invalid tone specified",
  "status": "error"
}

Example cURL Request

curl -X POST http://localhost:5000/rewrite \
  -H "Content-Type: application/json" \
  -d '{"text": "Hey, send me the file", "tone": "formal"}'

๐Ÿ›๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Frontend  โ”‚ โ”€โ”€HTTPโ”€โ†’โ”‚  Flask API   โ”‚ โ”€โ”€APIโ”€โ”€โ†’โ”‚  Hugging Face   โ”‚
โ”‚  (HTML/CSS/ โ”‚         โ”‚   (Python)   โ”‚         โ”‚   LLM (T5/BART) โ”‚
โ”‚     JS)     โ”‚ โ†โ”€JSONโ”€โ”€โ”‚              โ”‚ โ†โ”€Textโ”€โ”€โ”‚                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Data Flow

  1. User Input: User enters email and selects tone
  2. API Request: Frontend sends POST request to Flask backend
  3. Prompt Engineering: Backend formats prompt for LLM
  4. AI Processing: Hugging Face LLM generates rewritten email
  5. Response: Backend returns professional email to frontend
  6. Display: Frontend shows result with copy functionality


๐ŸŽฏ Use Cases

  • โœ… Corporate Communication: Convert casual messages to business-appropriate emails
  • โœ… Non-Native Speakers: Craft professional English emails with confidence
  • โœ… Freelancers: Maintain professionalism with clients
  • โœ… Follow-ups: Streamline repetitive email drafting tasks
  • โœ… Urgent Requests: Switch to assertive tone when needed

๐Ÿ”ฎ Future Enhancements

  • Additional Tones: Apologetic, persuasive, neutral
  • Context Awareness: Specify recipient type (client, manager, colleague)
  • Multilingual Support: Support for multiple languages using mT5
  • Email Templates: Pre-built templates for common scenarios
  • Rich Text Editor: Format output with bold, italics, bullet points
  • Batch Processing: Bulk email rewriting via CSV upload
  • Analytics Dashboard: Usage metrics and insights
  • Email Client Integration: Gmail and Outlook plugins
  • Feedback Loop: User ratings to improve model performance

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a 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

Contribution Guidelines

  • Write clear commit messages
  • Add tests for new features
  • Update documentation as needed
  • Follow PEP 8 style guide for Python code
  • Ensure all tests pass before submitting PR

๐Ÿ“„ License

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


๐Ÿ‘ฅ Authors

  • ARUNAGIRINATHAN K - Initial work - MyGitHub

๐Ÿ“ž Contact & Support


โญ Star this repo if you find it helpful!

Made by ARUNAGIRINATHAN

```

About

Refine your emails with AI-powered clarity, tone, and precision

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published