Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import tempfile
|
3 |
import re
|
|
|
4 |
import streamlit as st
|
5 |
import docx
|
6 |
import textract
|
@@ -51,7 +52,7 @@ def extract_text_from_file(file_obj):
|
|
51 |
def load_summarizer():
|
52 |
"""
|
53 |
Loads the summarization pipeline using a transformer model.
|
54 |
-
We use the model "
|
55 |
"""
|
56 |
return pipeline("summarization", model="google/pegasus-xsum")
|
57 |
|
@@ -61,11 +62,14 @@ def summarize_resume_text(resume_text):
|
|
61 |
If the resume text is very long, we trim it to avoid hitting the model's maximum input size.
|
62 |
"""
|
63 |
summarizer = load_summarizer()
|
64 |
-
|
|
|
65 |
max_input_length = 1024 # adjust as needed
|
66 |
if len(resume_text) > max_input_length:
|
|
|
67 |
resume_text = resume_text[:max_input_length]
|
68 |
-
|
|
|
69 |
summary_result = summarizer(resume_text, max_length=150, min_length=40, do_sample=False)
|
70 |
candidate_summary = summary_result[0]['summary_text']
|
71 |
return candidate_summary
|
@@ -92,8 +96,20 @@ def process_resume(file_obj):
|
|
92 |
Extracts text from the uploaded file and then generates a summary
|
93 |
using a text summarization model.
|
94 |
"""
|
|
|
95 |
resume_text = extract_text_from_file(file_obj)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
candidate_summary = summarize_resume_text(resume_text)
|
|
|
97 |
return candidate_summary
|
98 |
|
99 |
#####################################
|
@@ -115,7 +131,7 @@ st.markdown(
|
|
115 |
"""
|
116 |
Upload your resume file in **.doc** or **.docx** format. The app performs the following tasks:
|
117 |
1. Extracts text from the resume.
|
118 |
-
2. Uses a transformer-based text summarization model (**
|
119 |
3. Compares the candidate summary with a company profile (using Sentence-BERT) to produce a suitability score.
|
120 |
"""
|
121 |
)
|
@@ -130,9 +146,11 @@ if st.button("Process Resume"):
|
|
130 |
else:
|
131 |
with st.spinner("Processing resume..."):
|
132 |
candidate_summary = process_resume(uploaded_file)
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
136 |
|
137 |
# Pre-defined company prompt for Google LLC.
|
138 |
default_company_prompt = (
|
|
|
1 |
import os
|
2 |
import tempfile
|
3 |
import re
|
4 |
+
import time
|
5 |
import streamlit as st
|
6 |
import docx
|
7 |
import textract
|
|
|
52 |
def load_summarizer():
|
53 |
"""
|
54 |
Loads the summarization pipeline using a transformer model.
|
55 |
+
We use the model "google/pegasus-xsum" for summarization.
|
56 |
"""
|
57 |
return pipeline("summarization", model="google/pegasus-xsum")
|
58 |
|
|
|
62 |
If the resume text is very long, we trim it to avoid hitting the model's maximum input size.
|
63 |
"""
|
64 |
summarizer = load_summarizer()
|
65 |
+
|
66 |
+
# Trim resume_text if it's too long
|
67 |
max_input_length = 1024 # adjust as needed
|
68 |
if len(resume_text) > max_input_length:
|
69 |
+
st.info(f"Resume text is longer than {max_input_length} characters. Trimming text for summarization...")
|
70 |
resume_text = resume_text[:max_input_length]
|
71 |
+
|
72 |
+
# Generate summary
|
73 |
summary_result = summarizer(resume_text, max_length=150, min_length=40, do_sample=False)
|
74 |
candidate_summary = summary_result[0]['summary_text']
|
75 |
return candidate_summary
|
|
|
96 |
Extracts text from the uploaded file and then generates a summary
|
97 |
using a text summarization model.
|
98 |
"""
|
99 |
+
st.info("Extracting text from resume...")
|
100 |
resume_text = extract_text_from_file(file_obj)
|
101 |
+
|
102 |
+
# Check if resume_text is valid
|
103 |
+
if not resume_text or resume_text.strip() == "":
|
104 |
+
st.error("No text could be extracted. Please check your resume file!")
|
105 |
+
return ""
|
106 |
+
|
107 |
+
st.info(f"Text extraction complete. Extracted {len(resume_text)} characters.")
|
108 |
+
time.sleep(0.5) # slight delay to let the user read the info message
|
109 |
+
|
110 |
+
st.info("Generating candidate summary, please wait...")
|
111 |
candidate_summary = summarize_resume_text(resume_text)
|
112 |
+
st.info("Candidate summary generated.")
|
113 |
return candidate_summary
|
114 |
|
115 |
#####################################
|
|
|
131 |
"""
|
132 |
Upload your resume file in **.doc** or **.docx** format. The app performs the following tasks:
|
133 |
1. Extracts text from the resume.
|
134 |
+
2. Uses a transformer-based text summarization model (**google/pegasus-xsum**) to generate a concise candidate summary.
|
135 |
3. Compares the candidate summary with a company profile (using Sentence-BERT) to produce a suitability score.
|
136 |
"""
|
137 |
)
|
|
|
146 |
else:
|
147 |
with st.spinner("Processing resume..."):
|
148 |
candidate_summary = process_resume(uploaded_file)
|
149 |
+
if candidate_summary: # only if summary is generated
|
150 |
+
st.session_state["candidate_summary"] = candidate_summary
|
151 |
+
if candidate_summary:
|
152 |
+
st.subheader("Candidate Summary")
|
153 |
+
st.markdown(candidate_summary)
|
154 |
|
155 |
# Pre-defined company prompt for Google LLC.
|
156 |
default_company_prompt = (
|