Spaces:
Runtime error
Runtime error
Elvan Selvano
commited on
Commit
·
9ab4f02
1
Parent(s):
02757a2
Upload app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,15 @@
|
|
1 |
import pandas as pd
|
2 |
-
import os
|
3 |
-
import pickle
|
4 |
from sentence_transformers import SentenceTransformer, util
|
5 |
import streamlit as st
|
6 |
-
import
|
7 |
-
import
|
|
|
8 |
|
9 |
@st.cache(allow_output_mutation=True)
|
10 |
def load_model():
|
11 |
-
return SentenceTransformer('
|
12 |
|
13 |
def find_top_similar(sentence, corpus_sentences, corpus_embeddings):
|
14 |
-
|
15 |
# preprocess query
|
16 |
model = load_model()
|
17 |
query_embeddings = model.encode(sentence, convert_to_tensor=True) # encode to tensor
|
@@ -49,16 +47,6 @@ def get_result(df, query, corpus_sentences, corpus_embeddings):
|
|
49 |
result.drop_duplicates(inplace=True)
|
50 |
return result
|
51 |
|
52 |
-
class cpu_unpickler(pickle.Unpickler):
|
53 |
-
"""
|
54 |
-
Overrides the default behavior of the `Unpickler` class to load
|
55 |
-
a `torch.storage` object from abyte string
|
56 |
-
"""
|
57 |
-
def find_class(self, module, name):
|
58 |
-
if module == 'torch.storage' and name == '_load_from_bytes':
|
59 |
-
return lambda b: torch.load(io.BytesIO(b), map_location='cpu')
|
60 |
-
return super().find_class(module, name)
|
61 |
-
|
62 |
@st.cache(allow_output_mutation=True)
|
63 |
def load_embedding():
|
64 |
"""Loads the embeddings from the pickle file"""
|
@@ -74,7 +62,6 @@ def main():
|
|
74 |
sheet_id = '1KeuPPVw9gueNmMrQXk1uGFlY9H1vvhErMLiX_ZVRv_Y'
|
75 |
sheet_name = 'Form Response 3'.replace(' ', '%20')
|
76 |
url = f'https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}'
|
77 |
-
print(url)
|
78 |
df = pd.read_csv(url)
|
79 |
df = df.iloc[: , :7]
|
80 |
|
@@ -87,10 +74,43 @@ def main():
|
|
87 |
submitted = st.button('Submit')
|
88 |
|
89 |
if submitted:
|
|
|
90 |
result = get_result(df, job_title, corpus_sentences, corpus_embeddings)
|
91 |
result.reset_index(drop=True, inplace=True)
|
92 |
result.index += 1
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
if __name__ == '__main__':
|
96 |
main()
|
|
|
1 |
import pandas as pd
|
|
|
|
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
import streamlit as st
|
4 |
+
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode
|
5 |
+
from cpu_unpickler import cpu_unpickler
|
6 |
+
st.set_page_config(layout='wide')
|
7 |
|
8 |
@st.cache(allow_output_mutation=True)
|
9 |
def load_model():
|
10 |
+
return SentenceTransformer('all-MiniLM-L6-v2')
|
11 |
|
12 |
def find_top_similar(sentence, corpus_sentences, corpus_embeddings):
|
|
|
13 |
# preprocess query
|
14 |
model = load_model()
|
15 |
query_embeddings = model.encode(sentence, convert_to_tensor=True) # encode to tensor
|
|
|
47 |
result.drop_duplicates(inplace=True)
|
48 |
return result
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
@st.cache(allow_output_mutation=True)
|
51 |
def load_embedding():
|
52 |
"""Loads the embeddings from the pickle file"""
|
|
|
62 |
sheet_id = '1KeuPPVw9gueNmMrQXk1uGFlY9H1vvhErMLiX_ZVRv_Y'
|
63 |
sheet_name = 'Form Response 3'.replace(' ', '%20')
|
64 |
url = f'https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}'
|
|
|
65 |
df = pd.read_csv(url)
|
66 |
df = df.iloc[: , :7]
|
67 |
|
|
|
74 |
submitted = st.button('Submit')
|
75 |
|
76 |
if submitted:
|
77 |
+
st.info(f'Showing results for { job_title}')
|
78 |
result = get_result(df, job_title, corpus_sentences, corpus_embeddings)
|
79 |
result.reset_index(drop=True, inplace=True)
|
80 |
result.index += 1
|
81 |
+
|
82 |
+
st.download_button(
|
83 |
+
"Press to Download",
|
84 |
+
result.to_csv().encode('utf-8'),
|
85 |
+
"result.csv",
|
86 |
+
"text/csv",
|
87 |
+
key='download-csv'
|
88 |
+
)
|
89 |
+
|
90 |
+
gb = GridOptionsBuilder.from_dataframe(result)
|
91 |
+
gb.configure_pagination(paginationAutoPageSize=True) # Add pagination
|
92 |
+
# gb.configure_side_bar() #Add a sidebar
|
93 |
+
# gb.configure_selection('multiple', use_checkbox=True, groupSelectsChildren="Group checkbox select children") #Enable multi-row selection
|
94 |
+
|
95 |
+
gb.configure_column("LinkedIn Link",
|
96 |
+
headerName="LinkedIn Link",
|
97 |
+
# cellRenderer=JsCode('''function(params) {return '<a href=params.value + '" target="_blank">'+ params.value+'</a>'}'''),
|
98 |
+
cellRenderer=JsCode('''function(params) {return `<a href=${params.value} target="_blank">${params.value}</a>`}'''),
|
99 |
+
width=300)
|
100 |
+
|
101 |
+
gridOptions = gb.build()
|
102 |
+
|
103 |
+
grid_response = AgGrid(
|
104 |
+
dataframe=result,
|
105 |
+
gridOptions=gridOptions,
|
106 |
+
height=1100,
|
107 |
+
fit_columns_on_grid_load=True,
|
108 |
+
data_return_mode='AS_INPUT',
|
109 |
+
update_mode='VALUE_CHANGED',
|
110 |
+
theme='light',
|
111 |
+
enable_enterprise_modules=True,
|
112 |
+
allow_unsafe_jscode=True,
|
113 |
+
)
|
114 |
|
115 |
if __name__ == '__main__':
|
116 |
main()
|