JobGPT / app.py
Aditya Patkar
Added module docstrings and clean up
30396cd
raw
history blame
5.04 kB
'''
This is the main file of the app. This file contains the code for the streamlit app.
'''
import streamlit as st
from streamlit_chat import message
from job_description_generator import predict_job_description, get_job_description_conversation
from job_description_fixer import fix_job_description, get_job_description_fixer_conversation
conversation = get_job_description_conversation()
if 'generator_conversation' not in st.session_state:
st.session_state['generator_conversation'] = conversation
fixer_conversation = get_job_description_fixer_conversation()
if 'fixer_conversation' not in st.session_state:
st.session_state['fixer_conversation'] = fixer_conversation
def message_writer(input_text, response):
'''
Writes the messages to the chat window.
'''
messages = []
current_message = ""
current_is_user = True
for historical_message in response['history']:
if "human" in historical_message.lower():
messages.append([current_message, current_is_user])
current_message = historical_message.replace("Human:", "")
current_is_user = True
elif "JobGPT" in historical_message:
messages.append([current_message, current_is_user])
current_message = historical_message.replace("JobGPT:", "")
current_is_user = False
else:
current_message = current_message + "\n" + historical_message
messages.append([current_message, current_is_user])
for message_to_send, is_user in messages:
if message_to_send.strip() != "":
message(message_to_send, is_user=is_user)
message(input_text, is_user=True)
message(response['prediction'], is_user=False)
return 0
def setup():
"""
Streamlit related setup. This has to be run for each page.
"""
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
def main():
'''
Main function of the app.
'''
setup()
#create a sidebar where you can select your page
st.sidebar.title("JobGPT")
st.sidebar.markdown("---")
#selector
page = st.sidebar.selectbox(
"Select a page", ["Home", "Job Description Generator", "Job Description Fixer"])
if page == "Home":
st.title("JobGPT")
st.write("Select a page in the sidebar to get started.")
st.write("### Available options:")
st.write("1. Job Description Generator")
st.write("2. Job Description Fixer")
st.markdown("---")
elif page == "Job Description Generator":
container_one = st.container()
container_one.title("A Job Description Generating Chatbot")
container_one.markdown(
"JobGPT is a chatbot that generates job descriptions. \
This is built just for demo purpose."
)
input_text = container_one.text_input(
"Prompt",
"Hi, can you please help me generate an unbiased job description?")
button = container_one.button("Send")
st.sidebar.markdown("---")
st.sidebar.markdown("Click on `new chat` to start a new chat. \
History will be cleared and you'll lose access to current chat."
)
clear_session = st.sidebar.button("New Chat")
if clear_session:
st.session_state['generator_conversation'] = conversation
container_one.markdown("---")
initial_message = "Hello, how can I help you?"
message(initial_message)
if button:
response = predict_job_description(input_text,
st.session_state['generator_conversation'])
message_writer(input_text, response)
elif page == "Job Description Fixer":
container_two = st.container()
container_two.title("JobGPT: A Job Description Fixing Chatbot")
container_two.markdown(
"JobGPT is a chatbot that fixes job descriptions. This is built just for demo purpose."
)
input_text = container_two.text_area(
"Prompt",
"Hi, can you please help me fix my job description? It's biased.")
button = container_two.button("Send")
st.sidebar.markdown("---")
st.sidebar.markdown("Click on `new chat` to start a new chat. \
History will be cleared and you'll lose access to current chat."
)
clear_session = st.sidebar.button("New Chat")
if clear_session:
st.session_state['fixer_conversation'] = fixer_conversation
container_two.markdown("---")
initial_message = "Hello, how can I help you?"
message(initial_message)
if button:
response = fix_job_description(
input_text, st.session_state['fixer_conversation'])
message_writer(input_text, response)
main()