Spaces:
Runtime error
Runtime error
File size: 2,641 Bytes
ec96972 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# HackRx Insurance Policy Assistant
A FastAPI application that processes PDF documents and answers questions using AI, deployed on Hugging Face Spaces.
## Features
- PDF document parsing and text extraction
- Vector-based document search using FAISS
- AI-powered question answering using Google Gemini
- RESTful API endpoints for document processing
## API Endpoints
### Health Check
- `GET /` - Root endpoint
- `GET /health` - API status check
### Process PDF from URL
- `POST /api/v1/hackrx/run`
- **Headers**: `Authorization: Bearer <your_token>`
- **Body**:
```json
{
"documents": "https://example.com/document.pdf",
"questions": ["What is the coverage amount?", "What are the exclusions?"]
}
```
### Process Local PDF File
- `POST /api/v1/hackrx/local`
- **Body**:
```json
{
"document_path": "/app/files/document.pdf",
"questions": ["What is the coverage amount?", "What are the exclusions?"]
}
```
## Environment Variables
Set these in your Hugging Face Space settings:
- `GOOGLE_API_KEY` - Your Google Gemini API key
## Usage Examples
### Using curl
```bash
# Health check
curl https://your-space-name.hf.space/
# Process PDF from URL
curl -X POST https://your-space-name.hf.space/api/v1/hackrx/run \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_token_here" \
-d '{
"documents": "https://example.com/insurance-policy.pdf",
"questions": ["What is the coverage amount?", "What are the exclusions?"]
}'
```
### Using Python
```python
import requests
# Health check
response = requests.get("https://your-space-name.hf.space/")
print(response.json())
# Process PDF
url = "https://your-space-name.hf.space/api/v1/hackrx/run"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer your_token_here"
}
data = {
"documents": "https://example.com/insurance-policy.pdf",
"questions": ["What is the coverage amount?", "What are the exclusions?"]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
```
## Local Development
To run the application locally:
```bash
pip install -r requirements.txt
python app.py
```
The API will be available at `http://localhost:7860`
## Deployment
This application is configured for deployment on Hugging Face Spaces using Docker. The following files are included:
- `app.py` - Main application entry point
- `Dockerfile` - Docker configuration
- `.dockerignore` - Docker build optimization
- `requirements.txt` - Python dependencies
## Model Information
- **Framework**: FastAPI
- **AI Model**: Google Gemini
- **Vector Database**: FAISS
- **Document Processing**: PyMuPDF |