### 验证安装 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/installation.md 运行 start.py 脚本的 --help 选项以验证安装是否成功。 ```bash python scripts/start.py --help ``` -------------------------------- ### 命令行基本用法 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/index.md 使用 python scripts/start.py 处理单个简历文件,可指定输出目录或批量处理输入目录。 ```bash # 基本用法 python scripts/start.py --file resume.pdf # 指定输出目录 python scripts/start.py --file resume.pdf --output_dir ./results # 批量处理 python scripts/start.py --input_dir ./resumes --output_dir ./results ``` -------------------------------- ### 批量处理优化 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 使用SSD存储、调整并行度和使用GPU加速。 ```bash # 使用SSD存储 python scripts/start.py --input_dir /ssd/resumes --output_dir /ssd/results # 调整并行度 python scripts/start.py --num_workers $(nproc) --batch_size 16 # 使用GPU加速 python scripts/start.py --use_gpu --batch_size 32 ``` -------------------------------- ### 验证 SmartResume 安装 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/index.md 安装完成后验证 SmartResume 是否正常工作。检查版本号并运行 start.py 的 --help 命令进行简单测试。 ```bash # 检查版本 python -c "import smartresume; print(smartresume.__version__)" # 运行简单测试 python scripts/start.py --help ``` -------------------------------- ### ResumeAnalyzer.__init__ Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md Initializes the ResumeAnalyzer with optional OCR and LLM initialization, a config path, and additional keyword arguments. ```APIDOC ## ResumeAnalyzer.__init__ ### Description Initializes the resume analyzer with optional OCR and LLM initialization. ### Method Constructor ### Signature ```python ResumeAnalyzer(init_ocr: bool = True, init_llm: bool = True, config_path: str = None, **kwargs) ``` ### Parameters - **init_ocr** (bool) - Optional - Whether to initialize OCR functionality. - **init_llm** (bool) - Optional - Whether to initialize the LLM model. - **config_path** (str) - Optional - Path to the configuration file. - **kwargs** - Optional - Other configuration parameters. ### Example ```python analyzer = ResumeAnalyzer(init_ocr=True, init_llm=True) ``` ``` -------------------------------- ### 配置环境 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/index.md 复制配置文件模板并编辑 configs/config.yaml 以添加 API 密钥。 ```bash # 复制配置文件模板 cp configs/config.yaml.example configs/config.yaml # 编辑配置文件,添加API密钥 vim configs/config.yaml ``` -------------------------------- ### 批量处理 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 使用 --input_dir 处理整个目录,可指定文件类型和使用多进程加速。 ```bash # 处理整个目录 python scripts/start.py --input_dir ./resumes --output_dir ./results # 指定文件类型 python scripts/start.py --input_dir ./resumes --file_types pdf,jpg,png # 使用多进程加速 python scripts/start.py --input_dir ./resumes --num_workers 4 ``` -------------------------------- ### 检查 CUDA 是否可用 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 Python 检查 torch.cuda.is_available() 以确认 GPU 加速是否可用。 ```bash # 确保 CUDA 可用 python -c "import torch; print(torch.cuda.is_available())" ``` -------------------------------- ### 强制重新下载模型 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --force 参数强制重新下载模型。 ```bash # 强制重新下载 python scripts/download_models.py --force ``` -------------------------------- ### 使用配置文件 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 使用 --config 参数指定配置文件。 ```bash python scripts/start.py --config config.yaml --file resume.pdf ``` -------------------------------- ### 调整批处理大小以提升 GPU 利用率 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --batch_size 8 增加批处理大小,以提高 GPU 利用率。 ```bash python scripts/start.py --batch_size 8 # 增加批处理大小 ``` -------------------------------- ### 下载本地模型 Source: https://github.com/alibaba/smartresume/blob/main/README_CN.md 下载 Qwen-0.6B-resume 模型,用于本地模型部署。 ```bash # 下载 Qwen-0.6B-resume 模型 python scripts/download_models.py ``` -------------------------------- ### 设置环境变量 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/index.md 通过环境变量 SMARTRESUME_CONFIG 指定配置文件路径。 ```bash # 指定配置文件路径 export SMARTRESUME_CONFIG="configs/config.yaml" ``` -------------------------------- ### 下载所有模型 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 运行脚本下载所有模型。 ```bash # 下载所有模型 python scripts/download_models.py ``` -------------------------------- ### 使用环境变量配置 API 密钥 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 通过设置 OPENAI_API_KEY 环境变量来配置 API 密钥。 ```bash export OPENAI_API_KEY="your-api-key-here" ``` -------------------------------- ### 检查 GPU 内存 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 nvidia-smi 检查 GPU 内存使用情况。 ```bash nvidia-smi ``` -------------------------------- ### 运行 Docker 容器 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/docker.md 使用 docker run 命令以守护进程模式运行 smartresume 容器,并将宿主机的 8000 端口映射到容器的 8000 端口。 ```bash docker run -d --name smartresume -p 8000:8000 smartresume:latest ``` -------------------------------- ### ResumeAnalyzer 类定义 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 展示 ResumeAnalyzer 类的 __init__ 和 pipeline 方法的签名及文档字符串,说明参数和返回值。 ```python class ResumeAnalyzer: def __init__( self, init_ocr: bool = True, init_llm: bool = True, config_path: str = None, **kwargs ): """ 初始化简历分析器 Args: init_ocr: 是否初始化OCR功能 init_llm: 是否初始化LLM模型 config_path: 配置文件路径 **kwargs: 其他配置参数 """ pass def pipeline( self, cv_path: str, resume_id: str = None, extract_types: List[str] = None, **kwargs ) -> Dict: """ 执行完整的简历解析流程 Args: cv_path: 简历文件路径 resume_id: 简历ID(可选) extract_types: 要提取的字段类型列表 **kwargs: 其他参数 Returns: 解析结果字典 """ pass ``` -------------------------------- ### 模型预热:调用 warmup_models 提高处理速度 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 创建 ResumeAnalyzer 实例并调用 warmup_models() 进行预热,之后处理简历的速度会更快。 ```python # 预热模型以提高首次处理速度 analyzer = ResumeAnalyzer() analyzer.warmup_models() # 现在处理速度会更快 result = analyzer.pipeline(cv_path="resume.pdf") ``` -------------------------------- ### 配置文件 config.yaml Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 配置文件示例,定义默认提取类型、输出格式和性能参数。 ```yaml # config.yaml processing: default_extract_types: - basic_info - work_experience - education output: format: json save_images: false performance: num_workers: 4 batch_size: 8 ``` -------------------------------- ### 下载默认模型 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 使用仓库脚本下载默认模型,模型会存放在 models/ 目录。确保 GPU 显存足以加载目标模型。 ```bash # 使用仓库脚本下载默认模型 python scripts/download_models.py ``` -------------------------------- ### configs/config.yaml 标准配置示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/configuration.md 展示 SmartResume 当前版本的标准配置文件结构,包含模型、通道、OCR、版面检测等设置。若只使用远程 API,可删除 channels、extract_channels 以及 use_direct_models 等可选段落。 ```yaml model: name: "qwen-turbo" api_url: "https://dashscope.aliyuncs.com/compatible-mode/v1" api_key: "" max_tokens: 4096 temperature: 0 top_p: 1.0 seed: 0 channels: local_qwen: name: "models/Qwen3-0.6B" api_url: "http://localhost:8001/v1" api_key: "local" max_tokens: 4096 temperature: 0.1 top_p: 0.95 seed: 0 extract_channels: basic_info: "local_qwen" work_experience: "local_qwen" education: "local_qwen" processing: use_force_ocr: false use_force_json: false use_pdf_raw_text: false remove_position_and_company_line: false ocr: ocr_provider: "default" use_cuda: true confidence_threshold: 0.5 layout_detection: enabled: true use_direct_models: true direct_model_name: "models/Qwen3-0.6B" model_download: source: "modelscope" models_dir: llm: "models" layout: "models" auto_download: true ``` -------------------------------- ### 验证配置的 Python 示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/configuration.md 使用 Config.from_yaml 加载配置文件并打印成功信息。若需调试,可捕获异常并输出报错信息定位问题。 ```python from smartresume.utils.config import Config Config.from_yaml("configs/config.yaml") print("配置加载成功") ``` -------------------------------- ### 启动独立 vLLM API 服务 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 高级用法,通常不需要。以 API 方式单独启动 vLLM 服务,指定模型路径、端口、主机、张量并行大小和 GPU 内存利用率。 ```bash python -m vllm.entrypoints.openai.api_server \ --model ./models/Qwen3-0.6B \ --port 8001 \ --host 0.0.0.0 \ --tensor-parallel-size 1 \ --gpu-memory-utilization 0.8 ``` -------------------------------- ### 命令行解析单个简历文件 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/index.md 使用命令行界面解析单个简历文件,可指定提取类型。 ```bash # 解析单个简历文件 python scripts/start.py --file resume.pdf # 指定提取类型 python scripts/start.py --file resume.pdf --extract_types basic_info work_experience education ``` -------------------------------- ### 环境变量调试模式 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 设置 SMARTRESUME_DEBUG=1 环境变量启用调试模式。 ```bash # 环境变量调试 export SMARTRESUME_DEBUG=1 python scripts/start.py --file resume.pdf ``` -------------------------------- ### 错误处理:文件格式不支持 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 显示文件格式不支持的错误和解决方案。 ```bash ERROR: Unsupported file format: .pptx SOLUTION: 使用支持的文件格式(PDF、图片、Word、TXT) ``` -------------------------------- ### 检查模型文件 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 列出 models/ 目录下的文件,检查模型文件是否存在。 ```bash ls -la models/ ``` -------------------------------- ### 配置 API 密钥(YAML 配置) Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 在 configs/config.yaml 中配置模型名称、API URL 和 API 密钥。 ```yaml model: name: "qwen-turbo" api_url: "https://dashscope.aliyuncs.com/compatible-mode/v1" api_key: "your-api-key-here" ``` -------------------------------- ### 快速配置 Source: https://github.com/alibaba/smartresume/blob/main/README_CN.md 复制配置模板并根据需要编辑。 ```bash cp configs/config.yaml.example configs/config.yaml ``` -------------------------------- ### 重新安装对应版本的 PyTorch Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/requirements.md 故障排除中针对 CUDA 版本不匹配的解决方案,使用 pip 从指定 index-url 安装 torch 和 torchvision。 ```bash # 重新安装对应版本的 PyTorch pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118 ``` -------------------------------- ### 直接加载离线模型配置 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 在 configs/config.yaml 中设置 use_direct_models 和 direct_model_name,以直接加载 transformers 模型。保存后再次运行解析命令。 ```yaml use_direct_models: true direct_model_name: "models/Qwen3-0.6B" ``` -------------------------------- ### 内存优化环境变量设置 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/requirements.md 在性能优化建议的内存优化部分,通过设置 OMP_NUM_THREADS 和 MKL_NUM_THREADS 环境变量来限制线程数,以减少内存使用。 ```bash # 设置环境变量限制内存使用 export OMP_NUM_THREADS=4 export MKL_NUM_THREADS=4 ``` -------------------------------- ### 启动演示服务:Gradio 和 Streamlit 命令 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/demo/index.md 提供两种启动演示界面的命令:使用 Gradio Web 界面(python -m smartresume.cli.gradio_app)或 Streamlit 界面(streamlit run demo/streamlit_app.py)。选择其一即可启动本地演示服务。 ```bash # 启动 Gradio Web 界面 python -m smartresume.cli.gradio_app # 或启动 Streamlit 界面 streamlit run demo/streamlit_app.py ``` -------------------------------- ### 配置 SmartResume 通道 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 在 configs/config.yaml 中新增或修改通道信息,并将提取任务映射到该通道。保存配置后,普通命令即可启用本地服务。 ```yaml channels: local_qwen: name: "models/Qwen3-0.6B" api_url: "http://localhost:8001/v1" api_key: "local" max_tokens: 4096 temperature: 0.1 top_p: 0.95 extract_channels: basic_info: "local_qwen" work_experience: "local_qwen" education: "local_qwen" ``` -------------------------------- ### 克隆项目仓库 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/index.md 使用 git clone 克隆 SmartResume 项目并进入项目目录。 ```bash git clone https://github.com/your-username/SmartResume.git cd SmartResume ``` -------------------------------- ### 检查 CUDA 版本并安装对应 PyTorch Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 nvidia-smi 检查 CUDA 版本,然后安装对应版本的 PyTorch。 ```bash # 检查 CUDA 版本 nvidia-smi # 安装对应版本的 PyTorch pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118 ``` -------------------------------- ### 错误处理:API密钥错误 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 显示API密钥错误的错误和解决方案。 ```bash ERROR: Invalid API key SOLUTION: 检查配置文件中的API密钥 ``` -------------------------------- ### 拉取 Docker 镜像 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/docker.md 使用 docker pull 命令从镜像仓库拉取 smartresume:latest 镜像。 ```bash docker pull smartresume:latest ``` -------------------------------- ### 异步处理 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 使用 AsyncResumeAnalyzer 和 asyncio.gather 并发处理多个简历文件。 ```python import asyncio from smartresume import AsyncResumeAnalyzer async def process_resumes_async(file_paths): analyzer = AsyncResumeAnalyzer() tasks = [] for file_path in file_paths: task = analyzer.pipeline( cv_path=file_path, extract_types=["basic_info", "work_experience"] ) tasks.append(task) results = await asyncio.gather(*tasks) return results # 使用异步处理 file_paths = ["resume1.pdf", "resume2.pdf", "resume3.pdf"] results = asyncio.run(process_resumes_async(file_paths)) ``` -------------------------------- ### GPU 优化环境变量设置 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/requirements.md 在性能优化建议的 GPU 优化部分,设置 CUDA_VISIBLE_DEVICES 选择 GPU 设备,并启用 TORCH_CUDNN_V8_API_ENABLED 以启用混合精度训练。 ```bash # 设置 CUDA 设备 export CUDA_VISIBLE_DEVICES=0 # 启用混合精度训练 export TORCH_CUDNN_V8_API_ENABLED=1 ``` -------------------------------- ### 使用 Python API 解析简历 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/index.md 初始化 ResumeAnalyzer 并调用 pipeline 方法解析简历,返回结构化结果。 ```python from smartresume import ResumeAnalyzer # 初始化分析器 analyzer = ResumeAnalyzer(init_ocr=True, init_llm=True) # 解析简历 result = analyzer.pipeline( cv_path="resume.pdf", resume_id="resume_001", extract_types=["basic_info", "work_experience", "education"] ) print(result) ``` -------------------------------- ### 内存优化 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 限制内存使用和流式处理大文件。 ```bash # 限制内存使用 python scripts/start.py --max_memory 4GB --batch_size 1 # 流式处理大文件 python scripts/start.py --stream_processing --chunk_size 1024 ``` -------------------------------- ### 批量处理:遍历目录并保存结果 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 遍历指定目录下的所有 PDF 文件,调用 pipeline 解析并保存结果到输出目录,处理异常。 ```python import os from pathlib import Path # 处理目录中的所有文件 input_dir = Path("./resumes") output_dir = Path("./results") for file_path in input_dir.glob("*.pdf"): try: result = analyzer.pipeline( cv_path=str(file_path), resume_id=file_path.stem, extract_types=["basic_info", "work_experience", "education"] ) # 保存结果 output_file = output_dir / f"{file_path.stem}.json" with open(output_file, 'w', encoding='utf-8') as f: json.dump(result, f, ensure_ascii=False, indent=2) except Exception as e: print(f"处理文件 {file_path} 时出错: {e}") ``` -------------------------------- ### 批量处理优化命令 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/index.md 使用多进程和批处理大小参数优化批量处理性能。 ```bash # 使用多进程处理 python scripts/start.py --input_dir ./resumes --num_workers 4 # 设置批处理大小 python scripts/start.py --batch_size 8 ``` -------------------------------- ### 命令行调试模式 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --debug 参数启用调试模式,输出详细错误信息。 ```bash # 命令行调试 python scripts/start.py --file resume.pdf --debug ``` -------------------------------- ### 启动 Web 服务 Source: https://github.com/alibaba/smartresume/blob/main/README_CN.md 启动 Web 服务,在浏览器中访问 http://localhost:4999 上传简历。 ```bash python demo/web_app.py # 在浏览器中访问 http://localhost:4999 上传简历 ``` -------------------------------- ### 下载特定模型 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --model layout 参数下载特定模型。 ```bash # 下载特定模型 python scripts/download_models.py --model layout ``` -------------------------------- ### 创建 conda 环境 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/installation.md 使用 conda 创建名为 smartresume 的 Python 3.9 环境并激活它。 ```bash conda create -n smartresume python=3.9 conda activate smartresume ``` -------------------------------- ### 错误处理:内存不足 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 显示内存不足的错误和解决方案。 ```bash ERROR: Out of memory SOLUTION: 减少 --batch_size 或 --num_workers ``` -------------------------------- ### 减少批处理大小以解决内存不足 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/requirements.md 故障排除中针对内存不足的解决方案,通过 --batch_size 参数减少批处理大小。 ```bash # 减少批处理大小 python scripts/start.py --batch_size 1 ``` -------------------------------- ### 创建 conda 环境 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/index.md 创建并激活名为 resume_parsing 的 conda 环境,指定 Python 3.9 版本。 ```bash conda create -n resume_parsing python=3.9 conda activate resume_parsing ``` -------------------------------- ### 强制重新安装和 conda 安装主要依赖 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 当依赖冲突时,使用 pip 强制重新安装或使用 conda 安装 PyTorch 相关依赖。 ```bash # 强制重新安装 pip install --force-reinstall -e . # 或使用 conda 安装主要依赖 conda install pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia ``` -------------------------------- ### 安装依赖 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/installation.md 使用 pip 以可编辑模式安装项目及其依赖。 ```bash pip install -e . ``` -------------------------------- ### 设置代理以解决网络连接问题 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/requirements.md 故障排除中针对网络连接问题的解决方案,通过设置 http_proxy 和 https_proxy 环境变量使用代理。 ```bash # 使用代理 export http_proxy=http://proxy:port export https_proxy=http://proxy:port ``` -------------------------------- ### 检查 CUDA 设置 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 打印 CUDA 可用性、设备数量和当前设备信息,用于诊断 GPU 利用率问题。 ```python import torch print(f"CUDA available: {torch.cuda.is_available()}") print(f"CUDA devices: {torch.cuda.device_count()}") print(f"Current device: {torch.cuda.current_device()}") ``` -------------------------------- ### 示例1:处理PDF简历 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 处理单个PDF简历,指定输出目录、提取类型和输出格式。 ```bash python scripts/start.py \ --file resume.pdf \ --output_dir ./output \ --extract_types basic_info work_experience education \ --output_format json ``` -------------------------------- ### 设置 CUDA 设备 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 通过 CUDA_VISIBLE_DEVICES 环境变量指定使用的 GPU 设备。 ```bash export CUDA_VISIBLE_DEVICES=0 ``` -------------------------------- ### 检查 CUDA 和 cuDNN 版本 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/requirements.md 在 CUDA 环境(可选)部分,用于检查 GPU 驱动和 cuDNN 是否安装正确。nvidia-smi 显示 GPU 驱动信息,python 命令打印 cuDNN 版本。 ```bash # 检查 CUDA 版本 nvidia-smi # 检查 cuDNN python -c "import torch; print(torch.backends.cudnn.version())" ``` -------------------------------- ### 启动 Web 界面 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/index.md 启动 Gradio 或 Streamlit 界面,访问 http://localhost:7860。 ```bash # 启动 Gradio 界面 python -m smartresume.cli.gradio_app # 或使用 Streamlit streamlit run demo/streamlit_app.py ``` -------------------------------- ### 使用 OCR 模式处理 PDF Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --use_ocr 参数启用 OCR 模式,解决 PDF 乱码问题。 ```bash python scripts/start.py --file resume.pdf --use_ocr ``` -------------------------------- ### 使用 Docker Compose 配置 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/docker.md 提供 docker-compose.yml 配置示例,定义 smartresume 服务,使用 smartresume:latest 镜像并映射端口 8000。 ```yaml version: '3.8' services: smartresume: image: smartresume:latest ports: - "8000:8000" ``` -------------------------------- ### 检查输出配置文件 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 在 YAML 配置中设置输出格式、是否包含图片和是否保存中间结果。 ```yaml processing: output: format: "json" include_images: false save_intermediate: true ``` -------------------------------- ### 批量处理简历 Source: https://github.com/alibaba/smartresume/blob/main/README_CN.md 使用 Python API 批量处理多个 PDF 文件,只加载一次模型。 ```python from smartresume import ResumeAnalyzer import glob, json analyzer = ResumeAnalyzer(init_ocr=True, init_llm=True) # 只加载一次 for f in glob.glob("/path/to/resumes/*.pdf"): result = analyzer.pipeline(cv_path=f, resume_id=f.split("/")[-1]) print(json.dumps(result, ensure_ascii=False, indent=2)) ``` -------------------------------- ### 检查独立 API 服务 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 若使用独立 API 方式(高级用法),可通过 curl 命令检查服务是否可用。 ```bash curl http://localhost:8001/v1/models ``` -------------------------------- ### 使用更强的模型 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 在 YAML 配置中设置 llm 的 model_name 为 gpt-4 以提升解析准确性。 ```yaml model: llm: model_name: "gpt-4" # 使用 GPT-4 ``` -------------------------------- ### 源码安装 SmartResume Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/index.md 从源码安装 SmartResume 的方式。克隆 GitHub 仓库,进入目录后以可编辑模式安装依赖。 ```bash # 克隆仓库 git clone https://github.com/your-username/SmartResume.git cd SmartResume # 安装依赖 pip install -e . ``` -------------------------------- ### 查看程序错误日志 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 运行程序并捕获错误输出,查看最后 20 行日志。 ```bash # 检查程序输出的错误信息 python scripts/start.py --file resume.pdf 2>&1 | tail -20 ``` -------------------------------- ### 使用流式处理释放内存 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 逐个处理文件并立即保存结果,以释放内存。 ```python # 逐个处理文件 for file in files: result = analyzer.pipeline(cv_path=file) # 立即保存结果,释放内存 ``` -------------------------------- ### 重试机制:使用装饰器 retry_on_failure Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 定义 retry_on_failure 装饰器,在函数调用失败时自动重试,默认最多重试 3 次,每次间隔 1 秒。示例中将其应用于 robust_pipeline 函数,设置 max_retries=3, delay=2。 ```python import time from functools import wraps def retry_on_failure(max_retries=3, delay=1): def decorator(func): @wraps(func) def wrapper(*args, **kwargs): for attempt in range(max_retries): try: return func(*args, **kwargs) except Exception as e: if attempt == max_retries - 1: raise e print(f"尝试 {attempt + 1} 失败,{delay}秒后重试...") time.sleep(delay) return None return wrapper return decorator @retry_on_failure(max_retries=3, delay=2) def robust_pipeline(analyzer, cv_path): return analyzer.pipeline(cv_path=cv_path) ``` -------------------------------- ### 创建虚拟环境并安装 SmartResume Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 conda 创建 Python 3.9 虚拟环境并安装 SmartResume,用于隔离依赖,避免冲突。 ```bash # 创建新的虚拟环境 conda create -n smartresume python=3.9 conda activate smartresume # 重新安装 pip install -e . ``` -------------------------------- ### 并行处理文件 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --num_workers 4 参数启用并行处理,提高处理速度。 ```bash python scripts/start.py --input_dir ./resumes --num_workers 4 ``` -------------------------------- ### 使用 Python API 自定义输出格式 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 ResumeAnalyzer 类自定义提取类型和输出格式。 ```python from smartresume import ResumeAnalyzer analyzer = ResumeAnalyzer() # 自定义提取类型 custom_types = ["basic_info", "work_experience", "education"] result = analyzer.pipeline( cv_path="resume.pdf", extract_types=custom_types, ) # 自定义输出格式 output = { "candidate_name": result.get("basicInfo", {}).get("name", ""), "experience": result.get("workExperience", []), "education": result.get("education", []) } ``` -------------------------------- ### 调整置信度阈值 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 在 YAML 配置中提高 layout 的 confidence_threshold 以优化解析结果。 ```yaml model: layout: confidence_threshold: 0.7 # 提高阈值 ``` -------------------------------- ### ResumeAnalyzer.pipeline Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md Executes the complete resume parsing pipeline, extracting specified fields from a resume file. ```APIDOC ## ResumeAnalyzer.pipeline ### Description Executes the full resume parsing pipeline, extracting specified fields from a resume file. ### Method Method ### Signature ```python pipeline(cv_path: str, resume_id: str = None, extract_types: List[str] = None, **kwargs) -> Dict ``` ### Parameters - **cv_path** (str) - Required - Path to the resume file. - **resume_id** (str) - Optional - Resume ID. - **extract_types** (List[str]) - Optional - List of field types to extract. - **kwargs** - Optional - Other parameters. ### Returns - **Dict** - Parsing result dictionary. ### Example ```python result = analyzer.pipeline(cv_path="resume.pdf", resume_id="resume_001", extract_types=["basic_info", "work_experience", "education"]) ``` ``` -------------------------------- ### 运行解析命令(方案一) Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 保存配置后,运行解析命令以启用本地服务。此命令也用于验证进程内模式。 ```bash python scripts/start.py --file resume.pdf ``` -------------------------------- ### Flask Web 应用集成示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 使用 Flask 创建 /parse 端点,接收文件上传和 extract_types 参数,调用 ResumeAnalyzer 的 pipeline 方法解析简历,并返回 JSON 结果。需要安装 Flask 和 smartresume。 ```python from flask import Flask, request, jsonify from smartresume import ResumeAnalyzer app = Flask(__name__) analyzer = ResumeAnalyzer() @app.route('/parse', methods=['POST']) def parse_resume(): if 'file' not in request.files: return jsonify({'error': 'No file provided'}), 400 file = request.files['file'] extract_types = request.form.getlist('extract_types') or ['basic_info'] try: result = analyzer.pipeline( cv_path=file.filename, extract_types=extract_types ) return jsonify(result) except Exception as e: return jsonify({'error': str(e)}), 500 if __name__ == '__main__': app.run(debug=True) ``` -------------------------------- ### Python API 使用示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/index.md 使用 ResumeAnalyzer 初始化分析器并解析单个简历,支持指定提取字段类型。 ```python from smartresume import ResumeAnalyzer # 初始化分析器 analyzer = ResumeAnalyzer( init_ocr=True, init_llm=True, ) # 解析单个简历 result = analyzer.pipeline( cv_path="resume.pdf", resume_id="resume_001", extract_types=["basic_info", "work_experience", "education"] ) print(f"解析结果: {result}") ``` -------------------------------- ### 示例3:自定义配置 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 使用自定义配置文件,指定输出格式、保存图片和详细输出。 ```bash python scripts/start.py \ --input_dir ./resumes \ --config configs/custom_config.yaml \ --output_format xml \ --save_images \ --verbose ``` -------------------------------- ### 指定语言处理 PDF Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --language zh 参数指定语言,解决 PDF 乱码问题。 ```bash python scripts/start.py --file resume.pdf --language zh ``` -------------------------------- ### pip 安装 SmartResume Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/quick_start/index.md 使用 pip 安装 SmartResume 的推荐方式。首先创建并激活名为 smartresume 的 Conda 虚拟环境(Python 3.9),然后通过 pip 安装 smartresume 包。 ```bash # 创建虚拟环境 conda create -n smartresume python=3.9 conda activate smartresume # 安装 SmartResume pip install smartresume ``` -------------------------------- ### Python API 示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 使用 ResumeAnalyzer 类进行简历解析。API 会读取配置文件并自动选择合适的推理模式,无需额外设置本地 URL。 ```python from smartresume import ResumeAnalyzer analyzer = ResumeAnalyzer( init_ocr=True, init_llm=True, ) result = analyzer.pipeline( cv_path="resume.pdf", resume_id="resume_001", extract_types=["basic_info", "work_experience", "education"] ) ``` -------------------------------- ### 引用 SmartResume 论文 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/index.md BibTeX 格式的引用条目,用于学术引用。 ```bibtex @article{Zhu2026SmartResume, title={Layout-Aware Parsing Meets Efficient LLMs: A Unified, Scalable Framework for Resume Information Extraction and Evaluation}, author={Fanwei Zhu and Jinke Yu and Zulong Chen and Ying Zhou and Junhao Ji and Zhibo Yang and Yuxue Zhang and HaoYuan Hu and Zhenghao Liu}, journal={KDD2026}, year={2026} } ``` -------------------------------- ### 安装 vLLM Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/local_models.md 使用 pip 安装 vLLM,或安装最新源码版本。 ```bash pip install vllm # 或者安装最新源码版本 pip install git+https://github.com/vllm-project/vllm.git ``` -------------------------------- ### 检查端口占用 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 netstat 检查 8000 端口是否被占用。 ```bash netstat -tlnp | grep 8000 ``` -------------------------------- ### 内存优化配置 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/index.md 通过 max_memory_usage 参数限制内存使用。 ```python # 配置内存使用 analyzer = ResumeAnalyzer( init_ocr=True, init_llm=True, max_memory_usage="8GB" # 限制内存使用 ) ``` -------------------------------- ### 异常处理:捕获 smartresume 特定异常 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 导入 smartresume 的异常类,并在调用 analyzer.pipeline 时捕获 FileFormatError、ModelLoadError、APIError、ProcessingError 等特定异常,最后捕获通用异常。 ```python from smartresume.exceptions import ( FileFormatError, ModelLoadError, APIError, ProcessingError ) try: result = analyzer.pipeline(cv_path="resume.pdf") except FileFormatError as e: print(f"文件格式错误: {e}") except ModelLoadError as e: print(f"模型加载失败: {e}") except APIError as e: print(f"API调用失败: {e}") except ProcessingError as e: print(f"处理过程出错: {e}") except Exception as e: print(f"未知错误: {e}") ``` -------------------------------- ### 示例2:批量处理图片简历 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/cli.md 批量处理图片简历,使用OCR、指定语言和多进程。 ```bash python scripts/start.py \ --input_dir ./image_resumes \ --output_dir ./results \ --file_types jpg,png \ --use_ocr \ --language zh \ --num_workers 4 ``` -------------------------------- ### 流式处理 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 分批处理大量文件,捕获异常并清理内存。 ```python def stream_process_large_directory(input_dir, batch_size=10): """流式处理大量文件""" analyzer = ResumeAnalyzer() for batch in get_file_batches(input_dir, batch_size): results = [] for file_path in batch: try: result = analyzer.pipeline(cv_path=file_path) results.append(result) except Exception as e: print(f"处理失败: {file_path}, 错误: {e}") # 批量保存结果 save_batch_results(results, batch) # 清理内存 del results gc.collect() ``` -------------------------------- ### 指定输出格式为 JSON Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --output_format json 参数指定输出格式。 ```bash python scripts/start.py --file resume.pdf --output_format json ``` -------------------------------- ### 使用 PDFplumber 预处理 PDF Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 PDFplumber 提取 PDF 文本,作为预处理步骤。 ```python # 使用 PDFplumber 预处理 import pdfplumber with pdfplumber.open("resume.pdf") as pdf: page = pdf.pages[0] text = page.extract_text() ``` -------------------------------- ### XML 格式示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/output_format.md 展示 SmartResume 输出的 XML 格式简历数据,包含基本信息和联系方式。 ```xml 张三 13800138000 zhangsan@example.com ``` -------------------------------- ### 内存管理:使用 gc.collect() 清理中间结果 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 定义 MemoryEfficientAnalyzer 类,在 process_with_cleanup 方法中通过 finally 块调用 gc.collect() 清理中间结果,确保内存释放。 ```python import gc class MemoryEfficientAnalyzer: def __init__(self): self.analyzer = ResumeAnalyzer() def process_with_cleanup(self, cv_path): try: result = self.analyzer.pipeline(cv_path=cv_path) return result finally: # 清理中间结果 gc.collect() ``` -------------------------------- ### 自定义输出字段 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/faq.md 使用 --extract_types 参数指定要提取的字段类型。 ```bash python scripts/start.py --file resume.pdf --extract_types basic_info work_experience ``` -------------------------------- ### 自定义提取器 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/api.md 继承 BaseExtractor 并实现 extract 方法,然后注册到 analyzer 并使用。 ```python from smartresume.extractors import BaseExtractor class CustomExtractor(BaseExtractor): def extract(self, text: str, layout_info: dict) -> dict: """自定义提取逻辑""" # 实现您的提取逻辑 return { "custom_field": "extracted_value" } # 注册自定义提取器 analyzer.register_extractor("custom_field", CustomExtractor()) # 使用自定义提取器 result = analyzer.pipeline( cv_path="resume.pdf", extract_types=["basic_info", "custom_field"] ) ``` -------------------------------- ### CSV 格式示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/output_format.md 展示 SmartResume 输出的 CSV 格式简历数据,包含表头和一行数据。 ```csv resume_id,name,phone,email,company,position resume_001,张三,13800138000,zhangsan@example.com,ABC公司,软件工程师 ``` -------------------------------- ### 基本信息提取 JSON 示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/demo/index.md 展示解析简历后提取的基本信息 JSON 结构,包含姓名、性别、年龄、电话、邮箱和地址。用于演示结构化输出格式。 ```json { "basic_info": { "name": "张三", "gender": "男", "age": 28, "phone": "13800138000", "email": "zhangsan@example.com", "address": "北京市朝阳区" } } ``` -------------------------------- ### 处理流程 Mermaid 图 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/demo/index.md 展示 SmartResume 的处理流程:上传文档、格式检测、版面分析、OCR识别、文本提取、结构化解析、结果输出。 ```mermaid graph TD A[上传文档] --> B[格式检测] B --> C[版面分析] C --> D[OCR识别] D --> E[文本提取] E --> F[结构化解析] F --> G[结果输出] ``` -------------------------------- ### JSON 输出格式示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/usage/index.md 展示 SmartResume 解析结果的 JSON 结构,包含基本信息、工作经历和教育经历。 ```json { "resume_id": "resume_001", "basic_info": { "name": "张三", "phone": "13800138000", "email": "zhangsan@example.com" }, "work_experience": [ { "company": "ABC公司", "position": "软件工程师", "duration": "2020-2023" } ], "education": [ { "school": "某某大学", "major": "计算机科学", "degree": "本科" } ] } ``` -------------------------------- ### JSON 格式示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/reference/output_format.md 展示 SmartResume 输出的 JSON 格式简历数据,包含基本信息和工作经历。 ```json { "resume_id": "resume_001", "basic_info": { "name": "张三", "phone": "13800138000", "email": "zhangsan@example.com" }, "work_experience": [ { "company": "ABC公司", "position": "软件工程师", "duration": "2020-2023" } ] } ``` -------------------------------- ### 教育背景提取 JSON 示例 Source: https://github.com/alibaba/smartresume/blob/main/docs/zh/demo/index.md 展示解析简历后提取的教育背景 JSON 结构,包含学校、专业、学位、毕业年份和 GPA。用于演示结构化输出格式。 ```json { "education": [ { "school": "清华大学", "major": "计算机科学与技术", "degree": "本科", "graduation_year": "2020", "gpa": "3.8/4.0" } ] } ```