Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
app.py
CHANGED
|
@@ -84,8 +84,8 @@ def start_conversation() -> str:
|
|
| 84 |
"""
|
| 85 |
return str(uuid.uuid4()) # Limitation nb users Langfuse Hobby
|
| 86 |
|
| 87 |
-
def on_clear() -> tuple[str, list, str, str]:
|
| 88 |
-
return "", [], "", ""
|
| 89 |
|
| 90 |
def get_faq() -> str:
|
| 91 |
logger.info("🔍 Retrieving FAQ list")
|
|
@@ -143,14 +143,22 @@ def get_answer(
|
|
| 143 |
# Reconvertir le dict en objet AnswerOutput
|
| 144 |
answer_output = AnswerOutput(**dict_resp)
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
similarity = np.round(answer_output.similarity_score, 3)
|
| 147 |
cross_encoder_score = np.round(answer_output.cross_encoder_score, 3) if answer_output.cross_encoder_score is not None else None
|
| 148 |
-
gap = get_gap(
|
| 149 |
answer = f"{answer_output.answer}\n(Similarity: {similarity}, \
|
| 150 |
Cross-Encoder: {f'{cross_encoder_score:.3f}' if cross_encoder_score is not None else 'N/A'}, \
|
| 151 |
Gap: {f'{gap:.3f}' if gap is not None else 'N/A'})"
|
| 152 |
|
| 153 |
-
info_candidates = list_candidates(
|
| 154 |
|
| 155 |
# ----- OBSERVATION UPDATE -----
|
| 156 |
try:
|
|
@@ -167,7 +175,7 @@ def get_answer(
|
|
| 167 |
"theme": answer_output.theme,
|
| 168 |
"similarity_threshold": str(similarity_threshold),
|
| 169 |
"top_k": str(top_k),
|
| 170 |
-
"candidates":
|
| 171 |
"retrieval_api_url": API_URL,
|
| 172 |
"embeddings_model_name": embeddings_model_name,
|
| 173 |
"cross_encoder_model_name": cross_encoder_model_name,
|
|
@@ -579,7 +587,8 @@ with gr.Blocks(title="FAQ Search", css=custom_css) as demo:
|
|
| 579 |
clear.click(
|
| 580 |
fn=on_clear,
|
| 581 |
inputs=None,
|
| 582 |
-
outputs=[sel_query, chatbot, feedback_status, feedback_comment
|
|
|
|
| 583 |
)
|
| 584 |
# Launch the Gradio app with queue support and debug mode
|
| 585 |
if __name__ == "__main__":
|
|
|
|
| 84 |
"""
|
| 85 |
return str(uuid.uuid4()) # Limitation nb users Langfuse Hobby
|
| 86 |
|
| 87 |
+
def on_clear() -> tuple[str, list, str, str, str, float, int, float]:
|
| 88 |
+
return "", [], "", "", "", SIMILARITY_THRESHOLD, TOP_K, CROSS_ENCODER_THRESHOLD
|
| 89 |
|
| 90 |
def get_faq() -> str:
|
| 91 |
logger.info("🔍 Retrieving FAQ list")
|
|
|
|
| 143 |
# Reconvertir le dict en objet AnswerOutput
|
| 144 |
answer_output = AnswerOutput(**dict_resp)
|
| 145 |
|
| 146 |
+
ranked_candidates = sorted(
|
| 147 |
+
answer_output.list_candidates,
|
| 148 |
+
key=lambda c: c.cross_encoder_score
|
| 149 |
+
if c.cross_encoder_score is not None
|
| 150 |
+
else float("-inf"),
|
| 151 |
+
reverse=True,
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
similarity = np.round(answer_output.similarity_score, 3)
|
| 155 |
cross_encoder_score = np.round(answer_output.cross_encoder_score, 3) if answer_output.cross_encoder_score is not None else None
|
| 156 |
+
gap = get_gap(ranked_candidates) if ranked_candidates else None
|
| 157 |
answer = f"{answer_output.answer}\n(Similarity: {similarity}, \
|
| 158 |
Cross-Encoder: {f'{cross_encoder_score:.3f}' if cross_encoder_score is not None else 'N/A'}, \
|
| 159 |
Gap: {f'{gap:.3f}' if gap is not None else 'N/A'})"
|
| 160 |
|
| 161 |
+
info_candidates = list_candidates(ranked_candidates) if ranked_candidates else "No candidates found."
|
| 162 |
|
| 163 |
# ----- OBSERVATION UPDATE -----
|
| 164 |
try:
|
|
|
|
| 175 |
"theme": answer_output.theme,
|
| 176 |
"similarity_threshold": str(similarity_threshold),
|
| 177 |
"top_k": str(top_k),
|
| 178 |
+
"candidates": ranked_candidates if ranked_candidates else [],
|
| 179 |
"retrieval_api_url": API_URL,
|
| 180 |
"embeddings_model_name": embeddings_model_name,
|
| 181 |
"cross_encoder_model_name": cross_encoder_model_name,
|
|
|
|
| 587 |
clear.click(
|
| 588 |
fn=on_clear,
|
| 589 |
inputs=None,
|
| 590 |
+
outputs=[sel_query, chatbot, feedback_status, feedback_comment, view_candidates,
|
| 591 |
+
similarity_threshold, top_k, cross_encoder_threshold]
|
| 592 |
)
|
| 593 |
# Launch the Gradio app with queue support and debug mode
|
| 594 |
if __name__ == "__main__":
|