File size: 7,825 Bytes
7aaad1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1fc5e8
7aaad1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
from utlis.helper import *
import sqlite3
import hashlib
import io



initialize_session_state()

with st.sidebar:
    st.image("logo.png", width=170)
    st.title("Config Settings")
    # Get List of models
   
    st.session_state.genre = st.radio(
    "Choose option",
    [ "Select Service", "Add service"])#,"Delete service"])
    
    if st.session_state.genre=="Add service":
        st.session_state.results_str=False
        st.title('Add service')
        # Check service status
        # Get all available services
        add_new_service = st.checkbox("Add new service")
        if add_new_service:
            new_service = st.text_input("Enter service name")
            # Get list of Embedding models
            
            if  new_service and st.button('Add'):
                add_service(st.session_state.token,new_service)
        data = {"token": st.session_state.token}
        json_data = json.dumps(data)
        headers = {'Content-Type': 'application/json'}
        services  = requests.get(SERVICES_API,data=json_data, headers=headers)
        services =json.loads(services.text)
        if len(services)>0:
            st.session_state.service = st.selectbox("Choose Service",services)

            st.session_state.uploaded_files = st.file_uploader("Upload CVs",  type=["pdf","doc"], accept_multiple_files=True)
            if st.session_state.uploaded_files:
                st.session_state.process = st.button('Process')
                if st.session_state.process:
                    with st.spinner("Processing..."):
                        add_document(st.session_state.token,st.session_state.service)

    elif st.session_state.genre=="Select Service":
        st.title('Choose Service')
        data = {"token": st.session_state.token}
        json_data = json.dumps(data)
        headers = {'Content-Type': 'application/json'}
        services  = requests.get(SERVICES_API,data=json_data, headers=headers)
        services =json.loads(services.text)

        if len(services)>0:
            st.session_state.service_slected_to_chat = st.selectbox(" ",services)
            st.session_state.top_k=st.slider("Number of Candidates", min_value=1, max_value=10, value=3, step=1)
            # data = {"token": st.session_state.token, "servicename": st.session_state.service_slected_to_chat}
            # json_data = json.dumps(data)
            # headers = {'Content-Type': 'application/json'}
            # history_document  = requests.get(DOCUMENT_API,data=json_data, headers=headers)
            # history_document =json.loads(history_document.text).get("documents",[])
            # history_document = [doc["documentname"] for doc in history_document]
            

            
    # elif st.session_state.genre == "Delete service":
    #     st.title('Delete Service')
    #     data = {"token": st.session_state.token}
    #     json_data = json.dumps(data)
    #     headers = {'Content-Type': 'application/json'}
    #     services  = requests.get(SERVICES_API,data=json_data, headers=headers)
    #     services =json.loads(services.text)
    #     if len(services)>=2:
    #         services.append("ALL")
    #         # Get list of documents from histrory
    #     if "ALL" in services:
    #         service_slected = st.multiselect(
    #                 "",services ,default="ALL"
    #                 )
    #     elif len(services)==1:
    #         service_slected = st.multiselect(
    #                 "",services,default=services[0]
    #                 )
    #     else:
    #         service_slected = st.multiselect(
    #                 "",services
    #                 )
    #     if "ALL" in service_slected:
    #         service_slected = services
    #         service_slected.remove("ALL")
    #     st.write("You selected:", service_slected)

    #     if len(service_slected) > 0:
    #         st.session_state.delete = st.button('Delete')
    #         if st.session_state.delete:
    #             delete_service(st.session_state.token ,service_slected)
        
    # elif st.session_state.genre == "Delete CV(s)":
    #     st.title('Delete CV(s)')
    #     data = {"token": st.session_state.token}
    #     json_data = json.dumps(data)
    #     headers = {'Content-Type': 'application/json'}
    #     services  = requests.get(SERVICES_API,data=json_data, headers=headers)
    #     services =json.loads(services.text)
    #     if len(services)>0:
    #         service = st.selectbox("Choose Service",services)
    #         data = {"token": st.session_state.token, "servicename": service}
    #         json_data = json.dumps(data)
    #         headers = {'Content-Type': 'application/json'}
        

    #         st.write("You selected:", document_slected_to_delete)
    #         if len(document_slected_to_delete) > 0:
    #             st.session_state.delete = st.button('Delete')
    #             if st.session_state.delete:
    #                 delete_document(st.session_state.token,st.session_state.service ,document_slected_to_delete)

# css_style = """
# <style>
# .title {
#     white-space: nowrap;
# }
# </style>
# """

# st.markdown(css_style, unsafe_allow_html=True)
st.markdown("""
    <style>
    .st-bm {
        color: #1E90FF; /* DodgerBlue color */
    }
            .card {
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 15px;
    margin: 10px 0;
    transition: box-shadow 0.3s ease-in-out;
}
.card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.highlight {
    color:  #1E90FF; /* Custom color */
}
    </style>
    """, unsafe_allow_html=True)

with st.container():
    st.markdown('<h1 class="title">SmartHire Matcher</h1>', unsafe_allow_html=True)
    col1, col2 = st.columns([3, 1])
    if st.session_state.genre=="Select Service" and st.session_state.service_slected_to_chat:
        query = st.text_area("Add description of your offer:", height=300)
        
        if query and st.button('Process') :
            with st.spinner("Finding Matching CVs..."):
                results = search_document( index_name= "cvindex",token= "abcd",service_name= st.session_state.service_slected_to_chat,query= query,top_k= st.session_state.top_k)
                st.session_state.results_str = results.decode('utf-8')

            # Displaying results
        try:
            if st.session_state.results_str:  # check if there are results
                results = json.loads(st.session_state.results_str)

                for index, item in enumerate(results):
                    with st.container():
                        col1, col2 = st.columns([3, 1])
                        with col1:
                            st.markdown(f"<div class='card'><h3><span class='highlight'>Top:</span> {index+1}</h3><p><span class='highlight'>Score:</span> {round(item['score']*100, 3)}%</p><p><span class='highlight'>Document Name:</span> {item['documentname'].replace('_pdf', ' ')}</p></div>", unsafe_allow_html=True)

                            #st.markdown(f"**Tag:** {item['tag']}")
                            #st.markdown(f"**Score:** {round(item['score'], 3)}")
                            #st.markdown(f"**Document Name:** {item['documentname'].replace('_pdf', ' ')}")
                        with col2:
                            b64_pdf = item['encoded_cv']
                            pdf = base64.b64decode(b64_pdf)
                            pdf_file = io.BytesIO(pdf)
                            st.download_button("Download CV", data=pdf_file, file_name=item['documentname'].replace('_', '.'), mime='application/pdf', key=f"download_{index}_{item['documentname']}")
                if not results:
                    st.error("No results found.")
        except Exception as e:
            st.error("Failed to load results. Please try again later."+ str(e))