Spaces:
Sleeping
Sleeping
removed too much, adapt
Browse files
app.py
CHANGED
@@ -35,20 +35,23 @@ def compute_embeddings(problems):
|
|
35 |
"""Compute sentence embeddings."""
|
36 |
return model.encode(problems, normalize_embeddings=True)
|
37 |
|
38 |
-
|
39 |
-
|
40 |
def find_similar_problems(df, similarity_threshold=0.9):
|
41 |
-
"""Find similar problems using cosine similarity, optimized
|
42 |
|
43 |
-
|
44 |
-
|
|
|
|
|
45 |
start_time = time.time()
|
46 |
embeddings = compute_embeddings(df['problem'].tolist())
|
47 |
-
|
48 |
-
|
|
|
49 |
similarity_matrix = util.cos_sim(embeddings, embeddings).numpy()
|
50 |
|
51 |
-
|
|
|
|
|
52 |
num_problems = len(df)
|
53 |
upper_triangle_indices = np.triu_indices(num_problems, k=1)
|
54 |
|
@@ -67,7 +70,9 @@ def find_similar_problems(df, similarity_threshold=0.9):
|
|
67 |
|
68 |
sorted_pairs = sorted(pairs, key=lambda x: x[2], reverse=True)
|
69 |
|
70 |
-
|
|
|
|
|
71 |
st.success(f"β
Analysis complete! Found {len(sorted_pairs)} similar problems in {time.time() - start_time:.2f}s", icon="π")
|
72 |
|
73 |
return sorted_pairs
|
|
|
35 |
"""Compute sentence embeddings."""
|
36 |
return model.encode(problems, normalize_embeddings=True)
|
37 |
|
|
|
|
|
38 |
def find_similar_problems(df, similarity_threshold=0.9):
|
39 |
+
"""Find similar problems using cosine similarity, optimized with clear UI updates."""
|
40 |
|
41 |
+
status_msgs = []
|
42 |
+
|
43 |
+
msg = st.status("π Computing problem embeddings...")
|
44 |
+
status_msgs.append(msg)
|
45 |
start_time = time.time()
|
46 |
embeddings = compute_embeddings(df['problem'].tolist())
|
47 |
+
|
48 |
+
msg = st.status("π Computing cosine similarity matrix...")
|
49 |
+
status_msgs.append(msg)
|
50 |
similarity_matrix = util.cos_sim(embeddings, embeddings).numpy()
|
51 |
|
52 |
+
msg = st.status("π Filtering similar problems...")
|
53 |
+
status_msgs.append(msg)
|
54 |
+
|
55 |
num_problems = len(df)
|
56 |
upper_triangle_indices = np.triu_indices(num_problems, k=1)
|
57 |
|
|
|
70 |
|
71 |
sorted_pairs = sorted(pairs, key=lambda x: x[2], reverse=True)
|
72 |
|
73 |
+
for msg in status_msgs:
|
74 |
+
msg.empty()
|
75 |
+
|
76 |
st.success(f"β
Analysis complete! Found {len(sorted_pairs)} similar problems in {time.time() - start_time:.2f}s", icon="π")
|
77 |
|
78 |
return sorted_pairs
|