cohere-parse / README.md
dennis-zhao's picture
Migrate to the Parse API
270d701 verified
|
Raw History Blame Contribute Delete
3.03 kB
---
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.