|
import streamlit as st |
|
import os |
|
import pdfplumber |
|
from dotenv import load_dotenv |
|
from groq import Groq |
|
|
|
|
|
load_dotenv() |
|
api_key = os.getenv("GROQ_API_KEY") |
|
|
|
|
|
client = Groq(api_key=api_key) |
|
|
|
|
|
system_prompt = """ |
|
You are an AI Resume Analyzer designed to provide feedback on resumes. |
|
Your goal is to analyze resumes, identify missing keywords, rate resumes, |
|
and suggest better skills to highlight. |
|
|
|
### Response Format: |
|
**π Resume Rating:** _(Score out of 10)_ |
|
**π Missing Keywords:** _(Comma-separated list)_ |
|
**π Suggested Skills:** _(Bullet points)_ |
|
**π‘ Expert Improvement Tips:** _(Clear and actionable advice)_ |
|
""" |
|
|
|
|
|
def extract_text_from_pdf(pdf_file): |
|
"""Extracts text from an uploaded PDF resume using pdfplumber.""" |
|
text = "" |
|
try: |
|
with pdfplumber.open(pdf_file) as pdf: |
|
for page in pdf.pages: |
|
text += page.extract_text() + "\n" if page.extract_text() else "" |
|
except Exception as e: |
|
st.error(f"Error extracting text from PDF: {e}") |
|
return text.strip() or "No text found in the PDF." |
|
|
|
|
|
st.title("π AI-Powered Resume Analyzer π€") |
|
st.write("Upload your resume, and AI will analyze it for improvements!") |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload Your Resume (PDF)", type=["pdf"]) |
|
|
|
if uploaded_file is not None: |
|
with st.spinner("Analyzing your resume..."): |
|
resume_text = extract_text_from_pdf(uploaded_file) |
|
|
|
if resume_text and resume_text != "No text found in the PDF.": |
|
user_message = f"Resume Content:\n{resume_text}\n\nAnalyze the resume based on the given criteria." |
|
|
|
|
|
completion = client.chat.completions.create( |
|
model="llama-3.3-70b-versatile", |
|
messages=[ |
|
{"role": "system", "content": system_prompt}, |
|
{"role": "user", "content": user_message}, |
|
], |
|
temperature=0.6, |
|
max_tokens=4096, |
|
top_p=0.95, |
|
stream=True, |
|
) |
|
|
|
|
|
st.subheader("π‘ Resume Analysis") |
|
full_response = "" |
|
for chunk in completion: |
|
chunk_text = chunk.choices[0].delta.content or "" |
|
full_response += chunk_text |
|
|
|
|
|
st.markdown("### **π Resume Rating**") |
|
rating_part = full_response.split("**π Missing Keywords:**")[0].replace("**π Resume Rating:**", "").strip() |
|
st.markdown(f"β
**Rating:** {rating_part}") |
|
|
|
st.markdown("### **π Missing Keywords**") |
|
missing_keywords_part = full_response.split("**π Missing Keywords:**")[1].split("**π Suggested Skills:**")[0].strip() |
|
st.markdown(f"πΉ {missing_keywords_part}") |
|
|
|
st.markdown("### **π Suggested Skills**") |
|
suggested_skills_part = full_response.split("**π Suggested Skills:**")[1].split("**π‘ Expert Improvement Tips:**")[0].strip() |
|
st.markdown(f"πΈ {suggested_skills_part.replace('-', 'πΉ')}") |
|
|
|
st.markdown("### **π‘ Expert Improvement Tips**") |
|
improvement_tips_part = full_response.split("**π‘ Expert Improvement Tips:**")[1].strip() |
|
st.markdown(f"π {improvement_tips_part.replace('-', 'π')}") |
|
|
|
|
|
st.success("β
Resume analyzed successfully!") |
|
else: |
|
st.error("β οΈ No readable text found in the PDF. Please upload a valid resume.") |
|
|