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 .csv 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

GrammarFixAPI-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for GrammarFixAPI-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7745526c4f350653e0389b9642bf12df7ed4c4a82138a1fa3203fe6790b79024
MD5 d9a762d450ed54db0d85ef02d149dc15
BLAKE2b-256 8733ae3e587b339e1a0ec3e7cd0b92e8230b0dabd350c8b6f7ff52e64b11cfff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: GrammarFixAPI-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 GrammarFixAPI-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21a9951db853255aa3b1de81ad095b96fe8fde165ba65815598075e5ab769e05
MD5 e6ed7bccbcd706bce0ce58b1f0d67449
BLAKE2b-256 d58704131530f5e56554514c4fd55d1604cc3c18856d6066b5c612e1c4e31b4c

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