Skip to main content

Grammar checking using Ai

Project description

Grammar Checking Application

This project is a Flask-based web application that allows users to upload text, CSV, or Excel files to analyze their content for grammatical errors using the Gemini AI API. The application processes the file, corrects grammar issues, and provides the corrected content along with explanations for the changes. The corrected file can also be downloaded.


Features

  • Upload files in .txt, .csv, or .xlsx formats.
  • Analyze uploaded content for grammatical correctness and formality using the Gemini API.
  • View corrected sentences and explanations for corrections.
  • Download the corrected file in the same format as the uploaded file.
  • Interactive web interface built with Flask.

Prerequisites

  1. Python 3.7+
  2. Installed dependencies from requirements.txt (see below).
  3. A valid API key for the Gemini API.

Installation

1. Clone the Repository

git clone <repository-url>
cd <repository-folder>

2. Create a Virtual Environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Set Up Upload Folder

Ensure the uploads folder exists in the project directory. The folder is used to store uploaded files during processing:

mkdir uploads

5. Configure Gemini API Key

Replace the placeholder API key in app.py with your actual API key:

genai.configure(api_key="<your-gemini-api-key>")

Running the Application

1. Start the Flask Server

Run the application using the following command:

python app.py

2. Access the Application

Open your web browser and navigate to:

http://127.0.0.1:5000/

Usage

  1. Upload File: Select and upload a .txt, .csv, or .xlsx file.
  2. Process File: The application sends the file's content to the Gemini API for grammar analysis and correction.
  3. View Results: View the corrected sentences along with explanations in a table format.
  4. Download File: Click the download link to save the corrected file locally.

Project Structure

project/
├── app.py                 # Main Flask application
├── templates/
│   └── index.html         # HTML template for the web interface
├── static/                # Static assets (CSS, JS, etc.)
├── uploads/               # Folder to store uploaded files
├── requirements.txt       # Python dependencies
└── README.md              # Project documentation

API Integration

Gemini API Configuration

The Gemini API is used for grammar correction. Ensure you have a valid API key and replace the placeholder in app.py:

genai.configure(api_key="<your-gemini-api-key>")

Key Methods

  1. check_grammar(file_path):

    • Sends the file content to the Gemini API.
    • Returns the API response.
  2. extract_corrections(response):

    • Parses the API response to extract original sentences, corrections, and explanations.
  3. process_file(file_path):

    • Processes the uploaded file.
    • Calls check_grammar and extract_corrections.
    • Outputs the corrected file and a DataFrame of corrections.

Error Handling

  • File Format Validation: Ensures only .txt, .csv, or .xlsx files are accepted.
  • API Errors: Handles exceptions during API calls and provides error messages to the user.
  • Missing File: Validates the presence of the uploaded file.

Example

Input File

Original Sentences:

  • "He go to school every day."
  • "I is happy."

Output

Corrected Sentences:

  • Original: "He go to school every day."

    • Corrected: "He goes to school every day."
    • Explanation: "Verb agreement corrected."
  • Original: "I is happy."

    • Corrected: "I am happy."
    • Explanation: "Verb form corrected."

License

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


Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GrammarlyAPI-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

GrammarlyAPI-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file GrammarlyAPI-0.1.0.tar.gz.

File metadata

  • Download URL: GrammarlyAPI-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for GrammarlyAPI-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5975aff40b4b72a5f614c6a78c4814a3449811657cd5205705a1bc0b04ff1ed7
MD5 d2a180e693a8d00f15163fe0cacaccf1
BLAKE2b-256 c831d4e868f587db7499c3b83ed8dea4654895f2db20ccde76eb9d6a87194881

See more details on using hashes here.

File details

Details for the file GrammarlyAPI-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: GrammarlyAPI-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for GrammarlyAPI-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f27a5d146f1bca241edbeb1150a2360a2eff765239c0e206d1d49f33c7769af5
MD5 0849c2797c0f863d602a46fe25e07379
BLAKE2b-256 5a42c664a8110b50e166b3b27f1a0d1dac1aeea4272672e9176bb45090cffc26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page