Spaces:
Runtime error
Runtime error
Kuaaangwen
commited on
Commit
•
411304b
1
Parent(s):
d66b3f7
Update app.py
Browse files
app.py
CHANGED
@@ -72,38 +72,40 @@ if sidebar_selectbox == "Bulk upload and mark":
|
|
72 |
data_file = st.file_uploader("Upload CSV",type=["csv"])
|
73 |
|
74 |
if data_file is not None:
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
# Get length of df.shape (might not need this)
|
80 |
-
#total_rows = df.shape[0]
|
81 |
-
|
82 |
-
similarity_scores = []
|
83 |
-
|
84 |
-
for idx, row in df.iterrows():
|
85 |
-
# st.write(idx, row['Sentences'])
|
86 |
|
87 |
-
#
|
88 |
-
|
89 |
|
90 |
-
|
91 |
-
sentence_comparison = row['Sentences']
|
92 |
-
sentences.append(sentence_reference)
|
93 |
-
sentences.append(sentence_comparison)
|
94 |
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
|
98 |
-
cos_sim = round(cos_sim * 100)
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
df['Similarity (%)'] = similarity_scores
|
105 |
-
|
106 |
-
st.dataframe(df)
|
107 |
|
108 |
@st.cache
|
109 |
def convert_df(df):
|
|
|
72 |
data_file = st.file_uploader("Upload CSV",type=["csv"])
|
73 |
|
74 |
if data_file is not None:
|
75 |
+
with st.spinner('Wait for it...'):
|
76 |
+
file_details = {"filename":data_file.name, "filetype":data_file.type, "filesize":data_file.size}
|
77 |
+
# st.write(file_details)
|
78 |
+
df = pd.read_csv(data_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
# Get length of df.shape (might not need this)
|
81 |
+
#total_rows = df.shape[0]
|
82 |
|
83 |
+
similarity_scores = []
|
|
|
|
|
|
|
84 |
|
85 |
+
for idx, row in df.iterrows():
|
86 |
+
# st.write(idx, row['Sentences'])
|
87 |
+
|
88 |
+
# Create an empty sentence list
|
89 |
+
sentences = []
|
90 |
+
|
91 |
+
# Compare the setences two by two
|
92 |
+
sentence_comparison = row['Sentences']
|
93 |
+
sentences.append(sentence_reference)
|
94 |
+
sentences.append(sentence_comparison)
|
95 |
+
|
96 |
+
sentence_embeddings = model.encode(sentences)
|
97 |
+
|
98 |
+
cos_sim = cosine_similarity(sentence_embeddings[0].reshape(1, -1), sentence_embeddings[1].reshape(1, -1))[0][0]
|
99 |
+
cos_sim = round(cos_sim * 100)
|
100 |
+
|
101 |
+
similarity_scores.append(cos_sim)
|
102 |
|
103 |
+
# Append new column to dataframe
|
|
|
104 |
|
105 |
+
df['Similarity (%)'] = similarity_scores
|
106 |
+
|
107 |
+
st.dataframe(df)
|
108 |
+
st.success('Done!')
|
|
|
|
|
|
|
109 |
|
110 |
@st.cache
|
111 |
def convert_df(df):
|