Image-Text-to-Text
Safetensors
multilingual
deepseek_vl_v2
deepseek
unsloth
vision-language
ocr
custom_code
Instructions to use unsloth/DeepSeek-OCR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Local Apps Settings
- Unsloth Studio
How to use unsloth/DeepSeek-OCR with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/DeepSeek-OCR to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/DeepSeek-OCR to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/DeepSeek-OCR to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/DeepSeek-OCR", max_seq_length=2048, )
Change eval to ast.literal_eval
#5
by danielhanchen - opened
- modeling_deepseekocr.py +8 -7
modeling_deepseekocr.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
import os
|
| 3 |
import math
|
| 4 |
import re
|
|
|
|
| 5 |
from tqdm import tqdm
|
| 6 |
from abc import ABC
|
| 7 |
from typing import List, Optional, Tuple, Union
|
|
@@ -66,7 +67,7 @@ def extract_coordinates_and_label(ref_text, image_width, image_height):
|
|
| 66 |
|
| 67 |
try:
|
| 68 |
label_type = ref_text[1]
|
| 69 |
-
cor_list =
|
| 70 |
except Exception as e:
|
| 71 |
print(e)
|
| 72 |
return None
|
|
@@ -1003,12 +1004,12 @@ class DeepseekOCRForCausalLM(DeepseekV2ForCausalLM):
|
|
| 1003 |
|
| 1004 |
if 'line_type' in outputs:
|
| 1005 |
import matplotlib.pyplot as plt
|
| 1006 |
-
lines =
|
| 1007 |
|
| 1008 |
-
line_type =
|
| 1009 |
# print(lines)
|
| 1010 |
|
| 1011 |
-
endpoints =
|
| 1012 |
|
| 1013 |
fig, ax = plt.subplots(figsize=(3,3), dpi=200)
|
| 1014 |
ax.set_xlim(-15, 15)
|
|
@@ -1016,8 +1017,8 @@ class DeepseekOCRForCausalLM(DeepseekV2ForCausalLM):
|
|
| 1016 |
|
| 1017 |
for idx, line in enumerate(lines):
|
| 1018 |
try:
|
| 1019 |
-
p0 =
|
| 1020 |
-
p1 =
|
| 1021 |
|
| 1022 |
if line_type[idx] == '--':
|
| 1023 |
ax.plot([p0[0], p1[0]], [p0[1], p1[1]], linewidth=0.8, color='k')
|
|
@@ -1032,7 +1033,7 @@ class DeepseekOCRForCausalLM(DeepseekV2ForCausalLM):
|
|
| 1032 |
for endpoint in endpoints:
|
| 1033 |
|
| 1034 |
label = endpoint.split(': ')[0]
|
| 1035 |
-
(x, y) =
|
| 1036 |
ax.annotate(label, (x, y), xytext=(1, 1), textcoords='offset points',
|
| 1037 |
fontsize=5, fontweight='light')
|
| 1038 |
|
|
|
|
| 2 |
import os
|
| 3 |
import math
|
| 4 |
import re
|
| 5 |
+
import ast
|
| 6 |
from tqdm import tqdm
|
| 7 |
from abc import ABC
|
| 8 |
from typing import List, Optional, Tuple, Union
|
|
|
|
| 67 |
|
| 68 |
try:
|
| 69 |
label_type = ref_text[1]
|
| 70 |
+
cor_list = ast.literal_eval(ref_text[2])
|
| 71 |
except Exception as e:
|
| 72 |
print(e)
|
| 73 |
return None
|
|
|
|
| 1004 |
|
| 1005 |
if 'line_type' in outputs:
|
| 1006 |
import matplotlib.pyplot as plt
|
| 1007 |
+
lines = ast.literal_eval(outputs)['Line']['line']
|
| 1008 |
|
| 1009 |
+
line_type = ast.literal_eval(outputs)['Line']['line_type']
|
| 1010 |
# print(lines)
|
| 1011 |
|
| 1012 |
+
endpoints = ast.literal_eval(outputs)['Line']['line_endpoint']
|
| 1013 |
|
| 1014 |
fig, ax = plt.subplots(figsize=(3,3), dpi=200)
|
| 1015 |
ax.set_xlim(-15, 15)
|
|
|
|
| 1017 |
|
| 1018 |
for idx, line in enumerate(lines):
|
| 1019 |
try:
|
| 1020 |
+
p0 = ast.literal_eval(line.split(' -- ')[0])
|
| 1021 |
+
p1 = ast.literal_eval(line.split(' -- ')[-1])
|
| 1022 |
|
| 1023 |
if line_type[idx] == '--':
|
| 1024 |
ax.plot([p0[0], p1[0]], [p0[1], p1[1]], linewidth=0.8, color='k')
|
|
|
|
| 1033 |
for endpoint in endpoints:
|
| 1034 |
|
| 1035 |
label = endpoint.split(': ')[0]
|
| 1036 |
+
(x, y) = ast.literal_eval(endpoint.split(': ')[1])
|
| 1037 |
ax.annotate(label, (x, y), xytext=(1, 1), textcoords='offset points',
|
| 1038 |
fontsize=5, fontweight='light')
|
| 1039 |
|