CoolFace
Apppublic

ek-developers/my-ocr-api

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

๐Ÿ” DeepSeek OCR API

A self-hosted OCR API powered by DeepSeek-OCR via Ollama, deployed on Hugging Face Spaces using Docker. Upload an image and receive extracted text โ€” with support for custom prompts.


๐Ÿš€ Live Demo

https://ek-developers-my-ocr-api.hf.space

Interactive API docs available at:

https://ek-developers-my-ocr-api.hf.space/docs

๐Ÿ“ Project Structure

โ”œโ”€โ”€ Dockerfile        # Container setup with Ollama + Python dependencies
โ”œโ”€โ”€ start.sh          # Runtime script: installs Ollama, pulls model, starts API
โ”œโ”€โ”€ app.py            # FastAPI application
โ””โ”€โ”€ README.md         # Documentation

๐Ÿ› ๏ธ Tech Stack

ComponentTechnology
OCR Modeldeepseek-ocr via Ollama
API FrameworkFastAPI
ServerUvicorn
ContainerDocker (Ubuntu 22.04)
HostingHugging Face Spaces (Free CPU)

๐Ÿ“ก API Reference

GET /

Health check โ€” confirms the API is running.

Response

json
{
  "message": "DeepSeek OCR API running. POST an image to /ocr"
}

GET /health

Lightweight health probe.

Response

json
{
  "status": "ok"
}

POST /ocr

Upload an image and extract text from it.

Request โ€” multipart/form-data

FieldTypeRequiredDefaultDescription
fileimage fileโœ…โ€”The image to process (jpg, png, etc.)
prompt_textstringโŒFree OCR.Custom instruction passed to the model

Example โ€” default prompt

bash
curl -X POST https://ek-developers-my-ocr-api.hf.space/ocr \
  -F "file=@receipt.jpg"

Example โ€” custom prompt

bash
curl -X POST https://ek-developers-my-ocr-api.hf.space/ocr \
  -F "file=@menu.jpg" \
  -F "prompt_text=Extract all menu items and prices."

Response

json
{
  "text": "Extracted text from the image..."
}

Error Responses

StatusMeaning
400File is not an image
504Model timed out (>120s)
500Internal server error

โš™๏ธ Local Development

Prerequisites

  • โ€”Ollama installed locally
  • โ€”Python 3.10+

Setup

bash
# 1. Pull the model
ollama pull deepseek-ocr

# 2. Install Python dependencies
pip install fastapi uvicorn requests pydantic python-multipart

# 3. Run the API
uvicorn app:app --host 0.0.0.0 --port 7860 --reload

Test locally

bash
curl -X POST http://localhost:7860/ocr \
  -F "file=@image.jpg" \
  -F "prompt_text=Free OCR."

๐Ÿณ Docker

Build and run locally

bash
docker build -t deepseek-ocr-api .
docker run -p 7860:7860 deepseek-ocr-api

โš ๏ธ Performance Notes

This Space runs on free-tier CPU hardware (16GB RAM, no GPU).

ConditionExpected Response Time
First request (cold start)2โ€“3 minutes (model loading)
Subsequent requests (warm)30โ€“60 seconds
After inactivity (Space sleeps)Cold start again

To reduce latency, upgrade the Space hardware to a GPU instance in Settings โ†’ Hardware.


๐Ÿ“ Example Use Cases

  • โ€”Extract text from receipts or invoices
  • โ€”Read menu items from restaurant photos
  • โ€”Parse printed forms or documents
  • โ€”Digitize handwritten or printed notes

๐Ÿ“„ License

MIT License โ€” free to use and modify.