CR7CAD commited on
Commit
50528fd
·
verified ·
1 Parent(s): d836318

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -37
app.py CHANGED
@@ -25,7 +25,7 @@ def extract_text_from_file(file_obj):
25
  text = f"Error processing DOCX file: {e}"
26
  elif ext == ".doc":
27
  try:
28
- # textract requires a filename, so create a temporary file.
29
  with tempfile.NamedTemporaryFile(delete=False, suffix=".doc") as tmp:
30
  tmp.write(file_obj.read())
31
  tmp.flush()
@@ -51,15 +51,18 @@ def extract_basic_resume_info(text):
51
  Parse the extracted text to summarize basic info:
52
  - Name
53
  - Age
54
- - Work Experience
55
- - Expected Industry/Direction
56
- Returns a dictionary of extracted data.
 
 
57
  """
58
  info = {
59
  "Name": None,
60
  "Age": None,
61
- "Work Experience": None,
62
- "Expected Industry/Direction": None,
 
63
  }
64
 
65
  # Extract Name (e.g., "Name: John Doe")
@@ -67,7 +70,7 @@ def extract_basic_resume_info(text):
67
  if name_match:
68
  info["Name"] = name_match.group(1).strip()
69
  else:
70
- # Heuristic: search for a line with two or three capitalized words.
71
  potential_names = re.findall(r"\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){1,2}\b", text)
72
  if potential_names:
73
  info["Name"] = potential_names[0]
@@ -76,21 +79,30 @@ def extract_basic_resume_info(text):
76
  age_match = re.search(r"[Aa]ge[:\-]\s*(\d{1,2})", text)
77
  if age_match:
78
  info["Age"] = age_match.group(1)
79
-
80
- # Extract Work Experience (e.g., "5 years of experience")
81
  exp_match = re.search(r"(\d+)\s+(years|yrs)\s+(?:of\s+)?experience", text, re.IGNORECASE)
82
  if exp_match:
83
- info["Work Experience"] = f"{exp_match.group(1)} {exp_match.group(2)}"
84
  else:
85
- # Fallback: look for overall experience information.
86
- exp_line = re.search(r"(Experience|Background)[:\-]\s*(.*)", text, re.IGNORECASE)
87
  if exp_line:
88
- info["Work Experience"] = exp_line.group(2).strip()
89
-
90
- # Extract Expected Industry/Direction
91
- industry_match = re.search(r"(Industry|Interest|Direction)[:\-]\s*(.+)", text, re.IGNORECASE)
92
- if industry_match:
93
- info["Expected Industry/Direction"] = industry_match.group(2).strip()
 
 
 
 
 
 
 
 
 
94
 
95
  return info
96
 
@@ -99,22 +111,28 @@ def extract_basic_resume_info(text):
99
  #####################################
100
  def summarize_basic_info(info):
101
  """
102
- Create a paragraph summary from the basic resume information.
103
  """
104
  parts = []
 
105
  if info.get("Name"):
106
- parts.append(f"{info['Name']}")
 
 
 
107
  if info.get("Age"):
108
  parts.append(f"aged {info['Age']}")
109
- if info.get("Work Experience"):
110
- parts.append(f"with {info['Work Experience']} of work experience")
111
- if info.get("Expected Industry/Direction"):
112
- parts.append(f"seeking opportunities in {info['Expected Industry/Direction']}")
113
-
114
- if parts:
115
- summary_paragraph = "The candidate is " + ", ".join(parts) + "."
116
- else:
117
- summary_paragraph = "Basic information could not be extracted from the resume."
 
 
118
  return summary_paragraph
119
 
120
  #####################################
@@ -123,22 +141,21 @@ def summarize_basic_info(info):
123
  def process_resume(file_obj):
124
  if file_obj is None:
125
  return None, None
126
-
127
- # Extract text content from the file.
128
  resume_text = extract_text_from_file(file_obj)
129
- # Extract and summarize basic info.
130
  basic_info = extract_basic_resume_info(resume_text)
 
131
  summary_paragraph = summarize_basic_info(basic_info)
132
-
133
  return resume_text, summary_paragraph
134
 
135
  #####################################
136
  # Streamlit Interface
137
  #####################################
138
- st.title("Resume Basic Info Summary")
139
  st.markdown("""
140
- Upload your resume file in **.doc** or **.docx** format. The app will extract the content and generate a summary paragraph
141
- that highlights the candidate's basic information (name, age, work experience, and expected industry/direction).
142
  """)
143
 
144
  uploaded_file = st.file_uploader("Upload Resume", type=["doc", "docx"])
@@ -151,4 +168,7 @@ if st.button("Process Resume"):
151
  resume_text, summary_paragraph = process_resume(uploaded_file)
152
 
153
  st.subheader("Summary of Basic Information")
154
- st.markdown(summary_paragraph)
 
 
 
 
25
  text = f"Error processing DOCX file: {e}"
26
  elif ext == ".doc":
27
  try:
28
+ # textract requires a filename; solve this using a temporary file.
29
  with tempfile.NamedTemporaryFile(delete=False, suffix=".doc") as tmp:
30
  tmp.write(file_obj.read())
31
  tmp.flush()
 
51
  Parse the extracted text to summarize basic info:
52
  - Name
53
  - Age
54
+ - Job Experience (years or descriptive)
55
+ - Skills
56
+ - Education
57
+
58
+ Returns a dictionary with the extracted elements.
59
  """
