File size: 6,251 Bytes
6d30494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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 'conversation' not in st.session_state:
    st.session_state['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 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", ["Job Description Generator", "Job Description Fixer"])
    if page == "Job Description Generator":
        c1 = st.container()
        c1.title("JobGPT: A Job Description Generating Chatbot")
        c1.markdown(
            "JobGPT is a chatbot that generates job descriptions. This is built just for demo purpose."
        )
        input_text = c1.text_input(
            "Prompt",
            "Hi, can you please help me generate an unbiased job description?")
        button = c1.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['conversation'] = conversation
        c1.markdown("---")

        initial_message = "Hello, how can I help you?"
        message(initial_message)

        if button:
            messages = []
            current_message = ""
            current_is_user = True
            #clear prompt textbox
            response = predict_job_description(input_text,
                                               st.session_state['conversation'])
            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
                    # message(historical_message.replace("Human:", ""),
                    #         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
                # if message_to_send != "":
                #     message(message_to_send.replace("JobGPT:",
                #                                     "").replace("Human:", ""),
                #             is_user=is_user)
            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)
    else:
        c2 = st.container()
        c2.title("JobGPT: A Job Description Fixing Chatbot")
        c2.markdown(
            "JobGPT is a chatbot that fixes job descriptions. This is built just for demo purpose."
        )
        input_text = c2.text_area(
            "Prompt",
            "Hi, can you please help me fix my job description? It's biased.")
        button = c2.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
        c2.markdown("---")

        initial_message = "Hello, how can I help you?"
        message(initial_message)

        if button:
            messages = []
            current_message = ""
            current_is_user = True
            #clear prompt textbox
            response = fix_job_description(
                input_text, st.session_state['fixer_conversation'])
            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
                    # message(historical_message.replace("Human:", ""),
                    #         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
                # if message_to_send != "":
                #     message(message_to_send.replace("JobGPT:",
                #                                     "").replace("Human:", ""),
                #             is_user=is_user)
            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)


main()