Spaces:
Runtime error
Runtime error
Commit ·
01668e5
1
Parent(s): 7af92a3
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ def embed_data(data):
|
|
| 24 |
return model.encode(data)
|
| 25 |
|
| 26 |
|
| 27 |
-
def process_data(df, desc, message, embed=False):
|
| 28 |
data = [
|
| 29 |
[
|
| 30 |
f'Represent the document for retrieval of {x[desc]} information : ',
|
|
@@ -37,16 +37,17 @@ def process_data(df, desc, message, embed=False):
|
|
| 37 |
if embed :
|
| 38 |
corpus_embeddings = embed_data(data)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
with st.spinner('Wait for it...'):
|
| 45 |
-
similarities = cosine_similarity(query_embeddings,corpus_embeddings)
|
| 46 |
-
retrieved_doc_id = np.argmax(similarities)
|
| 47 |
-
st.markdown(f"{data[retrieved_doc_id][-1]}",unsafe_allow_html=True)
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# btn_q = st.button("Submit", key="submit_query")
|
| 51 |
|
| 52 |
# if btn_q :
|
|
@@ -67,6 +68,7 @@ if opt == "intent.csv":
|
|
| 67 |
process_data(df, desc='description', message='message', embed=True)
|
| 68 |
|
| 69 |
else :
|
|
|
|
| 70 |
f = st.file_uploader("Upload CSV File with at least 2 columns", ['xlsx', 'csv'])
|
| 71 |
delim = st.text_input('CSV File Delimiter')
|
| 72 |
btn = st.button("Submit", key="submit_first")
|
|
@@ -80,15 +82,20 @@ else :
|
|
| 80 |
st.write("FAILED! At least 2 columns needed. Please check your dataset")
|
| 81 |
else :
|
| 82 |
st.session_state.query_bool = True
|
|
|
|
| 83 |
|
| 84 |
if st.session_state.query_bool:
|
| 85 |
with st.form("my_form"):
|
| 86 |
cols = list(st.session_state.df.columns)
|
| 87 |
desc = st.radio("Description Column (e.g. description)", cols)
|
| 88 |
message = st.radio("Response Template Column (e.g. message)", cols)
|
|
|
|
| 89 |
submitted = st.form_submit_button("submit")
|
|
|
|
| 90 |
if submitted:
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
|
|
|
|
| 24 |
return model.encode(data)
|
| 25 |
|
| 26 |
|
| 27 |
+
def process_data(df, desc, message, query, embed=False):
|
| 28 |
data = [
|
| 29 |
[
|
| 30 |
f'Represent the document for retrieval of {x[desc]} information : ',
|
|
|
|
| 37 |
if embed :
|
| 38 |
corpus_embeddings = embed_data(data)
|
| 39 |
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
query_embeddings = model.encode(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
with st.spinner('Wait for it...'):
|
| 45 |
+
similarities = cosine_similarity(query_embeddings,corpus_embeddings)
|
| 46 |
+
retrieved_doc_id = np.argmax(similarities)
|
| 47 |
+
st.markdown(f"{data[retrieved_doc_id][-1]}",unsafe_allow_html=True)
|
| 48 |
+
|
| 49 |
+
# question = st.text_input("Question (Press Enter to query) :")
|
| 50 |
+
# query = [['Represent the question for retrieving supporting documents: ',question]]
|
| 51 |
# btn_q = st.button("Submit", key="submit_query")
|
| 52 |
|
| 53 |
# if btn_q :
|
|
|
|
| 68 |
process_data(df, desc='description', message='message', embed=True)
|
| 69 |
|
| 70 |
else :
|
| 71 |
+
embed = False
|
| 72 |
f = st.file_uploader("Upload CSV File with at least 2 columns", ['xlsx', 'csv'])
|
| 73 |
delim = st.text_input('CSV File Delimiter')
|
| 74 |
btn = st.button("Submit", key="submit_first")
|
|
|
|
| 82 |
st.write("FAILED! At least 2 columns needed. Please check your dataset")
|
| 83 |
else :
|
| 84 |
st.session_state.query_bool = True
|
| 85 |
+
embed=True
|
| 86 |
|
| 87 |
if st.session_state.query_bool:
|
| 88 |
with st.form("my_form"):
|
| 89 |
cols = list(st.session_state.df.columns)
|
| 90 |
desc = st.radio("Description Column (e.g. description)", cols)
|
| 91 |
message = st.radio("Response Template Column (e.g. message)", cols)
|
| 92 |
+
question = st.text_input("Question (Press Enter to query) :")
|
| 93 |
submitted = st.form_submit_button("submit")
|
| 94 |
+
|
| 95 |
if submitted:
|
| 96 |
+
query = [['Represent the question for retrieving supporting documents: ',question]]
|
| 97 |
+
process_data(st.session_state.df, desc, message, query, embed=embed)
|
| 98 |
+
embed=False
|
| 99 |
|
| 100 |
|
| 101 |
|