https://grammar-analyzer-ai-project.vercel.app/
A clean, secure, and responsive web application that uses a serverless backend to safely perform grammar and style analysis with a Hugging Face AI model.
This project is a full-stack (front-end + serverless backend) application designed to check text for grammatical correctness. It provides a "Correct" or "Incorrect" analysis along with a confidence score from the AI model.
The front-end is built with clean HTML, Tailwind CSS, and vanilla JavaScript. The backend is a secure serverless function (running on Vercel) that acts as a proxy to protect the Hugging Face API key.
- Secure API Key: The Hugging Face API key is never exposed to the browser. It is stored securely as an environment variable on the server.
- AI-Powered Analysis: Connects directly to the Hugging Face Inference API to analyze text using the
abdulmatinomotoso/English_Grammar_Checkermodel via a secure backend proxy. - Clean & Simple UI: A minimal, distraction-free interface for users to paste and check their text.
- Responsive Design: Looks great on all devices, from mobile phones to desktops.
- Real-time Word Count: Provides immediate feedback on the number of words, with a soft limit of 300.
- Clear Feedback: Displays results (Correct/Incorrect), a confidence score, and user-friendly messages.
- Loading & Error States: Includes a loading spinner and forwards clear error messages from the API (e.g., "Model is loading...").
From a user's perspective, the application works just as before:
- Open the deployed website.
- Type or paste your text (up to 300 words) into the text area.
- Click the "Check Grammar" button.
- Wait for the AI to analyze the text.
- View the results below the button, which will indicate if the text is "Correct" or "Incorrect" along with a confidence percentage.
This project is designed for an easy and secure deployment on platforms like Vercel or Netlify.
Step 1: Push to GitHub
- Make sure your project is a Git repository.
- Create a new repository on GitHub.
- Add, commit, and push your code (including the
api/check.jsfile) to your GitHub repository.
Step 2: Deploy on Vercel
- Sign up: Go to vercel.com and sign up using your GitHub account.
- Import Project: On your Vercel dashboard, click "Add New... > Project" and select your new GitHub repository.
- Configure Project: Vercel will automatically detect your static front-end and the
apifolder. You don't need to change any build settings. - Add Environment Variable (Most Important Step):
- Before deploying, expand the "Environment Variables" section.
- Add a new variable:
- Name:
HUGGING_FACE_API_KEY - Value:
hf_YOUR_SECRET_KEY_GOES_HERE
- Name:
- Click "Add" to save the variable.
- Deploy: Click the "Deploy" button.
Vercel will build and deploy your site. Your application is now live, and your API key is secure!
To run this project locally, you can no longer just use a simple Python server because you need to simulate the serverless function environment. The Vercel CLI is the best tool for this.
-
Install the Vercel CLI:
npm install -g vercel
-
Create an Environment File:
- In the root of your project, create a new file named
.env - Add your API key to this file:
HUGGING_FACE_API_KEY="hf_YOUR_SECRET_KEY_GOES_HERE" - In the root of your project, create a new file named
(Note: Make sure to add .env to your .gitignore file so you don't accidentally commit your key!)
-
Run a Local Server:
- Open your terminal in the project's root folder.
- Run the following command:
vercel dev
This command starts a local development server (like http://localhost:3000) that runs your front-end and your serverless function in api/check.js exactly as it would on Vercel, securely loading your API key from the .env file.
This project's security relies on a backend proxy pattern:
- Client: The browser (running
script.js) sends the user's text to our own backend endpoint (/api/check). - Serverless Function: The
api/check.jsfunction (running on Vercel) receives this request. It's the only part of the system that can access the secretHUGGING_FACE_API_KEYfrom its environment variables. - Hugging Face: The serverless function then makes the call to the Hugging Face API, adding the secret key.
- Response: The function gets the result from Hugging Face and passes it back to the client.
The secret API key never leaves the Vercel server, making it invisible to users.
- HTML5: Semantic structure for the application.
- Tailwind CSS: For all styling and responsive design, loaded via CDN.
- Vanilla JavaScript (ES6+): For all application logic, including DOM manipulation, event handling, and API calls.
- Node.js / Serverless Functions: For the secure backend proxy.
- Hugging Face Inference API: Powers the AI grammar analysis.
- Google Fonts: (Inter) For clean, modern typography.
- Material Symbols: For icons.
- Vercel: For deployment and local development.
📂 Project Structure
.
├── api/
│ └── check.js # The (Node.js) serverless backend function
│
├── index.html # The main HTML file
├── script.js # Client-side JavaScript (no API key!)
├── style.css # Minimal custom CSS
└── README.md # You are here!