Giter VIP home page Giter VIP logo

deeptrain-community / chatnio-blob-service Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 23.0 52 KB

πŸ“¦ Out-Of-The-Box & Powerful File Parsing Service, support Text/Pdf/Docx/Pptx/Xlsx/Image/Audio parsing, support OCR, support Base64/Local/S3/R2/TG/MinIO storage.

Home Page: https://blob.chatnio.net

License: Apache License 2.0

Python 64.75% Shell 2.51% HTML 31.92% Dockerfile 0.82%
blob fileparser ocr storage

chatnio-blob-service's Introduction

πŸ“¦ Chat Nio Blob Service

File Service for Chat Nio

Deploy to Vercel

Features

  • ⚑ Out-of-the-Box: No External Dependencies Required & Support Vercel/Render One-Click Deployment
  • ⭐ Multiple File Types: Support Text, Pdf, Docx, Excel, Image, Audio etc.
  • πŸ“¦ Multiple Storage Options: Base64, Local, S3, Cloudflare R2, Min IO, Telegram CDN etc.
  • πŸ” OCR Support: Extract Text from Image (Require Paddle OCR API)
  • πŸ”Š Audio Support: Convert Audio to Text (Require Azure Speech to Text Service)

Supported File Types

  • Text
  • Image (require vision models)
  • Audio (require Azure Speech to Text Service)
  • Docx (not support .doc)
  • Pdf
  • Pptx (not support .ppt)
  • Xlsx (support .xls)

Deploy by Docker

Image: programzmh/chatnio-blob-service

docker run -p 8000:8000 programzmh/chatnio-blob-service

# with environment variables
# docker run -p 8000:8000 -e AZURE_SPEECH_KEY="..." -e AZURE_SPEECH_REGION="..." programzmh/chatnio-blob-service


# if you are using `local` storage type, you need to mount volume (/static) to the host
# docker run -p 8000:8000 -v /path/to/static:/static programzmh/chatnio-blob-service

Deploy to Render.com

Deploy to Render

Select Web Service and Docker Image, then input the image programzmh/chatnio-blob-service and click Create Web Service.

⭐ Render.com Includes Free 750 Hours of Usage per Month

Deploy by Source Code

The service will be running on http://localhost:8000

Run

git clone --branch=main https://github.com/Deeptrain-Community/chatnio-blob-service
cd chatnio-blob-service

pip install -r requirements.txt
uvicorn main:app

# enable hot reload
# uvicorn main:app --reload

API

POST /upload Upload a file

{
    "file": "file",
    "model": "gpt-4-turbo-preview" // optional (for ocr models detection)
}

Response

{
  "status": true,
  "type": "pdf",
  "content": "...",
  "error": ""
}

Environment Variables

🎨 General Config (Optional)

  • PDF_MAX_IMAGES: Max Images Extracted from a PDF File
    • 0: Never Extract Images
    • -1: Extract All Images
    • other: Extract Top N Images
    • Tips: The extracted images will be treated as a normal image file and directly processed.
  • MAX_FILE_SIZE: Max Uploaded File Size MiB (Default: No Limit)
    • Tips: Size limit is also depend on the server configuration (e.g. Nginx/Apache Config, Vercel Free Plan Limit 5MB Body Size)
  • CORS_ALLOW_ORIGINS: CORS Allow Origins (Default: *)
  • AZURE_SPEECH_KEY: Azure Speech to Text Service Key (Required for Audio Support)
  • AZURE_SPEECH_REGION: Azure Speech to Text Service Region (Required for Audio Support)

πŸ–Ό Image Storage Config (Optional)

Note

When OCR is enabled, the service will firstly using OCR then store the images.

