File size: 2,953 Bytes
8735397
9411e01
8735397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# app.py

from transformers import (
    AutoModelForSequenceClassification,
    AutoTokenizer,
    AutoModelForTokenClassification,
    pipeline
)
import gradio as gr
import torch


# Use a pipeline as a high-level helper
from transformers import pipeline


CLASS_MODEL_NAME = "AmandaCAI/resume-classifier"  
NER_MODEL_NAME = "AmandaCAI/ner-keywords-extract"     

# 初始化分类模型
class_tokenizer = AutoTokenizer.from_pretrained(CLASS_MODEL_NAME)
class_model = AutoModelForSequenceClassification.from_pretrained(CLASS_MODEL_NAME)

# 初始化NER模型
ner_tokenizer = AutoTokenizer.from_pretrained(NER_MODEL_NAME)
ner_model = AutoModelForTokenClassification.from_pretrained(NER_MODEL_NAME)
ner_pipeline = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer, aggregation_strategy="simple")

# 岗位分类标签(根据你的训练数据调整)
job_categories = [
    "Data Science", "Java Developer", "HR", 
    "Python Developer", "Web Designing", "Testing"
]

def analyze_resume(text):
    """处理简历分析的主函数"""
    # 岗位分类
    class_inputs = class_tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
    with torch.no_grad():
        class_logits = class_model(**class_inputs).logits
    predicted_class = torch.argmax(class_logits).item()
    class_label = job_categories[predicted_class]
    
    # 技能提取
    ner_results = ner_pipeline(text)
    skills = [entity["word"] for entity in ner_results if entity["entity_group"] == "SKILL"]
    
    # 工作经验提取(示例)
    experience = [entity["word"] for entity in ner_results if entity["entity_group"] == "EXPERIENCE"]
    
    return {
        "岗位类别": class_label,
        "匹配度": f"{torch.softmax(class_logits, dim=1)[0][predicted_class].item()*100:.1f}%",
        "核心技能": list(set(skills))[:5],  # 取前5个不重复技能
        "工作经验": list(set(experience))[:3]
    }

# Gradio界面设计
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# 🧠 AI Resume Analyzer")
    
    with gr.Row():
        with gr.Column():
            input_text = gr.Textbox(label="📝 Paste Resume Text Here", lines=10, 
                                  placeholder="Enter your resume text here...")
            submit_btn = gr.Button("Start the analysis", variant="primary")
            
        with gr.Column():
            output_json = gr.JSON(label="Analysis result")
            
    # 示例数据
    gr.Examples(
        examples=[[
            """John Smith
            Senior Python Developer
            Skills: Python, Django, AWS, Machine Learning
            Experience: 5+ years at Google, 3 years at Amazon
            Education: MIT Computer Science"""
        ]],
        inputs=[input_text]
    )

    submit_btn.click(
        fn=analyze_resume,
        inputs=[input_text],
        outputs=output_json
    )

# 启动应用
if __name__ == "__main__":
    demo.launch()