Update app.py
Browse files
app.py
CHANGED
@@ -1,88 +1,60 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pdfplumber
|
3 |
-
import spacy
|
4 |
-
import openai
|
5 |
import os
|
6 |
from dotenv import load_dotenv
|
7 |
-
import
|
8 |
|
9 |
-
# Load
|
10 |
load_dotenv()
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
21 |
-
nlp = spacy.load("en_core_web_sm")
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
text += page.extract_text() + "\n"
|
30 |
-
except Exception as e:
|
31 |
-
st.error(f"Error extracting text from PDF: {e}")
|
32 |
-
return text.strip()
|
33 |
-
|
34 |
-
def extract_keywords(text):
|
35 |
-
"""Extracts important keywords from resume text using spaCy."""
|
36 |
-
doc = nlp(text)
|
37 |
-
keywords = set()
|
38 |
-
for token in doc:
|
39 |
-
if token.pos_ in ["NOUN", "PROPN"]: # Extract nouns and proper nouns
|
40 |
-
keywords.add(token.text.lower())
|
41 |
-
return list(keywords)
|
42 |
-
|
43 |
-
def analyze_resume(text):
|
44 |
-
"""Uses OpenAI GPT to analyze resume and suggest improvements."""
|
45 |
-
prompt = f"""
|
46 |
-
You are a professional resume analyzer. Given the following resume text,
|
47 |
-
provide a rating (out of 10), identify missing keywords based on general job trends,
|
48 |
-
and suggest improvements.
|
49 |
-
|
50 |
-
Resume Text:
|
51 |
-
{text}
|
52 |
-
|
53 |
-
Your response should be in this structured format:
|
54 |
-
- Resume Rating: (score out of 10)
|
55 |
-
- Missing Keywords: (comma-separated list)
|
56 |
-
- Suggestions for Improvement: (bullet points)
|
57 |
-
"""
|
58 |
-
|
59 |
-
response = openai.ChatCompletion.create(
|
60 |
-
model="gpt-4",
|
61 |
-
messages=[{"role": "user", "content": prompt}]
|
62 |
-
)
|
63 |
-
return response["choices"][0]["message"]["content"]
|
64 |
|
65 |
# Streamlit UI
|
66 |
-
st.title("
|
67 |
-
st.write("Upload your resume, and AI will
|
68 |
|
69 |
-
|
|
|
70 |
|
71 |
if uploaded_file is not None:
|
72 |
-
with st.spinner("
|
73 |
-
resume_text =
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
4 |
+
from groq import Groq
|
5 |
|
6 |
+
# Load API Key from .env
|
7 |
load_dotenv()
|
8 |
+
api_key = os.getenv("GROQ_API_KEY")
|
9 |
|
10 |
+
# Initialize Groq Client
|
11 |
+
client = Groq(api_key=api_key)
|
12 |
|
13 |
+
# Chatbot System Prompt
|
14 |
+
system_prompt = """
|
15 |
+
You are an AI Resume Analyzer designed to provide feedback on resumes.
|
16 |
+
Your goal is to analyze resumes, identify missing keywords, rate resumes,
|
17 |
+
and suggest better skills to highlight.
|
|
|
|
|
18 |
|
19 |
+
### Response Format:
|
20 |
+
1οΈβ£ **Resume Rating:** (Score out of 10)
|
21 |
+
2οΈβ£ **Missing Keywords:** (Comma-separated list)
|
22 |
+
3οΈβ£ **Suggested Skills:** (Bullet points)
|
23 |
+
4οΈβ£ **Expert Improvement Tips:** (Clear and actionable advice)
|
24 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Streamlit UI
|
27 |
+
st.title("π AI-Powered Resume Analyzer π€")
|
28 |
+
st.write("Upload your resume, and AI will analyze it for improvements!")
|
29 |
|
30 |
+
# File Uploader for PDF
|
31 |
+
uploaded_file = st.file_uploader("Upload Your Resume (PDF)", type=["pdf"])
|
32 |
|
33 |
if uploaded_file is not None:
|
34 |
+
with st.spinner("Analyzing your resume..."):
|
35 |
+
resume_text = uploaded_file.read().decode("utf-8") # Decode PDF text
|
36 |
+
user_message = f"Resume Content:\n{resume_text}\n\nAnalyze the resume based on the given criteria."
|
37 |
+
|
38 |
+
# Send request to Groq API
|
39 |
+
completion = client.chat.completions.create(
|
40 |
+
model="deepseek-r1-distill-llama-70b",
|
41 |
+
messages=[
|
42 |
+
{"role": "system", "content": system_prompt},
|
43 |
+
{"role": "user", "content": user_message},
|
44 |
+
],
|
45 |
+
temperature=0.6,
|
46 |
+
max_tokens=4096,
|
47 |
+
top_p=0.95,
|
48 |
+
stream=True,
|
49 |
+
)
|
50 |
+
|
51 |
+
# Stream response
|
52 |
+
st.subheader("π‘ Resume Analysis")
|
53 |
+
full_response = ""
|
54 |
+
for chunk in completion:
|
55 |
+
chunk_text = chunk.choices[0].delta.content or ""
|
56 |
+
full_response += chunk_text
|
57 |
+
st.write(chunk_text)
|
58 |
+
|
59 |
+
# Display final response
|
60 |
+
st.success("β
Resume analyzed successfully!")
|