You can configure the OCR Advanced Config to control the OCR Models Filtering.

  1. ✨ No Storage (Default)

    • No Storage Required & No External Dependencies
    • Base64 Encoding/Decoding
    • Support Serverless Deployment Without Storage (e.g. Vercel)
    • No Direct URL Access (Base64 not support models like gpt-4-all)
  2. πŸ“ Local Storage

    • Require Server Environment (e.g. VPS, Docker)
    • Support Direct URL Access
    • Payless Storage Cost
    • Config:
      • set env STORAGE_TYPE to local (e.g. STORAGE_TYPE=local)
      • set env LOCAL_STORAGE_DOMAIN to your deployment domain (e.g. LOCAL_STORAGE_DOMAIN=http://blob-service.onrender.com)
      • if you are using Docker, you need to mount volume /static to the host (e.g. -v /path/to/static:/static)
  3. πŸš€ AWS S3

    • Payment Storage Cost
    • Support Direct URL Access
    • China Mainland User Friendly
    • Config:
      • set env STORAGE_TYPE to s3 (e.g. STORAGE_TYPE=s3)
      • set env S3_ACCESS_KEY to your AWS Access Key ID
      • set env S3_SECRET_KEY to your AWS Secret Access Key
      • set env S3_BUCKET to your AWS S3 Bucket Name
      • set env S3_REGION to your AWS S3 Region
  4. πŸ”” Cloudflare R2

    • Free Storage Quota (10GB Storage & Zero Outbound Cost)
    • Support Direct URL Access
    • Config (S3 Compatible):
      • set env STORAGE_TYPE to s3 (e.g. STORAGE_TYPE=s3)
      • set env S3_ACCESS_KEY to your Cloudflare R2 Access Key ID
      • set env S3_SECRET_KEY to your Cloudflare R2 Secret Access Key
      • set env S3_BUCKET to your Cloudflare R2 Bucket Name
      • set env S3_DOMAIN to your Cloudflare R2 Domain Name (e.g. https://<account-id>.r2.cloudflarestorage.com)
      • set env S3_DIRECT_URL_DOMAIN to your Cloudflare R2 Public URL Access Domain Name (Open Public URL Access, e.g. https://pub-xxx.r2.dev)
  5. πŸ“¦ Min IO

    • Self Hosted
    • Reliable & Flexible Storage
    • Config (S3 Compatible):
      • set env STORAGE_TYPE to s3 (e.g. STORAGE_TYPE=s3)
      • set env S3_SIGN_VERSION to s3v4 (e.g. S3_SIGN_VERSION=s3v4)
      • set env S3_ACCESS_KEY to your Min IO Access Key ID
      • set env S3_SECRET_KEY to your Min IO Secret Access Key
      • set env S3_BUCKET to your Min IO Bucket Name
      • set env S3_DOMAIN to your Min IO Domain Name (e.g. https://oss.example.com)
      • [Optional] If you are using CDN, you can set S3_DIRECT_URL_DOMAIN to your Min IO Public URL Access Domain Name (e.g. https://cdn-hk.example.com)
  6. ❀ Telegram CDN

    • Free Storage (Rate Limit)
    • Support Direct URL Access (China Mainland User Unfriendly)
    • Config:
      • set env STORAGE_TYPE to tg (e.g. STORAGE_TYPE=tg)
      • set env TG_ENDPOINT to your TG-STATE Endpoint (e.g. TG_ENDPOINT=https://tgstate.vercel.app)
      • [Optional] if you are using password authentication, you can set TG_PASSWORD to your TG-STATE Password

πŸ” OCR Config (Optional)

Note

OCR Support is based on PaddleOCR API, please deploy the API to use OCR feature.

When OCR is enabled, the service will automatically extract text from the image and skip the original image storage solution below.

Advanced OCR Config:

Warning

Advanced Config Chat Nio Supported Version >= 4.3.1 or 3.10.9

  • OCR_SKIP_MODELS: Skip OCR Models List (Commonly for Vision Models)
    • e.g.: gpt-4-v,gpt-4-vision-preview,gpt-4-turbo, then the service will skip these models and directly store the image.
      • Tips: Each model has character inclusion matching, so when you set gpt-4-v model, it will skip all models that contain gpt-4-v (like azure-gpt-4-vision-preview, gpt-4-vision-preview will be also matched).
  • OCR_SPEC_MODELS: Specific OCR Models List (Commonly for Non-Vision Models)
    • then although the image has marked as SKIP_MODELS, the service will still ocr process the image with this model first.
    • for example, when you set gpt-4-turbo to SKIP_MODELS (because gpt-4-turbo support vision and don't need to use OCR, gpt-4-turbo-preview cannot vision and need OCR), commonly the gpt-4-turbo-preview will be marked as gpt-4-turbo and skipped, then you can set gpt-4-turbo-preview to SPEC_MODELS to force OCR process.

EXAMPLE OCR Config:

OCR_ENABLED=1
OCR_ENDPOINT=http://example.com:8000
OCR_SKIP_MODELS=vision,gpt-4-v,gpt-4-all,gpt-4-vision-preview,gpt-4-1106-vision-preview,gpt-4-turbo,gemini-pro-vision,gemini-1.5-pro,claude-3,glm-4v
OCR_SPEC_MODELS=gpt-4-turbo-preview,claude-3-haiku

Development

  • ~/config.py: Env Config
  • ~/main.py: Entry Point
  • ~/utils.py: Utilities
  • ~/handlers: File Handlers
  • ~/store: Storage Handlers
  • ~/static: Static Files (if using local storage)

Tech Stack

  • Python & FastAPI

License

Apache License 2.0

chatnio-blob-service's People

Contributors

zmh-program avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chatnio-blob-service's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.