File size: 3,867 Bytes
221306d 5d22396 f98d21e 3786f5d 221306d 3786f5d f98d21e 3786f5d 221306d 3786f5d f98d21e 3786f5d 221306d 3786f5d 8280d4c 3786f5d 221306d 5d22396 221306d 3786f5d 221306d 3786f5d 221306d 3786f5d 5d22396 5d924ed 5d22396 5d924ed 5d22396 8280d4c 5d22396 8280d4c 5d22396 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
import streamlit as st
import os
import pdfplumber # Proper PDF text extraction
from dotenv import load_dotenv
from groq import Groq
# Load API Key from .env
load_dotenv()
api_key = os.getenv("GROQ_API_KEY")
# Initialize Groq Client
client = Groq(api_key=api_key)
# Chatbot System Prompt
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)_
"""
# Function to Extract Text from PDF
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."
# Streamlit UI
st.title("π AI-Powered Resume Analyzer π€")
st.write("Upload your resume, and AI will analyze it for improvements!")
# File Uploader for PDF
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."
# Send request to Groq API using "llama-3.3-70b-versatile"
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,
)
# Stream response and format correctly
st.subheader("π‘ Resume Analysis")
full_response = ""
for chunk in completion:
chunk_text = chunk.choices[0].delta.content or ""
full_response += chunk_text
# Format Response
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('-', 'πΉ')}") # Convert hyphens to bullet points
st.markdown("### **π‘ Expert Improvement Tips**")
improvement_tips_part = full_response.split("**π‘ Expert Improvement Tips:**")[1].strip()
st.markdown(f"π {improvement_tips_part.replace('-', 'π')}") # Convert hyphens to bullet points
# Display success message
st.success("β
Resume analyzed successfully!")
else:
st.error("β οΈ No readable text found in the PDF. Please upload a valid resume.")
|