Spaces:
Sleeping
Sleeping
| import os | |
| import streamlit as st | |
| from langchain_community.document_loaders import UnstructuredPDFLoader | |
| from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace | |
| # Set HuggingFace API keys | |
| hf_token = os.getenv("HF_Token") | |
| os.environ["HUGGINGFACEHUB_API_TOKEN"] =hf_token | |
| os.environ["HF_TOKEN"]=hf_token | |
| llm_skeleton = HuggingFaceEndpoint( | |
| repo_id="meta-llama/Llama-3.1-8B-Instruct", | |
| provider="novita", | |
| temperature=0.7, | |
| max_new_tokens=150, | |
| task="conversational" | |
| ) | |
| llm = ChatHuggingFace( | |
| llm=llm_skeleton, | |
| repo_id="meta-llama/Llama-3.2-3B-Instruct", | |
| provider="novita", | |
| temperature=0.7, | |
| max_new_tokens=150, | |
| task="conversational" | |
| ) | |
| # Helper function to extract text from uploaded file | |
| def extract_text(file): | |
| try: | |
| loader = UnstructuredPDFLoader(file) | |
| return loader.load()[0].page_content | |
| except Exception as e: | |
| st.error(f"Error reading file: {e}") | |
| return "" | |
| # Streamlit UI | |
| st.set_page_config(page_title="Resume & JD Extractor", layout="centered") | |
| st.title("π Resume & Job Description Extractor") | |
| # Upload inputs | |
| resume_file = st.file_uploader("Upload Resume (PDF)", type=["pdf"]) | |
| jd_file = st.file_uploader("Upload Job Description (PDF or TXT)", type=["pdf", "txt"]) | |
| jd_text = st.text_area("Or paste Job Description text here") | |
| # Extract button | |
| if st.button("π Extract Data"): | |
| if not resume_file and not (jd_file or jd_text): | |
| st.warning("Please upload at least one file (Resume or JD) or paste JD text.") | |
| # Extract Resume | |
| if resume_file: | |
| resume_text = extract_text(resume_file) | |
| 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.subheader("π Extracted Resume Data") | |
| st.markdown(f"<div style='background-color:#f9f9f9;padding:10px;border-radius:8px;'>{resume_data}</div>", unsafe_allow_html=True) | |
| # Extract JD | |
| if jd_file or jd_text: | |
| jd_text_extracted = extract_text(jd_file) if jd_file else jd_text | |
| 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.subheader("π Extracted Job Description Data") | |
| st.markdown(f"<div style='background-color:#f9f9f9;padding:10px;border-radius:8px;'>{jd_data}</div>", unsafe_allow_html=True) | |