Skip to content

Commit

Permalink
Add API documentation for user authentication, document management, a…
Browse files Browse the repository at this point in the history
…nd error responses; enhance landing page with document support information; update version in base template; create results documentation for version 1.0
  • Loading branch information
Wambaforestin committed Dec 14, 2024
1 parent 7953ce0 commit c18b2e8
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 4 deletions.
209 changes: 206 additions & 3 deletions document_analysis/app_documentation.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,235 @@
# Deployment Guide

## API Documentation

### Authentication

### Register a new user

```http
POST /auth/register
Content-Type: application/x-www-form-urlencoded
username=example&password=secure_password
```

**Response**: 302 Redirect to login page

### Login

```http
POST /auth/#
Content-Type: application/x-www-form-urlencoded
username=example&password=secure_password
```

**Response**: 302 Redirect to dashboard

### Document Management

### Upload Document

```http
POST /upload
Content-Type: multipart/form-data
file: <document_file>
```

**Response**:

```json
{
"message": "File successfully processed",
"text": "extracted text content",
"document_id": 123
}
```

### Generate Quiz

```http
POST /generate_quiz
Content-Type: application/json
{
"text": "document content",
"document_id": 123
}
```

**Response**:

```json
{
"quiz": {
"multiple_choice": [...],
"fill_in_blank": [...],
"true_false": [...]
}
}
```

### Generate Summary

```http
POST /summarize
Content-Type: application/json
{
"text": "document content",
"length": "medium",
"document_id": 123
}
```

**Response**:

```json
{
"summary": "Generated summary content"
}
```

### Extract Keywords

```http
POST /extract_keywords
Content-Type: application/json
{
"text": "document content",
"document_id": 123
}
```

**Response**:

```json
{
"keywords": ["keyword1", "keyword2", ...]
}
```

### Translate Document

```http
POST /translate
Content-Type: application/json
{
"text": "document content",
"target_language": "Spanish",
"document_id": 123
}
```

**Response**:

```json
{
"translation": "Translated content"
}
```

### Error Responses

### 400 Bad Request

```json
{
"error": "Error message describing the problem"
}
```

### 401 Unauthorized

```json
{
"error": "Login required"
}
```

### 404 Not Found

```json
{
"error": "Requested resource not found"
}
```

### 500 Internal Server Error

```json
{
"error": "Internal server error"
}
```

### Authentication

All endpoints except registration and login require authentication. Include session cookie received after login.

### Testing the API (COMMING SOON...)

Example using curl:

```bash
# Upload document
curl -X POST -F "file=@document.pdf" http://localhost:5000/upload

# Generate quiz
curl -X POST \
-H "Content-Type: application/json" \
-d '{"text":"content", "document_id":123}' \
http://localhost:5000/generate_quiz
```

## Development Notes

1. API version: v1
2. Base URL: `http://localhost:5000` (development)

## Local Development Setup

1. Clone the repository:

```bash
git clone <repository-url>
cd document-analysis
```

2. Create and activate 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 environment variables:
Create a `.env` file with the following contents:
Create a `.env` file with the following contents:

```
FLASK_APP=document_analysis
FLASK_ENV=development
GEMINI_API_KEY=your_api_key_here
```

5. Initialize database:

```bash
flask init-db
```

6. Run development server:

```bash
flask run
```
Expand All @@ -42,11 +239,13 @@ flask run
### Using Gunicorn and Nginx

1. Install production dependencies:

```bash
pip install gunicorn
```

2. Create systemd service file `/etc/systemd/system/document-analysis.service`:

```ini
[Unit]
Description=Document Analysis Flask App
Expand All @@ -66,6 +265,7 @@ WantedBy=multi-user.target
```

3. Configure Nginx `/etc/nginx/sites-available/document-analysis`:

```nginx
server {
listen 80;
Expand All @@ -84,7 +284,7 @@ server {
```

4. Enable and start services:

```bash
sudo systemctl enable document-analysis
sudo systemctl start document-analysis
Expand All @@ -95,6 +295,7 @@ sudo systemctl restart nginx
### Docker Deployment

Create `Dockerfile`:

```dockerfile
FROM python:3.9-slim

Expand All @@ -115,6 +316,7 @@ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "document_analysis:create_app(
```

Create `docker-compose.yml`:

```yaml
version: '3'
services:
Expand All @@ -129,6 +331,7 @@ services:
```
Deploy with Docker:
```bash
docker-compose up -d
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ <h3 class="text-xl font-semibold mb-2">Translation</h3>
<h3 class="text-xl font-semibold mb-2">Keyword Analysis</h3>
<p class="text-gray-600">Extract keywords and phrases from your documents</p>
</div>
<!-- document support PDF, TXT DOCX -->
<div class="bg-white p-6 rounded-xl shadow-lg hover:shadow-xl transition">
<div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center mb-4">
<svg class="w-6 h-6 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
</div>
<h3 class="text-xl font-semibold mb-2">Document Support</h3>
<p class="text-gray-600">Supports PDF, TXT, DOCX file formats</p>
</div>
</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion document_analysis/document_analysis/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<div class="flex-shrink-0">
<a href="{{ url_for('index') }}" class="text-white font-bold text-xl">
Document Analysis
<span class="text-sm text-purple-200">Version Beta</span>
<span class="text-sm text-purple-200">
Version 1.2.0
</span>
</a>
</div>
<div class="hidden md:block">
Expand Down
Loading

0 comments on commit c18b2e8

Please # to comment.