Instructions to use mychen76/mistral7b_ocr_to_json_v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mychen76/mistral7b_ocr_to_json_v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mychen76/mistral7b_ocr_to_json_v1")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mychen76/mistral7b_ocr_to_json_v1") model = AutoModelForCausalLM.from_pretrained("mychen76/mistral7b_ocr_to_json_v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use mychen76/mistral7b_ocr_to_json_v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mychen76/mistral7b_ocr_to_json_v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mychen76/mistral7b_ocr_to_json_v1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/mychen76/mistral7b_ocr_to_json_v1
- SGLang
How to use mychen76/mistral7b_ocr_to_json_v1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mychen76/mistral7b_ocr_to_json_v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mychen76/mistral7b_ocr_to_json_v1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mychen76/mistral7b_ocr_to_json_v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mychen76/mistral7b_ocr_to_json_v1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use mychen76/mistral7b_ocr_to_json_v1 with Docker Model Runner:
docker model run hf.co/mychen76/mistral7b_ocr_to_json_v1
Using the model
Hello,
when I pass in "Sale #: S1 -40 1206145922\nServed by Lewis A\nS1 -40 1206145922\nDescription\nAmount\nM&M's Chocolate\n£1.50\nSubtotal:\n£1.50\nTotal ex tax:\n- VAT\n£1.25\n£0.25\nTotal Inc Tax:\nMethod\nVisa\n£1.50\nAmount\n£1.50\nPrices shown in GBP\n2023-12-06 14:59:39\nRegister: Soho POS 1\nPrinter: Soho Works Shoreditch - POS 1-TM-m30_02\n7738\nSale ID: k3vvig7k\nVAT: 283 1918 86\n"
The model does not return an expected outcome i.e.
{ "receipt": { "store": "BAJA FRESH", "manager": "GENERAL MANAGER: NORMAN", "address": "176 Rosa C", "check": "Chk 7545", "date": "Dec26'0707:26PM", "tax": "Gst0", "total": "20.00", "payment": "CASH", "change": "0.61", "discount": "Discount on purchases of $5.00 or more,Offer expires in 30 day", "coupon": "Use this receipt as coupon", "survey": "Take our brief survey", "redemption": "Write down redemption code", "prompt": "When Prompted, Enter Store Write down redemption code Use this receipt as coupon", "items": [ { "name": "1 BAJA STEAK", "price": "6.95", "modifiers": [ "NO GUACAMOLE", "ENCHILADO STYLE" ] }, { "name": "TAKE OUT", "price": "1.49" } ] } }
I deployed this with AN API and it did not work, even with the special characters removed. What am I doing wrong?
can you share your code and input structure here?
please take a quick look on the sample usage notebooks below:
English Receipts
model_id="mychen76/mistral7b_ocr_to_json_v1"
model_id: mychen76/mistral_ocr2json_v3_chatml
https://github.com/minyang-chen/LLM_convert_receipt_image-to-json_or_xml/blob/main/Convert_Receipt_Image-to-Json_using_OCR_to_JSON_v2_ChatML.ipynb
German Receipts
model_id="mychen76/mistral7b_ocr_to_json_v1"