File size: 3,027 Bytes
3530326
3719fca
3530326
 
 
 
 
 
 
3719fca
3530326
3719fca
3530326
 
 
 
 
 
 
 
3719fca
270d701
 
3530326
 
 
52d25f7
 
3530326
 
 
52d25f7
 
 
 
3719fca
3530326
 
52d25f7
270d701
 
52d25f7
 
3530326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3719fca
3530326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3719fca
3530326
 
 
 
 
 
 
 
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
---
title: Cohere Parse
sdk: gradio
sdk_version: 6.21.0
python_version: 3.12
app_file: app.py
pinned: false
---

# Cohere Parse

An account-free document parsing playground for Cohere Parse. Upload a PDF or
image, inspect the normalized page render, and review extracted text, tables,
and bounding boxes.

## Behavior

- Accepts one PDF, PNG, JPEG, or WebP up to 20 MB.
- Renders documents at up to 200 DPI and a 2,048 pixel maximum edge.
- Processes the first 10 pages and warns when additional pages are omitted.
- Re-encodes every page as lossless PNG before calling the Cohere API.
- Sends image-only `/v2/parse` requests with structured block output and does
  not persist parser output.

## Configuration

Set these in the Hugging Face Space's **Settings** page. Store API keys as
Space secrets; the other values can be public Space variables.

| Name | Default | Type |
| --- | --- | --- |
| `COHERE_ENV` | `staging` | Variable |
| `COHERE_API_KEY` | required in production | Secret |
| `COHERE_STG_API_KEY` | required in staging | Secret |
| `COHERE_API_URL` | selected from `COHERE_ENV` | Optional variable override |
| `COHERE_MODEL` | `parse-v5.0` | Variable |
| `COHERE_TIMEOUT` | `300` | Variable |

`COHERE_ENV=production` uses `COHERE_API_KEY` and
`https://api.cohere.com/v2/parse`. `COHERE_ENV=staging` uses
`COHERE_STG_API_KEY` and `https://stg.api.cohere.ai/v2/parse`. Keep
`COHERE_API_URL` unset unless routing through an intentional custom endpoint.

Use a dedicated, revocable API key with a quota appropriate for a public demo.

## Local development

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt
cp .env.example .env
set -a && source .env && set +a
python app.py
```

Open `http://127.0.0.1:7860`.

## Checks

```bash
pytest
python -m compileall app.py document_processing.py parser_client.py parser_output.py rate_limit.py ui_helpers.py
```

An integration test against staging is skipped unless
`RUN_STAGING_INTEGRATION=1`, `COHERE_STG_API_KEY` is configured, and a local sample
document is available.

## Deploy

Create a private Gradio Space under `CohereLabs`, configure the secret and
variables above, then upload this repository:

```bash
hf auth login
hf upload CohereLabs/cohere-parse . . --repo-type space
```

Every commit uploaded to the Space rebuilds and restarts the app. Keep the
Space private during review, then switch it to protected visibility for a
public app with private source.

## Privacy and security

Uploaded files are decoded in the Space, converted to normalized PNG page
images, and deleted after preparation. Only those page images are sent to the
Cohere API. Gradio may temporarily cache uploaded files while processing them;
the app deletes source files explicitly and also configures short cache
cleanup.

The application also enforces upload, page, pixel, queue, concurrency, and
per-client request limits. These controls reduce abuse but do not replace a
gateway-enforced quota on the API credential.