Harika22 commited on
Commit
f94e2c1
ยท
verified ยท
1 Parent(s): 1110a40

Delete pages/model1.py

Browse files
Files changed (1) hide show
  1. pages/model1.py +0 -108
pages/model1.py DELETED
@@ -1,108 +0,0 @@
1
- import os
2
- import zipfile
3
- import tempfile
4
- import fitz
5
- import streamlit as st
6
- from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
7
-
8
- os.environ["HF_TOKEN"]=os.getenv('HF_Token')
9
- os.environ["HUGGINGFACEHUB_API_KEY"]=os.getenv('HF_Token')
10
-
11
- llm_base = 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_chat = ChatHuggingFace(
20
- llm=llm_base,
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
-
29
- def extract_pdf_text(file_bytes):
30
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
31
- tmp.write(file_bytes)
32
- with fitz.open(tmp.name) as doc:
33
- return "\n".join(page.get_text() for page in doc)
34
-
35
- def resume_extraction_prompt(text):
36
- return (
37
- "You are a resume parser. Extract the following details:\n"
38
- "- Full Name\n- Education\n- Work Experience\n- Skills\n- Project Titles and Results\n\n"
39
- f"Resume Content:\n{text}"
40
- )
41
-
42
- def jd_extraction_prompt(text):
43
- return (
44
- "You are an expert recruiter. Extract this info from the job description:\n"
45
- "- Job ID\n- Company\n- Role\n- Required Experience\n- Required Skills\n- Education\n- Location\n\n"
46
- f"JD Content:\n{text}"
47
- )
48
-
49
- def resume_matching_prompt(jd, resumes):
50
- return (
51
- "You are an AI hiring assistant. Based on the job description and candidate summaries,"
52
- " identify the best match considering skills, experience, and education.\n\n"
53
- f"Job Description:\n{jd}\n\n"
54
- f"Resumes:\n{resumes}\n\n"
55
- "Return the name of the best candidate and a short justification."
56
- )
57
-
58
- st.set_page_config(page_title="TalentMatch AI", layout="centered")
59
- st.title("๐Ÿง  TalentMatch AI: Resume & JD Matcher")
60
-
61
- with st.expander("๐Ÿ“˜ About this App"):
62
- st.markdown("""
63
- This AI-powered app extracts key details from resumes and job descriptions to intelligently
64
- match the most suitable candidate. Upload a ZIP of PDF resumes and a job description (or paste text)
65
- to get started!
66
- """)
67
-
68
- zip_upload = st.file_uploader("๐Ÿ“Ž Upload ZIP of PDF Resumes", type=["zip"])
69
- jd_upload = st.file_uploader("๐Ÿ“ Upload Job Description (PDF/TXT)", type=["pdf", "txt"])
70
- jd_text = st.text_area("โœ๏ธ Or Paste Job Description Text")
71
-
72
- # Match Button
73
- if st.button("๐Ÿš€ Match Best Candidate"):
74
- if not zip_upload or not (jd_upload or jd_text.strip()):
75
- st.warning("โš  Please upload both resumes and a job description.")
76
- else:
77
- # Extract JD text
78
- jd_content = jd_text.strip()
79
- if jd_upload:
80
- jd_content = (
81
- extract_pdf_text(jd_upload.read()) if jd_upload.name.endswith(".pdf")
82
- else jd_upload.read().decode("utf-8")
83
- )
84
-
85
- if len(jd_content.split()) < 30:
86
- st.warning("๐Ÿ“„ JD text seems too short. Please provide a more detailed description.")
87
- else:
88
- jd_info = llm_chat.invoke(jd_extraction_prompt(jd_content)).content
89
- st.subheader("๐Ÿ” Extracted Job Details")
90
- st.markdown(jd_info)
91
-
92
- resume_summaries = ""
93
- with tempfile.TemporaryDirectory() as tmpdir:
94
- with zipfile.ZipFile(zip_upload, "r") as zip_ref:
95
- pdfs = [f for f in zip_ref.namelist() if f.endswith(".pdf")]
96
- if not pdfs:
97
- st.error("No PDF resumes found in the ZIP.")
98
- st.stop()
99
- for pdf in pdfs:
100
- with zip_ref.open(pdf) as f:
101
- text = extract_pdf_text(f.read())
102
- summary = llm_chat.invoke(resume_extraction_prompt(text)).content
103
- resume_summaries += f"\n\n๐Ÿ“„ {pdf}\n{summary}"
104
-
105
- with st.spinner("๐Ÿงฎ Evaluating best match..."):
106
- match = llm_chat.invoke(resume_matching_prompt(jd_content, resume_summaries)).content
107
- st.subheader("โœ… Top Candidate Match")
108
- st.markdown(match)