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.")