kylezhao101 commited on
Commit
09b06d4
·
1 Parent(s): 0f51a7f

update app.py

Browse files
Files changed (2) hide show
  1. .gitignore +2 -0
  2. app.py +70 -11
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ hf-env
2
+ .gradio
app.py CHANGED
@@ -1,19 +1,78 @@
1
- import streamlit as st
2
  from transformers import pipeline
 
3
 
4
  # Load the token classification pipeline
5
  model_name = "jjzha/jobbert_knowledge_extraction"
6
  pipe = pipeline("token-classification", model=model_name)
7
 
8
- # Streamlit UI
9
- st.title("Token Classification with Hugging Face")
10
- text_input = st.text_area("Enter text for token classification:")
11
 
12
- if text_input:
13
- # Perform token classification
14
- results = pipe(text_input)
15
-
16
- # Display the results
17
- st.write("Token Classification Results:")
18
  for result in results:
19
- st.write(f"Entity: {result['entity']}, Word: {result['word']}, Score: {result['score']:.2f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  from transformers import pipeline
3
+ import PyPDF2
4
 
5
  # Load the token classification pipeline
6
  model_name = "jjzha/jobbert_knowledge_extraction"
7
  pipe = pipeline("token-classification", model=model_name)
8
 
9
+ # Function to extract and highlight key skills/words from the job posting
10
+ def extract_keywords_with_highlights(job_posting_text):
11
+ results = pipe(job_posting_text)
12
 
13
+ # Fix the `##` issue by reconstructing full words
14
+ reconstructed_text = ""
15
+ highlighted_words = set()
16
+ previous_end = 0
 
 
17
  for result in results:
18
+ start, end, word = result['start'], result['end'], result['word']
19
+ # Remove `##` for subwords
20
+ clean_word = word.replace("##", "")
21
+ highlighted_words.add(clean_word.lower())
22
+ # Add text before the current word
23
+ reconstructed_text += job_posting_text[previous_end:start]
24
+ # Highlight the cleaned word
25
+ reconstructed_text += (
26
+ f'<span style="background-color:yellow; font-weight:bold;" '
27
+ f'title="Entity: {result["entity"]} (Score: {result["score"]:.2f})">'
28
+ f"{clean_word}</span>"
29
+ )
30
+ previous_end = end
31
+ # Add the remaining text
32
+ reconstructed_text += job_posting_text[previous_end:]
33
+ # Replace newline characters with <br> to preserve line breaks
34
+ reconstructed_text = reconstructed_text.replace("\n", "<br>")
35
+
36
+ return (
37
+ f'<div style="font-family:Arial, sans-serif; line-height:1.5;">{reconstructed_text}</div>',
38
+ highlighted_words,
39
+ )
40
+
41
+ # Function to check if highlighted words are in the resume
42
+ def check_keywords_in_resume(resume_file_path, job_posting_text):
43
+ # Extract text from the uploaded PDF resume
44
+ with open(resume_file_path, "rb") as file:
45
+ pdf_reader = PyPDF2.PdfReader(file)
46
+ resume_text = " ".join(page.extract_text() for page in pdf_reader.pages)
47
+
48
+ # Extract highlighted keywords from the job posting
49
+ highlighted_html, highlighted_words = extract_keywords_with_highlights(job_posting_text)
50
+
51
+ # Check if each highlighted word is in the resume
52
+ resume_words = set(resume_text.lower().split())
53
+ matched_words = highlighted_words.intersection(resume_words)
54
+ missing_words = highlighted_words - matched_words
55
+
56
+ # Prepare a summary
57
+ matched_summary = f"Matched Keywords: {', '.join(matched_words)}"
58
+ missing_summary = f"Missing Keywords: {', '.join(missing_words)}"
59
+ return highlighted_html, matched_summary, missing_summary
60
+
61
+ # Set up Gradio interface
62
+ interface = gr.Interface(
63
+ fn=check_keywords_in_resume,
64
+ inputs=[
65
+ gr.File(label="Upload Resume PDF", type="filepath"),
66
+ gr.Textbox(label="Enter Job Posting Text", lines=30, placeholder="Paste job posting text here..."),
67
+ ],
68
+ outputs=[
69
+ gr.HTML(label="Highlighted Key Skills/Words in Job Posting"),
70
+ gr.Textbox(label="Matched Keywords"),
71
+ gr.Textbox(label="Missing Keywords"),
72
+ ],
73
+ title="Resume vs Job Posting Skill Match with Highlights",
74
+ description="Upload your resume and enter a job posting. The app will highlight key skills from the job posting and check if they are present in your resume.",
75
+ )
76
+
77
+ # Launch the Gradio app
78
+ interface.launch()