GrammarlyAPI 0.1.0
Grammar checking using Ai
Requires Python: >=3.6

# 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
```bash
git clone <repository-url>
cd <repository-folder>
```

### 2. Create a Virtual Environment
```bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
```

### 3. Install Dependencies
```bash
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:
```bash
mkdir uploads
```

### 5. Configure Gemini API Key
Replace the placeholder API key in `app.py` with your actual API key:
```python
genai.configure(api_key="<your-gemini-api-key>")
```

---

## Running the Application

### 1. Start the Flask Server
Run the application using the following command:
```bash
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`:
```python
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
- [Google Generative AI API](https://ai.google/) for grammar correction.