DataGridView复制到Excel:剪贴板格式与样式保留完整指南
2026/10/8 10:45:42
LightOnOCR-2-1B是一个轻量级但功能强大的多语言OCR模型,仅1B参数就能实现11种语言的文字识别(中文、英文、日语、法语、德语、西班牙语、意大利语、荷兰语、葡萄牙语、瑞典语、丹麦语)。这个教程将带你快速完成从部署到使用的全流程。
确保系统已安装:
# 创建模型目录 mkdir -p /root/ai-models/lightonai/LightOnOCR-2-1B # 下载模型文件(假设已获取下载权限) wget -P /root/ai-models/lightonai/LightOnOCR-2-1B https://example.com/LightOnOCR-2-1B/model.safetensors wget -P /root/ai-models/lightonai/LightOnOCR-2-1B https://example.com/LightOnOCR-2-1B/config.json# 使用vLLM启动API服务 python -m vllm.entrypoints.api_server \ --model /root/ai-models/lightonai/LightOnOCR-2-1B \ --tensor-parallel-size 1 \ --port 8000创建app.py文件:
import gradio as gr import requests def ocr_inference(image): # 将图片转换为base64 import base64 buffered = io.BytesIO() image.save(buffered, format="PNG") img_str = base64.b64encode(buffered.getvalue()).decode() # 调用API response = requests.post( "http://localhost:8000/v1/chat/completions", json={ "model": "/root/ai-models/lightonai/LightOnOCR-2-1B", "messages": [{ "role": "user", "content": [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{img_str}"}}] }], "max_tokens": 4096 } ) return response.json()["choices"][0]["message"]["content"] # 创建界面 iface = gr.Interface( fn=ocr_inference, inputs=gr.Image(type="pil"), outputs="text", title="LightOnOCR-2-1B 文字识别" ) iface.launch(server_port=7860)启动前端:
python app.py# 检查端口监听情况 ss -tlnp | grep -E "7860|8000"浏览器打开:http://<你的服务器IP>:7860
curl -X POST http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "/root/ai-models/lightonai/LightOnOCR-2-1B", "messages": [{ "role": "user", "content": [{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64_IMAGE>"}}] }], "max_tokens": 4096 }'max_tokens参数通过本教程,你已经完成了:
这个解决方案特别适合需要多语言OCR能力的应用场景,如国际文档处理、多语言票据识别等。vLLM的加速使得1B参数的模型也能实现高效的推理速度。
获取更多AI镜像
想探索更多AI镜像和应用场景?访问 CSDN星图镜像广场,提供丰富的预置镜像,覆盖大模型推理、图像生成、视频生成、模型微调等多个领域,支持一键部署。