Spaces:
Sleeping
Sleeping
Ahmad-Moiz
commited on
Commit
•
9f0ae72
1
Parent(s):
eca0481
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ from llama_index import ServiceContext
|
|
9 |
from llama_index.schema import NodeWithScore
|
10 |
from llama_index.response_synthesizers import TreeSummarize
|
11 |
from pydantic import BaseModel
|
|
|
|
|
12 |
|
13 |
# Load environment variables from .env file
|
14 |
load_dotenv()
|
@@ -65,12 +67,12 @@ class ResumeScreenerPack(BaseLlamaPack):
|
|
65 |
"""Get modules."""
|
66 |
return {"synthesizer": self.synthesizer}
|
67 |
|
68 |
-
def run(self,
|
69 |
"""Run pack."""
|
70 |
node_with_score_input = {
|
71 |
"metadata": {}, # Provide any necessary metadata
|
72 |
-
"content":
|
73 |
-
"type": "
|
74 |
}
|
75 |
|
76 |
output = self.synthesizer.synthesize(
|
@@ -85,17 +87,36 @@ def main():
|
|
85 |
# Sidebar for user input
|
86 |
job_description = st.text_area("Job Description")
|
87 |
criteria = st.text_area("Screening Criteria (separate each criterion by a new line)")
|
88 |
-
|
|
|
89 |
|
90 |
if st.button("Submit"):
|
91 |
-
if job_description and criteria and
|
|
|
|
|
92 |
screener_pack = ResumeScreenerPack(job_description=job_description, criteria=criteria.split("\n"))
|
93 |
|
94 |
-
with st.spinner("Analyzing the
|
95 |
-
result = screener_pack.run(
|
96 |
|
97 |
st.subheader("Screening Results")
|
98 |
st.json(result)
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
if __name__ == "__main__":
|
101 |
main()
|
|
|
9 |
from llama_index.schema import NodeWithScore
|
10 |
from llama_index.response_synthesizers import TreeSummarize
|
11 |
from pydantic import BaseModel
|
12 |
+
import PyPDF2
|
13 |
+
import io
|
14 |
|
15 |
# Load environment variables from .env file
|
16 |
load_dotenv()
|
|
|
67 |
"""Get modules."""
|
68 |
return {"synthesizer": self.synthesizer}
|
69 |
|
70 |
+
def run(self, resume_text: str) -> Any:
|
71 |
"""Run pack."""
|
72 |
node_with_score_input = {
|
73 |
"metadata": {}, # Provide any necessary metadata
|
74 |
+
"content": resume_text, # Use extracted text as content
|
75 |
+
"type": "resume_text", # Define the type as per your schema
|
76 |
}
|
77 |
|
78 |
output = self.synthesizer.synthesize(
|
|
|
87 |
# Sidebar for user input
|
88 |
job_description = st.text_area("Job Description")
|
89 |
criteria = st.text_area("Screening Criteria (separate each criterion by a new line)")
|
90 |
+
|
91 |
+
uploaded_file = st.file_uploader("Upload Resume (PDF)", type=["pdf"])
|
92 |
|
93 |
if st.button("Submit"):
|
94 |
+
if job_description and criteria and uploaded_file:
|
95 |
+
resume_text = extract_text_from_pdf(uploaded_file)
|
96 |
+
|
97 |
screener_pack = ResumeScreenerPack(job_description=job_description, criteria=criteria.split("\n"))
|
98 |
|
99 |
+
with st.spinner("Analyzing the resume..."):
|
100 |
+
result = screener_pack.run(resume_text)
|
101 |
|
102 |
st.subheader("Screening Results")
|
103 |
st.json(result)
|
104 |
|
105 |
+
def extract_text_from_pdf(uploaded_file):
|
106 |
+
if uploaded_file is not None:
|
107 |
+
try:
|
108 |
+
# Read PDF content using PyPDF2's PdfReader
|
109 |
+
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
110 |
+
text = ""
|
111 |
+
for page in pdf_reader.pages:
|
112 |
+
text += page.extract_text()
|
113 |
+
return text
|
114 |
+
except Exception as e:
|
115 |
+
st.error(f"Error extracting text from PDF: {str(e)}")
|
116 |
+
return ""
|
117 |
+
else:
|
118 |
+
st.error("Please upload a PDF file.")
|
119 |
+
return ""
|
120 |
+
|
121 |
if __name__ == "__main__":
|
122 |
main()
|