Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -556,8 +556,8 @@ async def chat_endpoint(chat_query: ChatQuery):
|
|
556 |
else:
|
557 |
print("Sorry, I can't help with that.")
|
558 |
return {
|
559 |
-
"response": final_answer,
|
560 |
-
#"conversation_id": chat_query.conversation_id,
|
561 |
"success": True
|
562 |
}
|
563 |
except Exception as e:
|
@@ -629,20 +629,9 @@ async def recipes_endpoint(profile: MedicalProfile):
|
|
629 |
print("Document indices:", document_indices)
|
630 |
metadata_path = 'recipes_metadata.xlsx'
|
631 |
metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
|
632 |
-
print(f"Retrieved Metadata: {metadata}")
|
633 |
-
recipes = metadata
|
634 |
-
document_texts = retrieve_rec_texts(document_indices, folder_path)
|
635 |
-
if not document_texts:
|
636 |
-
raise ValueError("Failed to retrieve document texts.")
|
637 |
-
cross_encoder = models['cross_encoder']
|
638 |
-
scores = cross_encoder.predict([(query_text, doc) for doc in document_texts])
|
639 |
-
scores = [float(score) for score in scores]
|
640 |
-
for i, recipe in enumerate(recipes):
|
641 |
-
recipe["score"] = scores[i] if i < len(scores) else 0.0
|
642 |
-
recipes.sort(key=lambda x: x["score"], reverse=True)
|
643 |
-
return {"recipes": recipes, "success": True}
|
644 |
response = {
|
645 |
-
"recipes":
|
646 |
}
|
647 |
return response
|
648 |
except ValueError as ve:
|
|
|
556 |
else:
|
557 |
print("Sorry, I can't help with that.")
|
558 |
return {
|
559 |
+
"response": f"I hope this answers your question: {final_answer}",
|
560 |
+
# "conversation_id": chat_query.conversation_id,
|
561 |
"success": True
|
562 |
}
|
563 |
except Exception as e:
|
|
|
629 |
print("Document indices:", document_indices)
|
630 |
metadata_path = 'recipes_metadata.xlsx'
|
631 |
metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
|
632 |
+
print(f"Retrieved Metadata: {metadata}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
response = {
|
634 |
+
"recipes": metadata
|
635 |
}
|
636 |
return response
|
637 |
except ValueError as ve:
|