Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pdfplumber
|
3 |
+
import spacy
|
4 |
+
import openai
|
5 |
+
import os
|
6 |
+
|
7 |
+
# Set your OpenAI API key
|
8 |
+
openai.api_key = "your_openai_api_key" # Replace with your actual OpenAI API Key
|
9 |
+
|
10 |
+
# Load spaCy model for NLP
|
11 |
+
nlp = spacy.load("en_core_web_sm")
|
12 |
+
|
13 |
+
def extract_text_from_pdf(pdf_file):
|
14 |
+
"""Extracts text from an uploaded PDF resume."""
|
15 |
+
text = ""
|
16 |
+
try:
|
17 |
+
with pdfplumber.open(pdf_file) as pdf:
|
18 |
+
for page in pdf.pages:
|
19 |
+
text += page.extract_text() + "\n"
|
20 |
+
except Exception as e:
|
21 |
+
st.error(f"Error extracting text from PDF: {e}")
|
22 |
+
return text.strip()
|
23 |
+
|
24 |
+
def extract_keywords(text):
|
25 |
+
"""Extracts important keywords from resume text using spaCy."""
|
26 |
+
doc = nlp(text)
|
27 |
+
keywords = set()
|
28 |
+
for token in doc:
|
29 |
+
if token.pos_ in ["NOUN", "PROPN"]: # Extract nouns and proper nouns
|
30 |
+
keywords.add(token.text.lower())
|
31 |
+
return list(keywords)
|
32 |
+
|
33 |
+
def analyze_resume(text):
|
34 |
+
"""Uses OpenAI GPT to analyze resume and suggest improvements."""
|
35 |
+
prompt = f"""
|
36 |
+
You are a professional resume analyzer. Given the following resume text,
|
37 |
+
provide a rating (out of 10), identify missing keywords based on general job trends,
|
38 |
+
and suggest improvements.
|
39 |
+
|
40 |
+
Resume Text:
|
41 |
+
{text}
|
42 |
+
|
43 |
+
Your response should be in this structured format:
|
44 |
+
- Resume Rating: (score out of 10)
|
45 |
+
- Missing Keywords: (comma-separated list)
|
46 |
+
- Suggestions for Improvement: (bullet points)
|
47 |
+
"""
|
48 |
+
|
49 |
+
response = openai.ChatCompletion.create(
|
50 |
+
model="gpt-4",
|
51 |
+
messages=[{"role": "user", "content": prompt}]
|
52 |
+
)
|
53 |
+
return response["choices"][0]["message"]["content"]
|
54 |
+
|
55 |
+
# Streamlit UI
|
56 |
+
st.title("π AI-Powered Resume Analyzer")
|
57 |
+
st.write("Upload your resume, and AI will provide feedback to improve it!")
|
58 |
+
|
59 |
+
uploaded_file = st.file_uploader("Upload your Resume (PDF format)", type=["pdf"])
|
60 |
+
|
61 |
+
if uploaded_file is not None:
|
62 |
+
with st.spinner("Processing your resume..."):
|
63 |
+
resume_text = extract_text_from_pdf(uploaded_file)
|
64 |
+
|
65 |
+
if resume_text:
|
66 |
+
keywords = extract_keywords(resume_text)
|
67 |
+
analysis_result = analyze_resume(resume_text)
|
68 |
+
|
69 |
+
st.subheader("π Resume Analysis Report")
|
70 |
+
st.write(analysis_result)
|
71 |
+
|
72 |
+
st.subheader("π Extracted Keywords")
|
73 |
+
st.write(", ".join(keywords))
|
74 |
+
|
75 |
+
st.success("β
Resume analyzed successfully!")
|
76 |
+
else:
|
77 |
+
st.error("Could not extract text from the PDF. Please try another file.")
|