Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -111,7 +111,15 @@ class SearchEngine:
|
|
111 |
"""
|
112 |
query_embedding = self.model.encode(query, convert_to_tensor=True)
|
113 |
distances, indices = self.index.search(query_embedding.cpu().detach().numpy().reshape(1, -1), top_k)
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
|
117 |
# Conversational Model using GPT-2
|
@@ -228,8 +236,11 @@ async def search(request: QueryRequest):
|
|
228 |
if not query:
|
229 |
raise HTTPException(status_code=400, detail="No query provided")
|
230 |
|
231 |
-
|
232 |
-
|
|
|
|
|
|
|
233 |
|
234 |
|
235 |
@app.post("/topics")
|
|
|
111 |
"""
|
112 |
query_embedding = self.model.encode(query, convert_to_tensor=True)
|
113 |
distances, indices = self.index.search(query_embedding.cpu().detach().numpy().reshape(1, -1), top_k)
|
114 |
+
|
115 |
+
# Convert NumPy data types to native Python types
|
116 |
+
results = []
|
117 |
+
for i in indices[0]:
|
118 |
+
document = self.documents[i]
|
119 |
+
distance = float(distances[0][i]) # Convert numpy.float32 to float
|
120 |
+
results.append({"document": document, "distance": distance})
|
121 |
+
|
122 |
+
return results
|
123 |
|
124 |
|
125 |
# Conversational Model using GPT-2
|
|
|
236 |
if not query:
|
237 |
raise HTTPException(status_code=400, detail="No query provided")
|
238 |
|
239 |
+
try:
|
240 |
+
results = search_engine.search(query)
|
241 |
+
return {"results": results}
|
242 |
+
except Exception as e:
|
243 |
+
raise HTTPException(status_code=500, detail=str(e))
|
244 |
|
245 |
|
246 |
@app.post("/topics")
|