Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import google.generativeai as genai | |
| import os | |
| import PyPDF2 as pdf | |
| from dotenv import load_dotenv | |
| import json | |
| # Load environment variables | |
| load_dotenv() | |
| # Configure Google Generative AI | |
| genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) | |
| # Function to get response from Gemini | |
| def get_gemini_response(input): | |
| model = genai.GenerativeModel('gemini-pro') | |
| response = model.generate_content(input) | |
| return response.text | |
| # Function to extract text from PDF | |
| def input_pdf_text(uploaded_file): | |
| if uploaded_file is not None: | |
| reader = pdf.PdfReader(uploaded_file) | |
| text = "" | |
| for page in range(len(reader.pages)): | |
| page = reader.pages[page] | |
| text += str(page.extract_text()) | |
| return text | |
| else: | |
| return "" | |
| # Prompt templates for predefined questions | |
| predefined_prompts = { | |
| "What needs to improve?": """ | |
| As a skilled ATS with a deep understanding of the tech field, software engineering, data science, | |
| data analysis, and big data engineering, evaluate the resume based on the given job description. | |
| Provide feedback on what needs to be improved in the resume in concise, bullet points, and short, | |
| containing useful tips relevant to the job description. | |
| resume: {text} | |
| description: {jd} | |
| """, | |
| "How well does my resume match the job description?": """ | |
| As a skilled ATS with a deep understanding of the tech field, software engineering, data science, | |
| data analysis, and big data engineering, evaluate the resume based on the given job description. | |
| Assign a percentage match based on the job description and the resume. | |
| resume: {text} | |
| description: {jd} | |
| """, | |
| "What are the missing keywords?": """ | |
| As a skilled ATS with a deep understanding of the tech field, software engineering, data science, | |
| data analysis, and big data engineering, evaluate the resume based on the given job description. | |
| Identify the missing keywords in the resume in concise, bullet points. | |
| resume: {text} | |
| description: {jd} | |
| """, | |
| "Can you summarize the profile?": """ | |
| As a skilled ATS with a deep understanding of the tech field, software engineering, data science, | |
| data analysis, and big data engineering, evaluate the resume based on the given job description. | |
| Provide a concise summary of the profile. | |
| resume: {text} | |
| description: {jd} | |
| """ | |
| } | |
| # app | |
| st.title("Smart ATS") | |
| st.sidebar.title("Job Description and Resume") | |
| # Job Description input | |
| jd = st.sidebar.text_area("Paste the Job Description", help="Enter the job description for the position you are applying for.") | |
| # Resume upload | |
| uploaded_file = st.sidebar.file_uploader("Upload Your Resume", type="pdf", help="Please upload your resume in PDF format.") | |
| resume_text = input_pdf_text(uploaded_file) | |
| # Pre-written questions | |
| st.sidebar.subheader("Quick Questions") | |
| questions = [ | |
| "What needs to improve?", | |
| "How well does my resume match the job description?", | |
| "What are the missing keywords?", | |
| "Can you summarize the profile?" | |
| ] | |
| selected_question = st.sidebar.radio("Choose a question:", questions) | |
| # Custom question input | |
| custom_question = st.text_input("Ask a custom question:", help="Enter any custom question related to your resume and job description.") | |
| # Submit button for custom question | |
| custom_submit = st.button("Reply") | |
| # Function to display formatted response | |
| def display_response(response): | |
| st.subheader("According to ATS:") | |
| formatted_response = format_response(response) | |
| st.markdown(formatted_response, unsafe_allow_html=True) | |
| def format_response(response): | |
| lines = response.split("\n") | |
| html_list = "<ol>" | |
| for line in lines: | |
| if line.strip(): | |
| parts = line.split(":", 1) | |
| main_point = parts[0].strip() | |
| details = parts[1].strip() if len(parts) > 1 else "" | |
| html_list += f"<li><b>{main_point}:</b> {details}</li>" | |
| html_list += "</ol>" | |
| return html_list | |
| # Handle pre-written question | |
| if selected_question and resume_text and not custom_submit: | |
| input_text = predefined_prompts[selected_question].format(text=resume_text, jd=jd) | |
| response = get_gemini_response(input_text) | |
| st.subheader(selected_question) | |
| display_response(response) | |
| # Handle custom question | |
| if custom_submit and custom_question and resume_text and jd: | |
| custom_prompt = f""" | |
| As a skilled ATS with a deep understanding of the tech field, software engineering, data science, | |
| data analysis, and big data engineering, evaluate the resume based on the given job description. | |
| Respond to the following custom question: {custom_question} | |
| resume: {{text}} | |
| description: {{jd}} | |
| """ | |
| input_text = custom_prompt.format(text=resume_text, jd=jd) | |
| response = get_gemini_response(input_text) | |
| st.subheader("Your Question Response") | |
| display_response(response) | |
| # Styling for buttons | |
| st.markdown( | |
| """ | |
| <style> | |
| .stButton button { | |
| background-color: #4CAF50; | |
| color: white; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |