Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -97,10 +97,7 @@ def refine_answer(question, retrieved_answer):
|
|
| 97 |
system_content = "You are an assistant that refines answers to make them more relevant and natural."
|
| 98 |
return llama_query(prompt, system_content)
|
| 99 |
|
| 100 |
-
def get_answer(user_question, threshold=0.
|
| 101 |
-
if not check_blood_donation_relevance(user_question):
|
| 102 |
-
return "I'm sorry, but your question doesn't seem to be related to blood donation. Could you please ask a question about blood donation?", 0
|
| 103 |
-
|
| 104 |
language = detect_language(user_question)
|
| 105 |
|
| 106 |
if language == 'swahili':
|
|
@@ -119,10 +116,20 @@ def get_answer(user_question, threshold=0.01):
|
|
| 119 |
|
| 120 |
return refined_answer, final_score
|
| 121 |
else:
|
| 122 |
-
|
| 123 |
-
if
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
# Gradio app
|
| 128 |
def gradio_app(user_question):
|
|
|
|
| 97 |
system_content = "You are an assistant that refines answers to make them more relevant and natural."
|
| 98 |
return llama_query(prompt, system_content)
|
| 99 |
|
| 100 |
+
def get_answer(user_question, threshold=0.3):
|
|
|
|
|
|
|
|
|
|
| 101 |
language = detect_language(user_question)
|
| 102 |
|
| 103 |
if language == 'swahili':
|
|
|
|
| 116 |
|
| 117 |
return refined_answer, final_score
|
| 118 |
else:
|
| 119 |
+
# Use LLaMa to determine if the question is related to blood donation
|
| 120 |
+
if check_blood_donation_relevance(english_question):
|
| 121 |
+
llama_response = llama_query(
|
| 122 |
+
f"Please provide a brief, general answer to this blood donation related question: {english_question}",
|
| 123 |
+
"You are an assistant knowledgeable about blood donation. Provide brief, accurate answers."
|
| 124 |
+
)
|
| 125 |
+
if language == 'swahili':
|
| 126 |
+
llama_response = translate_to_swahili(llama_response)
|
| 127 |
+
return llama_response, 0
|
| 128 |
+
else:
|
| 129 |
+
off_topic_message = "I'm sorry, but your question doesn't seem to be related to blood donation. Could you please ask a question about blood donation?"
|
| 130 |
+
if language == 'swahili':
|
| 131 |
+
off_topic_message = translate_to_swahili(off_topic_message)
|
| 132 |
+
return off_topic_message, 0
|
| 133 |
|
| 134 |
# Gradio app
|
| 135 |
def gradio_app(user_question):
|