-
Notifications
You must be signed in to change notification settings - Fork 795
Description
System Info / 系統信息
vllm 0.10.2
cuda 12.8
Running Xinference with Docker? / 是否使用 Docker 运行 Xinfernece?
- docker / docker
- pip install / 通过 pip install 安装
- installation from source / 从源码安装
Version info / 版本信息
v1.15.0
The command used to start Xinference / 用以启动 xinference 的命令
docker run
-v /opt/xinference/.xinference:/root/.xinference
-v /opt/xinference/.cache/huggingface:/root/.cache/huggingface
-v /opt/xinference/.cache/modelscope:/root/.cache/modelscope
-p 9997:9997
--shm-size 64G
--gpus all
--name xinference
xprobe/xinference:v1.15.0-cu128
xinference-local -H 0.0.0.0
Reproduction / 复现过程
我使用xinference部署的PaddleOCR-VL,在Maxkb中用函数库工具进行调用,现在图片识别调用是正常的,图片工具调用python代码是:
import requests
import mimetypes
def ocr_image_via_xinference(img_list):
"""
仅支持:图片(jpg / jpeg / png / bmp / webp / tiff)
输入:img_list(开始 → 图片)
输出:OCR 识别文本(string)
"""
if not img_list or not isinstance(img_list, list):
raise ValueError("未检测到图片输入(img_list 为空)")
f = img_list[0]
file_name = f.get("name", "")
file_url = f.get("url")
if not file_url:
raise ValueError("图片对象缺少 url 字段")
# -------- 1️⃣ 校验图片类型 --------
ext = file_name.lower().split(".")[-1]
valid_ext = ["jpg", "jpeg", "png", "bmp", "webp", "tiff", "tif"]
if ext not in valid_ext:
raise ValueError(f"当前节点仅支持图片文件,收到:.{ext}")
# -------- 2️⃣ 拼接下载地址(按你当前环境) --------
if file_url.startswith("/"):
file_url = "http://15.32.142.138:8080/admin" + file_url
elif file_url.startswith("."):
file_url = "http://15.32.142.138:8080/admin" + file_url.lstrip(".")
# -------- 3️⃣ 下载图片(二进制) --------
resp = requests.get(file_url, timeout=30)
resp.raise_for_status()
image_bytes = resp.content
# -------- 4️⃣ MIME 类型 --------
mime_type, _ = mimetypes.guess_type(file_name)
if not mime_type:
mime_type = "image/jpeg"
# -------- 5️⃣ 调用 Xinference OCR(图片专用) --------
xinference_url = "http://15.32.142.191:9997/v1/images/ocr"
files = {
"image": (file_name, image_bytes, mime_type)
}
data = {
"model": "PaddleOCR-VL"
}
ocr_resp = requests.post(
xinference_url,
files=files,
data=data,
timeout=120
)
ocr_resp.raise_for_status()
# -------- 6️⃣ 返回 OCR 文本 --------
ocr_text = ocr_resp.text.strip()
if not ocr_text:
raise RuntimeError("OCR 返回为空")
return ocr_text
但是通过函数库工具进行PDF识别的时候会报错,文件识别函数库库工具python代码:
import requests
def ocr_pdf_via_xinference(file_list):
"""
仅支持:PDF
输入:file_list(开始 → 文档)
输出:OCR 文本
"""
if not file_list or not isinstance(file_list, list):
raise ValueError("未检测到文档输入(file_list 为空)")
f = file_list[0]
file_name = f.get("name", "")
file_url = f.get("url")
if not file_url:
raise ValueError("文档对象缺少 url 字段")
if not file_name.lower().endswith(".pdf"):
raise ValueError(f"当前节点仅支持 PDF,收到:{file_name}")
# -------- 1️⃣ 构造 fake pdf URL(关键)--------
base_url = "http://15.32.142.138:8080/admin"
raw_url = base_url + file_url.lstrip(".")
fake_pdf_url = raw_url + "#.pdf"
# -------- 2️⃣ 调用 Xinference PaddleOCR-VL(URL 推理)--------
xinference_url = "http://15.32.142.191:9997/v1/models/PaddleOCR-VL:predict"
payload = {
"input": fake_pdf_url
}
resp = requests.post(
xinference_url,
json=payload,
timeout=300
)
resp.raise_for_status()
# -------- 3️⃣ 解析返回 --------
result = resp.json()
# 不同版本 PaddleOCR-VL 返回结构略有不同,做兼容
if isinstance(result, dict):
# 常见情况
if "text" in result:
return result["text"]
if "output" in result:
return result["output"]
# 兜底
return str(result)
报错信息:
错误日志
405 Client Error: Method Not Allowed for url: http://15.32.142.191:9997/v1/models/PaddleOCR-VL:predict
Expected behavior / 期待表现
希望能正常识别PDF文档