UmaKumpatla commited on
Commit
db91ea2
Β·
verified Β·
1 Parent(s): 90631e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from langchain_community.document_loaders import UnstructuredPDFLoader
4
+ from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
5
+
6
+ # Set HuggingFace API keys
7
+ hf_token = os.getenv("HF_Token")
8
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] =hf_token
9
+ os.environ["HF_TOKEN"]=hf_token
10
+
11
+ llm_skeleton = HuggingFaceEndpoint(
12
+ repo_id="meta-llama/Llama-3.1-8B-Instruct",
13
+ provider="novita",
14
+ temperature=0.7,
15
+ max_new_tokens=150,
16
+ task="conversational"
17
+ )
18
+
19
+ llm = ChatHuggingFace(
20
+ llm=llm_skeleton,
21
+ repo_id="meta-llama/Llama-3.2-3B-Instruct",
22
+ provider="novita",
23
+ temperature=0.7,
24
+ max_new_tokens=150,
25
+ task="conversational"
26
+ )
27
+
28
+ # Helper function to extract text from uploaded file
29
+ def extract_text(file):
30
+ try:
31
+ loader = UnstructuredPDFLoader(file)
32
+ return loader.load()[0].page_content
33
+ except Exception as e:
34
+ st.error(f"Error reading file: {e}")
35
+ return ""
36
+
37
+ # Streamlit UI
38
+ st.set_page_config(page_title="Resume & JD Extractor", layout="centered")
39
+ st.title("πŸ“„ Resume & Job Description Extractor")
40
+
41
+ # Upload inputs
42
+ resume_file = st.file_uploader("Upload Resume (PDF)", type=["pdf"])
43
+ jd_file = st.file_uploader("Upload Job Description (PDF or TXT)", type=["pdf", "txt"])
44
+ jd_text = st.text_area("Or paste Job Description text here")
45
+
46
+ # Extract button
47
+ if st.button("πŸ” Extract Data"):
48
+ if not resume_file and not (jd_file or jd_text):
49
+ st.warning("Please upload at least one file (Resume or JD) or paste JD text.")
50
+
51
+ # Extract Resume
52
+ if resume_file:
53
+ resume_text = extract_text(resume_file)
54
+ resume_prompt = (
55
+ "Extract the following from the resume:\n"
56
+ "1. Name\n2. Education\n3. Experience\n4. Skills\n5. Project Names and Results\n\n"
57
+ f"Resume:\n{resume_text}"
58
+ )
59
+ resume_data = llm.invoke(resume_prompt)
60
+ st.subheader("πŸ“Œ Extracted Resume Data")
61
+ st.markdown(f"<div style='background-color:#f9f9f9;padding:10px;border-radius:8px;'>{resume_data}</div>", unsafe_allow_html=True)
62
+
63
+ # Extract JD
64
+ if jd_file or jd_text:
65
+ jd_text_extracted = extract_text(jd_file) if jd_file else jd_text
66
+ jd_prompt = (
67
+ "Extract the following from the job description:\n"
68
+ "1. Job ID\n2. Company Name\n3. Role\n4. Experience Required\n5. Skills Required\n"
69
+ "6. Education Required\n7. Location\n\n"
70
+ f"Job Description:\n{jd_text_extracted}"
71
+ )
72
+ jd_data = llm.invoke(jd_prompt)
73
+ st.subheader("πŸ“Œ Extracted Job Description Data")
74
+ st.markdown(f"<div style='background-color:#f9f9f9;padding:10px;border-radius:8px;'>{jd_data}</div>", unsafe_allow_html=True)