60
  info = {
61
  "Name": None,
62
  "Age": None,
63
+ "Job Experience": None,
64
+ "Skills": None,
65
+ "Education": None,
66
  }
67
 
68
  # Extract Name (e.g., "Name: John Doe")
 
70
  if name_match:
71
  info["Name"] = name_match.group(1).strip()
72
  else:
73
+ # Fallback: heuristic, assume the first two or three capitalized words are the candidate name.
74
  potential_names = re.findall(r"\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){1,2}\b", text)
75
  if potential_names:
76
  info["Name"] = potential_names[0]
 
79
  age_match = re.search(r"[Aa]ge[:\-]\s*(\d{1,2})", text)
80
  if age_match:
81
  info["Age"] = age_match.group(1)
82
+
83
+ # Extract Job Experience (e.g., "5 years of experience")
84
  exp_match = re.search(r"(\d+)\s+(years|yrs)\s+(?:of\s+)?experience", text, re.IGNORECASE)
85
  if exp_match:
86
+ info["Job Experience"] = f"{exp_match.group(1)} {exp_match.group(2)}"
87
  else:
88
+ # Attempt to capture a descriptive work experience line via a labeled section.
89
+ exp_line = re.search(r"(Experience|Work History)[:\-]\s*(.+)", text, re.IGNORECASE)
90
  if exp_line:
91
+ info["Job Experience"] = exp_line.group(2).strip()
92
+
93
+ # Extract Skills (e.g., "Skills: Python, Java, SQL")
94
+ # This is a simple pattern and might require refinement for your resume formats.
95
+ skills_match = re.search(r"(Skills|Technical Skills)[:\-]\s*(.+)", text, re.IGNORECASE)
96
+ if skills_match:
97
+ # Cleanup skills by removing any trailing or extra characters.
98
+ skills_str = skills_match.group(2).strip()
99
+ info["Skills"] = skills_str.rstrip(".")
100
+
101
+ # Extract Education (e.g., "Education: B.Sc in Computer Science")
102
+ edu_match = re.search(r"Education[:\-]\s*(.+)", text, re.IGNORECASE)
103
+ if edu_match:
104
+ edu_str = edu_match.group(1).strip()
105
+ info["Education"] = edu_str.rstrip(".")
106
 
107
  return info
108
 
 
111
  #####################################
112
  def summarize_basic_info(info):
113
  """
114
+ Combine the extracted basic resume information into a cohesive paragraph.
115
  """
116
  parts = []
117
+
118
  if info.get("Name"):
119
+ parts.append(f"Candidate {info['Name']}")
120
+ else:
121
+ parts.append("The candidate")
122
+
123
  if info.get("Age"):
124
  parts.append(f"aged {info['Age']}")
125
+
126
+ if info.get("Job Experience"):
127
+ parts.append(f"with {info['Job Experience']} of work experience")
128
+
129
+ if info.get("Skills"):
130
+ parts.append(f"skilled in {info['Skills']}")
131
+
132
+ if info.get("Education"):
133
+ parts.append(f"and educated with a background in {info['Education']}")
134
+
135
+ summary_paragraph = ", ".join(parts) + "."
136
  return summary_paragraph
137
 
138
  #####################################
 
141
  def process_resume(file_obj):
142
  if file_obj is None:
143
  return None, None
144
+ # Extract the full resume text.
 
145
  resume_text = extract_text_from_file(file_obj)
146
+ # Extract basic info from the text.
147
  basic_info = extract_basic_resume_info(resume_text)
148
+ # Create a summary paragraph from the extracted info.
149
  summary_paragraph = summarize_basic_info(basic_info)
 
150
  return resume_text, summary_paragraph
151
 
152
  #####################################
153
  # Streamlit Interface
154
  #####################################
155
+ st.title("Resume Basic Information Summary")
156
  st.markdown("""
157
+ Upload your resume file in **.doc** or **.docx** format. The app will extract the document's content and generate a summary paragraph
158
+ highlighting the candidates name, age, job experience, skills, and education.
159
  """)
160
 
161
  uploaded_file = st.file_uploader("Upload Resume", type=["doc", "docx"])
 
168
  resume_text, summary_paragraph = process_resume(uploaded_file)
169
 
170
  st.subheader("Summary of Basic Information")
171
+ st.markdown(summary_paragraph)
172
+
173
+ st.subheader("Full Extracted Resume Text")
174
+ st.text_area("", resume_text, height=300)