Robin Claude Sonnet 4.6 commited on
Commit ·
e48047d
1
Parent(s): eb553d1
deploy: pre-download model in Dockerfile, update README routes
Browse files- Dockerfile: bake GLiNER model into image at build time so cold-start
needs no network and starts instantly on HF Spaces
- README: update routes to /api/v1/, threshold to 0.6, add HF Space URL
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Dockerfile +6 -0
- README.md +28 -17
Dockerfile
CHANGED
|
@@ -5,6 +5,12 @@ WORKDIR /app
|
|
| 5 |
COPY requirements.txt .
|
| 6 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
COPY app/ app/
|
| 9 |
COPY run.py .
|
| 10 |
|
|
|
|
| 5 |
COPY requirements.txt .
|
| 6 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
|
| 8 |
+
# Pre-download model at build time so cold-start needs no network access.
|
| 9 |
+
# The image will be ~1.5 GB but startup is instant.
|
| 10 |
+
RUN python -c "\
|
| 11 |
+
from gliner import GLiNER; \
|
| 12 |
+
GLiNER.from_pretrained('urchade/gliner_medium-v2.1', cache_dir='/app/model_cache')"
|
| 13 |
+
|
| 14 |
COPY app/ app/
|
| 15 |
COPY run.py .
|
| 16 |
|
README.md
CHANGED
|
@@ -14,13 +14,23 @@ Zero-shot Named Entity Recognition HTTP API powered by [GLiNER](https://github.c
|
|
| 14 |
|
| 15 |
## API
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
```json
|
| 20 |
{
|
| 21 |
-
"text": "Elon Musk founded SpaceX in
|
| 22 |
-
"labels": ["person", "organization"],
|
| 23 |
-
"threshold": 0.
|
| 24 |
}
|
| 25 |
```
|
| 26 |
|
|
@@ -29,23 +39,24 @@ Zero-shot Named Entity Recognition HTTP API powered by [GLiNER](https://github.c
|
|
| 29 |
```json
|
| 30 |
{
|
| 31 |
"entities": [
|
| 32 |
-
{"text": "Elon Musk",
|
| 33 |
-
{"text": "SpaceX",
|
|
|
|
|
|
|
| 34 |
]
|
| 35 |
}
|
| 36 |
```
|
| 37 |
|
| 38 |
-
##
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
```
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
##
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
| `MODEL_NAME` | `urchade/gliner_medium-v2.1` | GLiNER model name |
|
| 49 |
-
| `PORT` | `7860` | Listen port |
|
| 50 |
-
| `MODEL_CACHE_DIR` | `./model_cache` | Local model cache |
|
| 51 |
-
| `HF_ENDPOINT` | *(huggingface.co)* | Custom HF mirror URL |
|
|
|
|
| 14 |
|
| 15 |
## API
|
| 16 |
|
| 17 |
+
Base URL: `https://<your-hf-username>-ner-server.hf.space`
|
| 18 |
+
|
| 19 |
+
### `GET /api/v1/health`
|
| 20 |
+
|
| 21 |
+
```json
|
| 22 |
+
{"status": "ok"}
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
### `POST /api/v1/extract`
|
| 26 |
+
|
| 27 |
+
**Request**
|
| 28 |
|
| 29 |
```json
|
| 30 |
{
|
| 31 |
+
"text": "Elon Musk founded SpaceX in Hawthorne, California.",
|
| 32 |
+
"labels": ["person", "organization", "location"],
|
| 33 |
+
"threshold": 0.6
|
| 34 |
}
|
| 35 |
```
|
| 36 |
|
|
|
|
| 39 |
```json
|
| 40 |
{
|
| 41 |
"entities": [
|
| 42 |
+
{"text": "Elon Musk", "label": "person", "score": 0.98, "start": 0, "end": 9 },
|
| 43 |
+
{"text": "SpaceX", "label": "organization", "score": 0.97, "start": 18, "end": 24},
|
| 44 |
+
{"text": "Hawthorne", "label": "location", "score": 0.91, "start": 28, "end": 37},
|
| 45 |
+
{"text": "California", "label": "location", "score": 0.95, "start": 39, "end": 49}
|
| 46 |
]
|
| 47 |
}
|
| 48 |
```
|
| 49 |
|
| 50 |
+
## Environment Variables
|
| 51 |
|
| 52 |
+
| Variable | Default | Description |
|
| 53 |
+
|-------------------|-------------------------------|------------------------------------|
|
| 54 |
+
| `MODEL_NAME` | `urchade/gliner_medium-v2.1` | GLiNER model name |
|
| 55 |
+
| `PORT` | `7860` | Listen port (fixed by HF Spaces) |
|
| 56 |
+
| `MODEL_CACHE_DIR` | `/app/model_cache` | Model cache path |
|
| 57 |
+
| `HF_ENDPOINT` | *(huggingface.co)* | Override with a custom mirror URL |
|
| 58 |
|
| 59 |
+
## Interactive Docs
|
| 60 |
|
| 61 |
+
- Swagger UI: `/docs`
|
| 62 |
+
- ReDoc: `/redoc`
|
|
|
|
|
|
|
|
|
|
|
|