File size: 1,041 Bytes
2b67506
 
 
 
 
 
 
 
 
 
 
d2237d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Magbert Ner Api
emoji: πŸƒ
colorFrom: yellow
colorTo: indigo
sdk: docker
pinned: false
short_description: magbert-ner-fr-api
---


# Private BERT NER API on Hugging Face Space

This repo contains a private FastAPI-based NER API built on a Hugging Face BERT model.

## Features
- Private Hugging Face model loading
- FastAPI REST endpoint for NER
- Token-based authentication (`X-API-KEY`)
- Rate limiting per IP using `slowapi`
- Usage tracking per API key

## Run locally
```bash
export HF_TOKEN=your_hf_token
export X-API-KEY=your-secret-key
uvicorn app:app --reload
```

## Example request
```bash
curl -X POST http://localhost:8000/ner \
 -H "X-API-KEY: your-secret-key" \
 -H "Content-Type: application/json" \
 -d '{"text": "Barack Obama was the president of the United States."}'
```

## Deployment
Can be deployed to Hugging Face Spaces (with Docker option enabled) or any cloud with Docker support.

### Hugging Face Space Setup
- Make sure to enable **Docker** runtime
- Add two secrets:
  - `HF_TOKEN`
  - `X-API-KEY`