|
import streamlit as st |
|
import pdfplumber |
|
import spacy |
|
import openai |
|
import os |
|
from dotenv import load_dotenv |
|
import subprocess |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
openai.api_key = os.getenv("OPENAI_API_KEY") |
|
|
|
|
|
try: |
|
nlp = spacy.load("en_core_web_sm") |
|
except OSError: |
|
st.warning("Downloading 'en_core_web_sm' model. Please wait...") |
|
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"]) |
|
nlp = spacy.load("en_core_web_sm") |
|
|
|
def extract_text_from_pdf(pdf_file): |
|
"""Extracts text from an uploaded PDF resume.""" |
|
text = "" |
|
try: |
|
with pdfplumber.open(pdf_file) as pdf: |
|
for page in pdf.pages: |
|
text += page.extract_text() + "\n" |
|
except Exception as e: |
|
st.error(f"Error extracting text from PDF: {e}") |
|
return text.strip() |
|
|
|
def extract_keywords(text): |
|
"""Extracts important keywords from resume text using spaCy.""" |
|
doc = nlp(text) |
|
keywords = set() |
|
for token in doc: |
|
if token.pos_ in ["NOUN", "PROPN"]: |
|
keywords.add(token.text.lower()) |
|
return list(keywords) |
|
|
|
def analyze_resume(text): |
|
"""Uses OpenAI GPT to analyze resume and suggest improvements.""" |
|
prompt = f""" |
|
You are a professional resume analyzer. Given the following resume text, |
|
provide a rating (out of 10), identify missing keywords based on general job trends, |
|
and suggest improvements. |
|
|
|
Resume Text: |
|
{text} |
|
|
|
Your response should be in this structured format: |
|
- Resume Rating: (score out of 10) |
|
- Missing Keywords: (comma-separated list) |
|
- Suggestions for Improvement: (bullet points) |
|
""" |
|
|
|
response = openai.ChatCompletion.create( |
|
model="gpt-4", |
|
messages=[{"role": "user", "content": prompt}] |
|
) |
|
return response["choices"][0]["message"]["content"] |
|
|
|
|
|
st.title("π AI-Powered Resume Analyzer") |
|
st.write("Upload your resume, and AI will provide feedback to improve it!") |
|
|
|
uploaded_file = st.file_uploader("Upload your Resume (PDF format)", type=["pdf"]) |
|
|
|
if uploaded_file is not None: |
|
with st.spinner("Processing your resume..."): |
|
resume_text = extract_text_from_pdf(uploaded_file) |
|
|
|
if resume_text: |
|
keywords = extract_keywords(resume_text) |
|
analysis_result = analyze_resume(resume_text) |
|
|
|
st.subheader("π Resume Analysis Report") |
|
st.write(analysis_result) |
|
|
|
st.subheader("π Extracted Keywords") |
|
st.write(", ".join(keywords)) |
|
|
|
st.success("β
Resume analyzed successfully!") |
|
else: |
|
st.error("Could not extract text from the PDF. Please try another file.") |
|
|
|
|