| import os | |
| import streamlit as st | |
| from langchain_community.document_loaders import UnstructuredPDFLoader | |
| from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace | |
| import tempfile | |
| os.environ["HF_TOKEN"]=os.getenv('HF_Token') | |
| os.environ["HUGGINGFACEHUB_API_KEY"]=os.getenv('HF_Token') | |
| llm_skeleton = HuggingFaceEndpoint( | |
| repo_id="deepseek-ai/DeepSeek-R1", | |
| provider="nebius", | |
| temperature=0.7, | |
| max_new_tokens=150, | |
| task="conversational" | |
| ) | |
| llm = ChatHuggingFace( | |
| llm=llm_skeleton, | |
| repo_id="deepseek-ai/DeepSeek-R1", | |
| provider="nebius", | |
| temperature=0.7, | |
| max_new_tokens=150, | |
| task="conversational" | |
| ) | |
| def extract_text_from_pdf(uploaded_file): | |
| try: | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file: | |
| tmp_file.write(uploaded_file.read()) | |
| tmp_path = tmp_file.name | |
| loader = UnstructuredPDFLoader(tmp_path) | |
| return loader.load()[0].page_content | |
| except Exception as e: | |
| st.error(f"β οΈ Error reading PDF file: {e}") | |
| return "" | |
| def extract_text_from_txt(uploaded_file): | |
| try: | |
| return uploaded_file.read().decode("utf-8") | |
| except Exception as e: | |
| st.error(f"β οΈ Error reading text file: {e}") | |
| return "" | |
| st.set_page_config(page_title="SmartHire AI β Resume & JD Analyzer", layout="centered") | |
| st.markdown("<h1 style='text-align:center;'>π€ SmartHire AI</h1>", unsafe_allow_html=True) | |
| st.markdown("<h4 style='text-align:center;color:gray;'>AI-powered Resume & Job Description Analyzer</h4><br>", unsafe_allow_html=True) | |
| with st.container(): | |
| st.markdown("### π Upload Center") | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| resume_file = st.file_uploader("Upload Candidate Resume (PDF)", type=["pdf"]) | |
| with col2: | |
| jd_file = st.file_uploader("Upload Job Description (PDF or TXT)", type=["pdf", "txt"]) | |
| jd_text = st.text_area("π Or paste the Job Description text below", height=150) | |
| if st.button("π Analyze Now"): | |
| if not resume_file and not (jd_file or jd_text): | |
| st.warning("β οΈ Please upload at least one resume or job description.") | |
| else: | |
| if resume_file: | |
| resume_text = extract_text_from_pdf(resume_file) | |
| if resume_text: | |
| resume_prompt = ( | |
| "Extract the following from the resume:\n" | |
| "1. Name\n2. Education\n3. Experience\n4. Skills\n5. Project Names and Results\n\n" | |
| f"Resume:\n{resume_text}" | |
| ) | |
| resume_data = llm.invoke(resume_prompt) | |
| st.markdown("---") | |
| st.subheader("π Candidate Summary") | |
| st.markdown(f""" | |
| <div style='background-color:#eef6fb;padding:15px;border-left:5px solid #0099cc;border-radius:6px'> | |
| {resume_data} | |
| </div> | |
| """, unsafe_allow_html=True) | |
| jd_text_extracted = "" | |
| if jd_file: | |
| if jd_file.type == "application/pdf": | |
| jd_text_extracted = extract_text_from_pdf(jd_file) | |
| elif jd_file.type == "text/plain": | |
| jd_text_extracted = extract_text_from_txt(jd_file) | |
| elif jd_text: | |
| jd_text_extracted = jd_text | |
| if jd_text_extracted: | |
| jd_prompt = ( | |
| "Extract the following from the job description:\n" | |
| "1. Job ID\n2. Company Name\n3. Role\n4. Experience Required\n5. Skills Required\n" | |
| "6. Education Required\n7. Location\n\n" | |
| f"Job Description:\n{jd_text_extracted}" | |
| ) | |
| jd_data = llm.invoke(jd_prompt) | |
| st.markdown("---") | |
| st.subheader("π Job Role Breakdown") | |
| st.markdown(f""" | |
| <div style='background-color:#fff7e6;padding:15px;border-left:5px solid #ffaa00;border-radius:6px'> | |
| {jd_data} | |
| </div> | |
| """, unsafe_allow_html=True) |