Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,11 @@ def encode_text(text):
|
|
18 |
def find_best_response(user_input, response_pool):
|
19 |
user_embedding = encode_text(user_input)
|
20 |
response_embeddings = np.array([encode_text(resp) for resp in response_pool])
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
similarities = cosine_similarity(user_embedding, response_embeddings).flatten()
|
23 |
best_response_index = np.argmax(similarities)
|
24 |
return response_pool[best_response_index]
|
@@ -48,3 +52,4 @@ iface = gr.Interface(
|
|
48 |
# Launch the interface
|
49 |
iface.launch()
|
50 |
|
|
|
|
18 |
def find_best_response(user_input, response_pool):
|
19 |
user_embedding = encode_text(user_input)
|
20 |
response_embeddings = np.array([encode_text(resp) for resp in response_pool])
|
21 |
+
|
22 |
+
# Ensure response_embeddings are 2D
|
23 |
+
if response_embeddings.ndim == 3:
|
24 |
+
response_embeddings = response_embeddings.squeeze(axis=1)
|
25 |
+
|
26 |
similarities = cosine_similarity(user_embedding, response_embeddings).flatten()
|
27 |
best_response_index = np.argmax(similarities)
|
28 |
return response_pool[best_response_index]
|
|
|
52 |
# Launch the interface
|
53 |
iface.launch()
|
54 |
|
55 |
+
|