Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%%writefile app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import os
|
| 4 |
+
import faiss
|
| 5 |
+
import numpy as np
|
| 6 |
+
import PyPDF2
|
| 7 |
+
from sentence_transformers import SentenceTransformer
|
| 8 |
+
from groq import Groq
|
| 9 |
+
|
| 10 |
+
# Set Groq API key
|
| 11 |
+
GROQ_API_KEY = "your-groq-api-key"
|
| 12 |
+
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 13 |
+
embedder = SentenceTransformer("all-MiniLM-L6-v2")
|
| 14 |
+
|
| 15 |
+
# Example job descriptions
|
| 16 |
+
job_data = {
|
| 17 |
+
"Data Scientist": "Python, Machine Learning, Data Analysis, Pandas, Scikit-learn, SQL",
|
| 18 |
+
"Software Engineer": "C++, Java, Git, Object Oriented Programming, System Design",
|
| 19 |
+
"Web Developer": "HTML, CSS, JavaScript, React, Responsive Design, Web APIs"
|
| 20 |
+
}
|
| 21 |
+
job_chunks = [f"{k}: {v}" for k, v in job_data.items()]
|
| 22 |
+
job_embeddings = embedder.encode(job_chunks)
|
| 23 |
+
faiss_index = faiss.IndexFlatL2(job_embeddings.shape[1])
|
| 24 |
+
faiss_index.add(np.array(job_embeddings).astype("float32"))
|
| 25 |
+
|
| 26 |
+
# ----------- Functions -----------
|
| 27 |
+
def extract_text_from_pdf(uploaded_file):
|
| 28 |
+
reader = PyPDF2.PdfReader(uploaded_file)
|
| 29 |
+
return " ".join([page.extract_text() for page in reader.pages if page.extract_text()])
|
| 30 |
+
|
| 31 |
+
def find_best_job_match(resume_text):
|
| 32 |
+
query_embed = embedder.encode([resume_text])
|
| 33 |
+
_, indices = faiss_index.search(np.array(query_embed).astype("float32"), 1)
|
| 34 |
+
return job_chunks[indices[0][0]]
|
| 35 |
+
|
| 36 |
+
def query_llm(context, question):
|
| 37 |
+
prompt = f"""You are an expert job coach. Based on the resume below and the job context:
|
| 38 |
+
|
| 39 |
+
Context: {context}
|
| 40 |
+
|
| 41 |
+
Resume: {question}
|
| 42 |
+
|
| 43 |
+
Give a simple analysis of how well this resume fits and what's missing."""
|
| 44 |
+
|
| 45 |
+
response = groq_client.chat.completions.create(
|
| 46 |
+
model="llama-3-8b-8192",
|
| 47 |
+
messages=[{"role": "user", "content": prompt}]
|
| 48 |
+
)
|
| 49 |
+
return response.choices[0].message.content
|
| 50 |
+
|
| 51 |
+
# ----------- Streamlit UI -----------
|
| 52 |
+
st.set_page_config(page_title="🧠 Resume Analyzer + Job Match AI")
|
| 53 |
+
st.title("📄 Resume Analyzer + Job Match AI")
|
| 54 |
+
|
| 55 |
+
uploaded_file = st.file_uploader("Upload Your Resume (PDF)", type=["pdf"])
|
| 56 |
+
if uploaded_file:
|
| 57 |
+
resume_text = extract_text_from_pdf(uploaded_file)
|
| 58 |
+
st.success("Resume Uploaded Successfully!")
|
| 59 |
+
|
| 60 |
+
st.subheader("💼 Analyzing for Job Match...")
|
| 61 |
+
best_job = find_best_job_match(resume_text)
|
| 62 |
+
st.write(f"🔍 Best Job Match Found: **{best_job}**")
|
| 63 |
+
|
| 64 |
+
with st.spinner("Analyzing Resume Fit..."):
|
| 65 |
+
response = query_llm(best_job, resume_text)
|
| 66 |
+
|
| 67 |
+
st.subheader("🧾 AI Feedback:")
|
| 68 |
+
st.write(response)
|
| 69 |
+
|
| 70 |
+
st.info("This app is for guidance only. Tailor your resume per job posting!")
|