Update pages/model.py
Browse files- pages/model.py +92 -0
pages/model.py
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from langchain_community.chat_models import ChatHuggingFace
|
| 4 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
| 5 |
+
from langchain_community.document_loaders import UnstructuredPDFLoader
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
os.environ["HF_TOKEN"]=os.getenv('HF_Token')
|
| 9 |
+
os.environ["HUGGINGFACEHUB_API_KEY"]=os.getenv('HF_Token')
|
| 10 |
+
|
| 11 |
+
llm_config = HuggingFaceEndpoint(
|
| 12 |
+
repo_id="meta-llama/Llama-3.1-8B-Instruct",
|
| 13 |
+
provider="nebius",
|
| 14 |
+
temperature=0.5,
|
| 15 |
+
max_new_tokens=300,
|
| 16 |
+
task="conversational"
|
| 17 |
+
)
|
| 18 |
+
llm = ChatHuggingFace(
|
| 19 |
+
llm=llm_config,
|
| 20 |
+
repo_id="meta-llama/Llama-3.1-8B-Instruct",
|
| 21 |
+
provider="nebius"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
st.set_page_config(page_title="Smart Resume-JD Extractor", layout="centered")
|
| 26 |
+
st.markdown("""
|
| 27 |
+
<div style="text-align:center; padding: 30px; background-color: #f3f4f6; border-radius: 12px;">
|
| 28 |
+
<h1 style="color:#2c3e50;">📄 PrescriptoHire: Resume & JD Extractor</h1>
|
| 29 |
+
<p style="color:#555; font-size: 16px;">AI-powered tool to extract & compare details from resumes and job descriptions</p>
|
| 30 |
+
</div>
|
| 31 |
+
""", unsafe_allow_html=True)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
resume_file = st.file_uploader("Upload Candidate Resume (PDF)", type=["pdf"])
|
| 35 |
+
jd_file = st.file_uploader("Upload Job Description (PDF)", type=["pdf"])
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
st.markdown("<p style='text-align:center; margin:10px 0;'>-- OR --</p>", unsafe_allow_html=True)
|
| 39 |
+
jd_text_input = st.text_area("Paste Job Description Text")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
if st.button("🔍 Extract & Compare"):
|
| 43 |
+
if not resume_file:
|
| 44 |
+
st.error("Please upload a resume PDF to proceed.")
|
| 45 |
+
else:
|
| 46 |
+
# Extract Resume Text
|
| 47 |
+
resume_text = UnstructuredPDFLoader(resume_file).load()[0].page_content
|
| 48 |
+
|
| 49 |
+
resume_prompt = f"""
|
| 50 |
+
Extract the following from the resume:
|
| 51 |
+
1. Name
|
| 52 |
+
2. Contact Info
|
| 53 |
+
3. Education
|
| 54 |
+
4. Experience
|
| 55 |
+
5. Skills
|
| 56 |
+
6. Projects and Achievements
|
| 57 |
+
|
| 58 |
+
Resume Text:
|
| 59 |
+
{resume_text}
|
| 60 |
+
"""
|
| 61 |
+
with st.spinner("Extracting from Resume..."):
|
| 62 |
+
resume_output = llm.invoke(resume_prompt)
|
| 63 |
+
st.success("Resume data extracted!")
|
| 64 |
+
st.subheader("🧾 Resume Summary")
|
| 65 |
+
st.write(resume_output)
|
| 66 |
+
|
| 67 |
+
# Process JD (file or text)
|
| 68 |
+
if jd_file or jd_text_input:
|
| 69 |
+
if jd_file:
|
| 70 |
+
jd_text = UnstructuredPDFLoader(jd_file).load()[0].page_content
|
| 71 |
+
else:
|
| 72 |
+
jd_text = jd_text_input
|
| 73 |
+
|
| 74 |
+
jd_prompt = f"""
|
| 75 |
+
Extract the following from the job description:
|
| 76 |
+
1. Job Title
|
| 77 |
+
2. Company Name
|
| 78 |
+
3. Experience Required
|
| 79 |
+
4. Key Responsibilities
|
| 80 |
+
5. Skills & Qualifications
|
| 81 |
+
6. Location
|
| 82 |
+
|
| 83 |
+
Job Description:
|
| 84 |
+
{jd_text}
|
| 85 |
+
"""
|
| 86 |
+
with st.spinner("Extracting from Job Description..."):
|
| 87 |
+
jd_output = llm.invoke(jd_prompt)
|
| 88 |
+
st.success("Job description data extracted!")
|
| 89 |
+
st.subheader("📌 Job Description Summary")
|
| 90 |
+
st.write(jd_output)
|
| 91 |
+
else:
|
| 92 |
+
st.warning("Please upload or paste a job description.")
|