Spaces:
Runtime error
Runtime error
Download app.py from deepak1307/jd_score: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/spaces/deepak1307/jd_score/resolve/main/app.py
- Command line
-
hf download hf://spaces/deepak1307/jd_score/app.py
-
curl -L -o app.py https://huggingface.co/spaces/deepak1307/jd_score/resolve/main/app.py
3.88 kB
| import openai | |
| import os | |
| import streamlit as st | |
| import json | |
| from PyPDF2 import PdfReader | |
| JD_SCORE="User will give a Job description. On a scale of 0 to 100, how likely is it that a person with the given set of skills is a good fit for the job described? Also seperately mention the years of experience required from the job description. If the the experience required in job description is more than what is mentioned below then mention it clearly. \n Skills: {skills}" | |
| WORK_EXP="User will give a job description. On a scale of 0 to 100, how likely is it that a person with the given the work experience a good fit for the job description. Do consider years of experience as well. BE STRCT. If the the experience required in job description is more than what is mentioned below then mention it clearly and reject the candidate. Only one candidate's experience is given. The candidate may have multiple work experiences. \n Work Experience: {work_experience}" | |
| GPT_MODELS = ["gpt-3.5-turbo-16k", "gpt-4", "gpt-4-turbo-preview", "gpt-4-32k", "gpt-4-32k-0613", "gpt-3.5-turbo"] # Add your other model names here | |
| def get_openai_key(): | |
| if "openai_key" not in st.session_state: | |
| with st.form("API key"): | |
| key = st.text_input("OpenAI Key", value="", type="password") | |
| if st.form_submit_button("Submit"): | |
| st.session_state.openai_key = key | |
| st.session_state.prompt_history = [] | |
| st.session_state.df = None | |
| st.success('Saved API key for this session.') | |
| def process_pdf_upload(pdf): | |
| pdf_read = PdfReader(pdf) | |
| raw_text = '' | |
| for i, page in enumerate(pdf_read.pages): | |
| content = page.extract_text() | |
| if content: | |
| raw_text += content | |
| result_raw_text = ' '.join(raw_text.splitlines()) | |
| return result_raw_text | |
| def generate_chat_completion(conv_list, prompt, model): | |
| response = openai.ChatCompletion.create( | |
| model=model, | |
| messages=conv_list, | |
| temperature=0, | |
| ) | |
| return response['choices'][0]['message']['content'].strip() | |
| if "openai_key" not in st.session_state: | |
| get_openai_key() | |
| if "openai_key" in st.session_state: | |
| openai.api_key = st.session_state.openai_key | |
| pdf = st.file_uploader("Upload your PDF", type='pdf') | |
| job_description = st.text_area("Job Description", placeholder='Job Description', key='job-description', height=100) | |
| extra_prompt = st.text_area("Additional Requirements", placeholder="Optional Instructions", key='extra-prompt', height=100) | |
| selected_model = st.selectbox("Select Model", GPT_MODELS) | |
| if st.button("Submit"): | |
| with st.spinner("Generating....."): | |
| if pdf is not None: | |
| result_raw_text = process_pdf_upload(pdf) | |
| conv_list = [{"role": "system", "content": "From the data given by the user of a person, extract the job experience and work done by the person. Also associate work done with technical skills and mention them as well."}] | |
| conv_list.append({"role": "user", "content": result_raw_text}) | |
| work_experience = generate_chat_completion(conv_list, "", selected_model) | |
| st.write(work_experience) | |
| if extra_prompt: | |
| jd_score_prompt = f'These are certain requirements that are a must:\n {extra_prompt}' | |
| jd_prompt = WORK_EXP.format(work_experience=work_experience) + jd_score_prompt | |
| else: | |
| jd_prompt = WORK_EXP.format(work_experience=work_experience) | |
| print(jd_prompt) | |
| conv_list_2 = [{"role": "system", "content": jd_prompt}] | |
| conv_list_2.append({"role": "user", "content": str(job_description)}) | |
| response = generate_chat_completion(conv_list_2, "", selected_model) | |
| st.write(response) | |