File size: 2,731 Bytes
db91ea2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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)