Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,95 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
import
|
| 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 |
-
for job in jobs
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from sentence_transformers import SentenceTransformer
|
| 4 |
+
import faiss
|
| 5 |
+
import numpy as np
|
| 6 |
+
from groq import Groq
|
| 7 |
+
|
| 8 |
+
# -----------------------------
|
| 9 |
+
# CONFIG
|
| 10 |
+
# -----------------------------
|
| 11 |
+
REMOTEOK_URL = "https://remoteok.com/api"
|
| 12 |
+
EMBED_MODEL = "BAAI/bge-small-en-v1.5"
|
| 13 |
+
|
| 14 |
+
# Load embedding model
|
| 15 |
+
@st.cache_resource
|
| 16 |
+
def load_model():
|
| 17 |
+
return SentenceTransformer(EMBED_MODEL)
|
| 18 |
+
|
| 19 |
+
model = load_model()
|
| 20 |
+
|
| 21 |
+
# Initialize Groq client
|
| 22 |
+
groq_client = Groq(api_key=st.secrets.get("GROQ_API_KEY", None))
|
| 23 |
+
|
| 24 |
+
# -----------------------------
|
| 25 |
+
# FUNCTIONS
|
| 26 |
+
# -----------------------------
|
| 27 |
+
|
| 28 |
+
def fetch_jobs():
|
| 29 |
+
resp = requests.get(REMOTEOK_URL)
|
| 30 |
+
if resp.status_code == 200:
|
| 31 |
+
jobs = resp.json()[1:] # skip metadata
|
| 32 |
+
return jobs
|
| 33 |
+
return []
|
| 34 |
+
|
| 35 |
+
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) # cosine similarity (normalized)
|
| 49 |
+
index.add(job_vecs)
|
| 50 |
+
|
| 51 |
+
scores, idx = index.search(resume_vec, top_k)
|
| 52 |
+
results = []
|
| 53 |
+
for i, score in zip(idx[0], scores[0]):
|
| 54 |
+
results.append((jobs[i], float(score)))
|
| 55 |
+
return results
|
| 56 |
+
|
| 57 |
+
def generate_resume(resume_text, job):
|
| 58 |
+
prompt = f"""
|
| 59 |
+
You are an AI career assistant.
|
| 60 |
+
Given this resume:\n{resume_text}\n
|
| 61 |
+
and this job description:\n{job['description']}\n
|
| 62 |
+
Generate a tailored one-page resume that highlights relevant skills and experience.
|
| 63 |
+
Keep it concise and professional.
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
chat_completion = groq_client.chat.completions.create(
|
| 67 |
+
model="llama-3.1-70b-versatile",
|
| 68 |
+
messages=[{"role": "user", "content": prompt}],
|
| 69 |
+
temperature=0.7,
|
| 70 |
+
)
|
| 71 |
+
return chat_completion.choices[0].message["content"]
|
| 72 |
+
|
| 73 |
+
# -----------------------------
|
| 74 |
+
# STREAMLIT UI
|
| 75 |
+
# -----------------------------
|
| 76 |
+
st.title("MATCHHIVE - AI Job Matcher")
|
| 77 |
+
|
| 78 |
+
resume_file = st.file_uploader("Upload your resume (txt/pdf/docx)", type=["txt"])
|
| 79 |
+
if resume_file:
|
| 80 |
+
resume_text = resume_file.read().decode("utf-8", errors="ignore")
|
| 81 |
+
|
| 82 |
+
st.subheader("Fetching jobs...")
|
| 83 |
+
jobs = fetch_jobs()
|
| 84 |
+
|
| 85 |
+
st.subheader("Best Matches")
|
| 86 |
+
matches = match_jobs(resume_text, jobs, top_k=5)
|
| 87 |
+
|
| 88 |
+
for job, score in matches:
|
| 89 |
+
st.markdown(f"**{job['position']}** at *{job['company']}* \n"
|
| 90 |
+
f"[View Job Posting]({job['url']}) \n"
|
| 91 |
+
f"**Match Score:** {score:.2f}")
|
| 92 |
+
|
| 93 |
+
if st.button(f"Generate Resume for {job['position']}", key=job['id']):
|
| 94 |
+
tailored_resume = generate_resume(resume_text, job)
|
| 95 |
+
st.text_area("Tailored Resume", tailored_resume, height=300)
|