Josif_tepe

Untitled

Jun 13th, 2025
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. import io
  2. import os
  3.  
  4. import PyPDF2
  5. import streamlit as st
  6. from dotenv import load_dotenv
  7. import openai
  8. from openai import api_key, OpenAI
  9.  
  10. load_dotenv()
  11.  
  12. st.set_page_config(page_title="AI Resume Critiquer", page_icon="", layout="centered")
  13. st.title("AI Resume Critiquer")
  14. st.markdown("Upload your resume and get AI-powered feedback tailored to your needs!")
  15.  
  16. OPENAI_KEY = os.getenv('OPENAI_API_KEY')
  17.  
  18. uplodaded_file = st.file_uploader("Upload your resume (PDF or TXT", type=['pdf', 'txt'])
  19. job_role = st.text_input("Enter the jon role you're applying for: ")
  20. analyze_button = st.button("Analyze Resume")
  21.  
  22.  
  23. def extract_text_from_pdf_file(pdf_file_path):
  24.     pdf_reader = PyPDF2.PdfReader(pdf_file_path)
  25.     text = ""
  26.     for page in pdf_reader.pages:
  27.         text += page.extract_text() + '\n'
  28.  
  29.     return text
  30.  
  31. def extract_text_from_file(uploaded_file):
  32.     if uploaded_file.type == "application/pdf":
  33.         return extract_text_from_pdf_file(io.BytesIO(uploaded_file.read()))
  34.  
  35.     return uploaded_file.read().decode('utf-8')
  36.  
  37.  
  38. if analyze_button and uplodaded_file:
  39.     try:
  40.         file_content = extract_text_from_file(uplodaded_file)
  41.  
  42.         if not file_content.strip():
  43.             st.error("File does not have any content...")
  44.             st.stop()
  45.  
  46.         prompt = f"""Please analyze this resume and provide constructive feedback.
  47.        Focus on the following aspects:
  48.        1. Content clarity and impact
  49.        2. Skills presentation
  50.        3. Experience description
  51.        4. Specific improvements for {job_role if job_role else 'general job application!'}
  52.        
  53.        
  54.        Resume content:
  55.        {file_content}
  56.        
  57.        Please provide your analysis in a clear, structured format with specific recommendations.
  58.        """
  59.         open_ai_client = OpenAI(api_key=OPENAI_KEY)
  60.         response = open_ai_client.chat.completions.create(
  61.             model="gpt-4o-mini",
  62.             messages=[
  63.                 {"role": "system", "content": "You are an expert resume reviewer with years of hiring and HR experience"},
  64.                 {"role": "user", "content": prompt}
  65.             ],
  66.             max_tokens=1000
  67.         )
  68.  
  69.         st.markdown("Analysis Results!")
  70.         st.markdown(response.choices[0].message.content)
  71.     except Exception as e:
  72.         st.error(e)
  73.  
Advertisement
Add Comment
Please, Sign In to add comment