Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
|
|
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
import faiss
|
| 5 |
import numpy as np
|
|
@@ -24,6 +26,23 @@ groq_client = Groq(api_key=st.secrets.get("GROQ_API_KEY", None))
|
|
| 24 |
# -----------------------------
|
| 25 |
# FUNCTIONS
|
| 26 |
# -----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def fetch_jobs():
|
| 29 |
resp = requests.get(REMOTEOK_URL)
|
|
@@ -36,16 +55,13 @@ def embed_texts(texts):
|
|
| 36 |
return model.encode(texts, convert_to_numpy=True, normalize_embeddings=True)
|
| 37 |
|
| 38 |
def match_jobs(resume_text, jobs, top_k=5):
|
| 39 |
-
# prepare job descriptions
|
| 40 |
job_texts = [f"{job.get('position','')} {job.get('company','')} {job.get('description','')}" for job in jobs]
|
| 41 |
|
| 42 |
-
# embeddings
|
| 43 |
resume_vec = embed_texts([resume_text])
|
| 44 |
job_vecs = embed_texts(job_texts)
|
| 45 |
|
| 46 |
-
# FAISS index
|
| 47 |
dim = job_vecs.shape[1]
|
| 48 |
-
index = faiss.IndexFlatIP(dim)
|
| 49 |
index.add(job_vecs)
|
| 50 |
|
| 51 |
scores, idx = index.search(resume_vec, top_k)
|
|
@@ -75,21 +91,22 @@ def generate_resume(resume_text, job):
|
|
| 75 |
# -----------------------------
|
| 76 |
st.title("MATCHHIVE - AI Job Matcher")
|
| 77 |
|
| 78 |
-
resume_file = st.file_uploader("Upload your resume (
|
| 79 |
if resume_file:
|
| 80 |
-
resume_text = resume_file
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
+
import pdfplumber
|
| 4 |
+
import docx
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
import faiss
|
| 7 |
import numpy as np
|
|
|
|
| 26 |
# -----------------------------
|
| 27 |
# FUNCTIONS
|
| 28 |
# -----------------------------
|
| 29 |
+
def extract_text_from_resume(file):
|
| 30 |
+
"""Extract text from PDF or DOCX file"""
|
| 31 |
+
if file.name.endswith(".pdf"):
|
| 32 |
+
text = ""
|
| 33 |
+
with pdfplumber.open(file) as pdf:
|
| 34 |
+
for page in pdf.pages:
|
| 35 |
+
text += page.extract_text() or ""
|
| 36 |
+
return text
|
| 37 |
+
|
| 38 |
+
elif file.name.endswith(".docx"):
|
| 39 |
+
doc = docx.Document(file)
|
| 40 |
+
text = "\n".join([p.text for p in doc.paragraphs])
|
| 41 |
+
return text
|
| 42 |
+
|
| 43 |
+
else:
|
| 44 |
+
st.error("Unsupported file type. Please upload PDF or DOCX.")
|
| 45 |
+
return ""
|
| 46 |
|
| 47 |
def fetch_jobs():
|
| 48 |
resp = requests.get(REMOTEOK_URL)
|
|
|
|
| 55 |
return model.encode(texts, convert_to_numpy=True, normalize_embeddings=True)
|
| 56 |
|
| 57 |
def match_jobs(resume_text, jobs, top_k=5):
|
|
|
|
| 58 |
job_texts = [f"{job.get('position','')} {job.get('company','')} {job.get('description','')}" for job in jobs]
|
| 59 |
|
|
|
|
| 60 |
resume_vec = embed_texts([resume_text])
|
| 61 |
job_vecs = embed_texts(job_texts)
|
| 62 |
|
|
|
|
| 63 |
dim = job_vecs.shape[1]
|
| 64 |
+
index = faiss.IndexFlatIP(dim)
|
| 65 |
index.add(job_vecs)
|
| 66 |
|
| 67 |
scores, idx = index.search(resume_vec, top_k)
|
|
|
|
| 91 |
# -----------------------------
|
| 92 |
st.title("MATCHHIVE - AI Job Matcher")
|
| 93 |
|
| 94 |
+
resume_file = st.file_uploader("Upload your resume (PDF or DOCX)", type=["pdf", "docx"])
|
| 95 |
if resume_file:
|
| 96 |
+
resume_text = extract_text_from_resume(resume_file)
|
| 97 |
|
| 98 |
+
if resume_text.strip():
|
| 99 |
+
st.subheader("Fetching jobs...")
|
| 100 |
+
jobs = fetch_jobs()
|
| 101 |
|
| 102 |
+
st.subheader("Best Matches")
|
| 103 |
+
matches = match_jobs(resume_text, jobs, top_k=5)
|
| 104 |
|
| 105 |
+
for job, score in matches:
|
| 106 |
+
st.markdown(f"**{job['position']}** at *{job['company']}* \n"
|
| 107 |
+
f"[View Job Posting]({job['url']}) \n"
|
| 108 |
+
f"**Match Score:** {score:.2f}")
|
| 109 |
|
| 110 |
+
if st.button(f"Generate Resume for {job['position']}", key=job['id']):
|
| 111 |
+
tailored_resume = generate_resume(resume_text, job)
|
| 112 |
+
st.text_area("Tailored Resume", tailored_resume, height=300)
|