Spaces:
Sleeping
Sleeping
Aditya Patkar
commited on
Commit
·
6d30494
1
Parent(s):
4c4ef6d
First Commit
Browse files- app.py +152 -0
- job_description_fixer.py +29 -0
- job_description_generator.py +29 -0
- llm.py +37 -0
- requirements.txt +4 -0
- templates/job_description_fixer.txt +33 -0
- templates/job_description_generation.txt +35 -0
app.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_chat import message
|
| 3 |
+
|
| 4 |
+
from job_description_generator import predict_job_description, get_job_description_conversation
|
| 5 |
+
from job_description_fixer import fix_job_description, get_job_description_fixer_conversation
|
| 6 |
+
|
| 7 |
+
conversation = get_job_description_conversation()
|
| 8 |
+
if 'conversation' not in st.session_state:
|
| 9 |
+
st.session_state['conversation'] = conversation
|
| 10 |
+
|
| 11 |
+
fixer_conversation = get_job_description_fixer_conversation()
|
| 12 |
+
if 'fixer_conversation' not in st.session_state:
|
| 13 |
+
st.session_state['fixer_conversation'] = fixer_conversation
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def setup():
|
| 17 |
+
"""
|
| 18 |
+
Streamlit related setup. This has to be run for each page.
|
| 19 |
+
"""
|
| 20 |
+
hide_streamlit_style = """
|
| 21 |
+
|
| 22 |
+
<style>
|
| 23 |
+
#MainMenu {visibility: hidden;}
|
| 24 |
+
footer {visibility: hidden;}
|
| 25 |
+
</style>
|
| 26 |
+
"""
|
| 27 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def main():
|
| 31 |
+
'''
|
| 32 |
+
Main function of the app.
|
| 33 |
+
'''
|
| 34 |
+
setup()
|
| 35 |
+
|
| 36 |
+
#create a sidebar where you can select your page
|
| 37 |
+
st.sidebar.title("JobGPT")
|
| 38 |
+
st.sidebar.markdown("---")
|
| 39 |
+
#selector
|
| 40 |
+
page = st.sidebar.selectbox(
|
| 41 |
+
"Select a page", ["Job Description Generator", "Job Description Fixer"])
|
| 42 |
+
if page == "Job Description Generator":
|
| 43 |
+
c1 = st.container()
|
| 44 |
+
c1.title("JobGPT: A Job Description Generating Chatbot")
|
| 45 |
+
c1.markdown(
|
| 46 |
+
"JobGPT is a chatbot that generates job descriptions. This is built just for demo purpose."
|
| 47 |
+
)
|
| 48 |
+
input_text = c1.text_input(
|
| 49 |
+
"Prompt",
|
| 50 |
+
"Hi, can you please help me generate an unbiased job description?")
|
| 51 |
+
button = c1.button("Send")
|
| 52 |
+
|
| 53 |
+
st.sidebar.markdown("---")
|
| 54 |
+
st.sidebar.markdown("Click on `new chat` to start a new chat. \
|
| 55 |
+
History will be cleared and you'll lose access to current chat."
|
| 56 |
+
)
|
| 57 |
+
clear_session = st.sidebar.button("New Chat")
|
| 58 |
+
|
| 59 |
+
if clear_session:
|
| 60 |
+
st.session_state['conversation'] = conversation
|
| 61 |
+
c1.markdown("---")
|
| 62 |
+
|
| 63 |
+
initial_message = "Hello, how can I help you?"
|
| 64 |
+
message(initial_message)
|
| 65 |
+
|
| 66 |
+
if button:
|
| 67 |
+
messages = []
|
| 68 |
+
current_message = ""
|
| 69 |
+
current_is_user = True
|
| 70 |
+
#clear prompt textbox
|
| 71 |
+
response = predict_job_description(input_text,
|
| 72 |
+
st.session_state['conversation'])
|
| 73 |
+
for historical_message in response['history']:
|
| 74 |
+
if "human" in historical_message.lower():
|
| 75 |
+
messages.append([current_message, current_is_user])
|
| 76 |
+
current_message = historical_message.replace("Human:", "")
|
| 77 |
+
current_is_user = True
|
| 78 |
+
# message(historical_message.replace("Human:", ""),
|
| 79 |
+
# is_user=True)
|
| 80 |
+
elif "JobGPT" in historical_message:
|
| 81 |
+
messages.append([current_message, current_is_user])
|
| 82 |
+
current_message = historical_message.replace("JobGPT:", "")
|
| 83 |
+
current_is_user = False
|
| 84 |
+
else:
|
| 85 |
+
current_message = current_message + "\n" + historical_message
|
| 86 |
+
# if message_to_send != "":
|
| 87 |
+
# message(message_to_send.replace("JobGPT:",
|
| 88 |
+
# "").replace("Human:", ""),
|
| 89 |
+
# is_user=is_user)
|
| 90 |
+
messages.append([current_message, current_is_user])
|
| 91 |
+
for message_to_send, is_user in messages:
|
| 92 |
+
if message_to_send.strip() != "":
|
| 93 |
+
message(message_to_send, is_user=is_user)
|
| 94 |
+
message(input_text, is_user=True)
|
| 95 |
+
message(response['prediction'], is_user=False)
|
| 96 |
+
else:
|
| 97 |
+
c2 = st.container()
|
| 98 |
+
c2.title("JobGPT: A Job Description Fixing Chatbot")
|
| 99 |
+
c2.markdown(
|
| 100 |
+
"JobGPT is a chatbot that fixes job descriptions. This is built just for demo purpose."
|
| 101 |
+
)
|
| 102 |
+
input_text = c2.text_area(
|
| 103 |
+
"Prompt",
|
| 104 |
+
"Hi, can you please help me fix my job description? It's biased.")
|
| 105 |
+
button = c2.button("Send")
|
| 106 |
+
|
| 107 |
+
st.sidebar.markdown("---")
|
| 108 |
+
st.sidebar.markdown("Click on `new chat` to start a new chat. \
|
| 109 |
+
History will be cleared and you'll lose access to current chat."
|
| 110 |
+
)
|
| 111 |
+
clear_session = st.sidebar.button("New Chat")
|
| 112 |
+
|
| 113 |
+
if clear_session:
|
| 114 |
+
st.session_state['fixer_conversation'] = fixer_conversation
|
| 115 |
+
c2.markdown("---")
|
| 116 |
+
|
| 117 |
+
initial_message = "Hello, how can I help you?"
|
| 118 |
+
message(initial_message)
|
| 119 |
+
|
| 120 |
+
if button:
|
| 121 |
+
messages = []
|
| 122 |
+
current_message = ""
|
| 123 |
+
current_is_user = True
|
| 124 |
+
#clear prompt textbox
|
| 125 |
+
response = fix_job_description(
|
| 126 |
+
input_text, st.session_state['fixer_conversation'])
|
| 127 |
+
for historical_message in response['history']:
|
| 128 |
+
if "human" in historical_message.lower():
|
| 129 |
+
messages.append([current_message, current_is_user])
|
| 130 |
+
current_message = historical_message.replace("Human:", "")
|
| 131 |
+
current_is_user = True
|
| 132 |
+
# message(historical_message.replace("Human:", ""),
|
| 133 |
+
# is_user=True)
|
| 134 |
+
elif "JobGPT" in historical_message:
|
| 135 |
+
messages.append([current_message, current_is_user])
|
| 136 |
+
current_message = historical_message.replace("JobGPT:", "")
|
| 137 |
+
current_is_user = False
|
| 138 |
+
else:
|
| 139 |
+
current_message = current_message + "\n" + historical_message
|
| 140 |
+
# if message_to_send != "":
|
| 141 |
+
# message(message_to_send.replace("JobGPT:",
|
| 142 |
+
# "").replace("Human:", ""),
|
| 143 |
+
# is_user=is_user)
|
| 144 |
+
messages.append([current_message, current_is_user])
|
| 145 |
+
for message_to_send, is_user in messages:
|
| 146 |
+
if message_to_send.strip() != "":
|
| 147 |
+
message(message_to_send, is_user=is_user)
|
| 148 |
+
message(input_text, is_user=True)
|
| 149 |
+
message(response['prediction'], is_user=False)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
main()
|
job_description_fixer.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
from langchain.chat_models import ChatOpenAI
|
| 4 |
+
from langchain.memory import ConversationBufferMemory
|
| 5 |
+
from llm import generate_prompt, generate_conversation, predict
|
| 6 |
+
|
| 7 |
+
openai_api_key = os.environ['OPENAI_API_KEY']
|
| 8 |
+
openai.api_key = openai_api_key
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def get_job_description_fixer_conversation():
|
| 12 |
+
'''
|
| 13 |
+
Generate a conversation object for job description fixer
|
| 14 |
+
'''
|
| 15 |
+
prompt = generate_prompt(
|
| 16 |
+
input_variables=['history', 'input'],
|
| 17 |
+
template_file='templates/job_description_fixer.txt')
|
| 18 |
+
llm = ChatOpenAI(temperature=0, openai_api_key=openai_api_key)
|
| 19 |
+
memory = ConversationBufferMemory(ai_prefix="JobGPT")
|
| 20 |
+
conversation = generate_conversation(memory=memory, llm=llm, prompt=prompt)
|
| 21 |
+
return conversation
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def fix_job_description(input_text: str, conversation: object):
|
| 25 |
+
'''
|
| 26 |
+
predict the next response from the conversation object
|
| 27 |
+
'''
|
| 28 |
+
response = predict(input_text=input_text, conversation=conversation)
|
| 29 |
+
return response
|
job_description_generator.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
from langchain.chat_models import ChatOpenAI
|
| 4 |
+
from langchain.memory import ConversationBufferMemory
|
| 5 |
+
from llm import generate_prompt, generate_conversation, predict
|
| 6 |
+
|
| 7 |
+
openai_api_key = os.environ['OPENAI_API_KEY']
|
| 8 |
+
openai.api_key = openai_api_key
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def get_job_description_conversation():
|
| 12 |
+
'''
|
| 13 |
+
Generate a conversation object for job description generation
|
| 14 |
+
'''
|
| 15 |
+
prompt = generate_prompt(
|
| 16 |
+
input_variables=['history', 'input'],
|
| 17 |
+
template_file='templates/job_description_generation.txt')
|
| 18 |
+
llm = ChatOpenAI(temperature=0, openai_api_key=openai_api_key)
|
| 19 |
+
memory = ConversationBufferMemory(ai_prefix="JobGPT")
|
| 20 |
+
conversation = generate_conversation(memory=memory, llm=llm, prompt=prompt)
|
| 21 |
+
return conversation
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def predict_job_description(input_text: str, conversation: object):
|
| 25 |
+
'''
|
| 26 |
+
Predict the next response from the conversation object
|
| 27 |
+
'''
|
| 28 |
+
response = predict(input_text=input_text, conversation=conversation)
|
| 29 |
+
return response
|
llm.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.chains import ConversationChain
|
| 2 |
+
from langchain.prompts import PromptTemplate
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def generate_prompt(input_variables: list, template_file: str):
|
| 6 |
+
"""
|
| 7 |
+
Generate a prompt from a template file and a list of input variables
|
| 8 |
+
"""
|
| 9 |
+
with open(template_file, 'r', encoding='utf-8') as source_file:
|
| 10 |
+
template = source_file.read()
|
| 11 |
+
prompt = PromptTemplate(template=template, input_variables=input_variables)
|
| 12 |
+
return prompt
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def generate_conversation(memory: object,
|
| 16 |
+
llm: object,
|
| 17 |
+
prompt: object,
|
| 18 |
+
verbose: bool = False):
|
| 19 |
+
"""
|
| 20 |
+
Generate a conversation from a memory object, a language model object, and a prompt object
|
| 21 |
+
"""
|
| 22 |
+
conversation = ConversationChain(memory=memory,
|
| 23 |
+
llm=llm,
|
| 24 |
+
prompt=prompt,
|
| 25 |
+
verbose=verbose)
|
| 26 |
+
return conversation
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def predict(input_text: str, conversation: object):
|
| 30 |
+
'''
|
| 31 |
+
Predict the next response from the conversation object
|
| 32 |
+
'''
|
| 33 |
+
response = conversation(input_text)
|
| 34 |
+
history = response['history']
|
| 35 |
+
history = history.split('\n')
|
| 36 |
+
prediction = response['response']
|
| 37 |
+
return {'history': history, 'prediction': prediction}
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain==0.0.194
|
| 2 |
+
openai==0.27.8
|
| 3 |
+
streamlit==1.23.1
|
| 4 |
+
streamlit_chat==0.0.2.2
|
templates/job_description_fixer.txt
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
JobGPT is a chatbot which fixes job posting for executive positions in terms of bias, format etc.
|
| 2 |
+
|
| 3 |
+
It greets the human and then asks to paste a job posting \
|
| 4 |
+
|
| 5 |
+
Once it has the job posting, it fixes the job posting using following guidelines \
|
| 6 |
+
Use gender-neutral language: Avoid using gender-specific pronouns (he, she) and job titles (salesman, saleswoman). Instead, opt for inclusive terms such as “they” and “salesperson.” \
|
| 7 |
+
Focus on skills and qualifications: When writing job descriptions, emphasize the skills, qualifications, and experience required for the role, rather than making assumptions about which gender might be more suitable. \
|
| 8 |
+
Remove gender-coded words: Avoid using adjectives that may be associated with a specific gender, such as “aggressive” or “nurturing.” Use neutral descriptors, like “results-driven” or “collaborative.” \
|
| 9 |
+
Closely consider the education requirements listed in the job posting. \
|
| 10 |
+
Express a commitment to equality and diversity. \
|
| 11 |
+
Identify bias in job description in the form of “issue” and “how to fix” \
|
| 12 |
+
|
| 13 |
+
If the posting is already fixed, it tells the human that it is already fixed. \
|
| 14 |
+
|
| 15 |
+
The fixed job description includes following sections, well formatted: \
|
| 16 |
+
Job Title \
|
| 17 |
+
Company name \
|
| 18 |
+
About the job \
|
| 19 |
+
small description \
|
| 20 |
+
responsibilities \
|
| 21 |
+
Required qualifications \
|
| 22 |
+
Benefitial qualifications \
|
| 23 |
+
Salary : JobGPT estimates salary based on location and title, return a range of numbers \
|
| 24 |
+
Legal writeup \
|
| 25 |
+
|
| 26 |
+
Finally it tells what changes it made to the job posting \
|
| 27 |
+
|
| 28 |
+
The following is a friendly conversation between a human and JobGPT. JobGPT provides lots of specific details from its context. Your job is to predict what JobGPT says next.
|
| 29 |
+
|
| 30 |
+
Current conversation:
|
| 31 |
+
{history}
|
| 32 |
+
Human: {input}
|
| 33 |
+
JobGPT:
|
templates/job_description_generation.txt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
JobGPT is a chatbot which generates job description for executive positions
|
| 2 |
+
|
| 3 |
+
It greets the human and then ask ONLY one question at a time to get the following information \
|
| 4 |
+
title: \
|
| 5 |
+
industry: \
|
| 6 |
+
location: \
|
| 7 |
+
skills: \
|
| 8 |
+
experience: \
|
| 9 |
+
One it has the above information, generate a job description as follows \
|
| 10 |
+
|
| 11 |
+
It strictly follows these guidelines: \
|
| 12 |
+
Use gender-neutral language: Avoid using gender-specific pronouns (he, she) and job titles (salesman, saleswoman). Instead, opt for inclusive terms such as “they” and “salesperson.” \
|
| 13 |
+
Focus on skills and qualifications: When writing job descriptions, emphasize the skills, qualifications, and experience required for the role, rather than making assumptions about which gender might be more suitable. \
|
| 14 |
+
Remove gender-coded words: Avoid using adjectives that may be associated with a specific gender, such as “aggressive” or “nurturing.” Use neutral descriptors, like “results-driven” or “collaborative.” \
|
| 15 |
+
Closely consider the education requirements listed in the job posting. \
|
| 16 |
+
Express a commitment to equality and diversity. \
|
| 17 |
+
Identify bias in job description in form of “issue” and “how to fix” \
|
| 18 |
+
|
| 19 |
+
The job description includes following sections, well formatted: \
|
| 20 |
+
Job Title \
|
| 21 |
+
Company name \
|
| 22 |
+
About the job \
|
| 23 |
+
small description \
|
| 24 |
+
responsibilities \
|
| 25 |
+
Required qualifications \
|
| 26 |
+
Benefitial qualifications \
|
| 27 |
+
Salary : JobGPT estimates salary based on location and title, return a range of numbers \
|
| 28 |
+
Legal writeup \
|
| 29 |
+
|
| 30 |
+
The following is a friendly conversation between a human and JobGPT. JobGPT provides lots of specific details from its context. Your job is to predict what JobGPT says next.
|
| 31 |
+
|
| 32 |
+
Current conversation:
|
| 33 |
+
{history}
|
| 34 |
+
Human: {input}
|
| 35 |
+
JobGPT:
|