Spaces:
Build error
Build error
Commit ·
4aca022
1
Parent(s): 8feb650
fix translation
Browse files- src/app.py +2 -4
- src/handler.py +8 -16
src/app.py
CHANGED
|
@@ -218,8 +218,6 @@ if selected == "Chatbot":
|
|
| 218 |
query = st.chat_input("Ask your question here... (Example: How to apply for KITAS?)")
|
| 219 |
|
| 220 |
if query:
|
| 221 |
-
# lang = detect(query)
|
| 222 |
-
|
| 223 |
is_feedback = check_question_feedback(query, "anonymous")
|
| 224 |
|
| 225 |
if is_feedback['is_feedback']:
|
|
@@ -228,11 +226,11 @@ if selected == "Chatbot":
|
|
| 228 |
|
| 229 |
if not last_question:
|
| 230 |
resp = "Sorry, you have not asked a question, or the session has been reset. Please ask a question first before providing feedback."
|
| 231 |
-
|
| 232 |
st.session_state.messages.append({
|
| 233 |
"role": "assistant",
|
| 234 |
"type": "warning",
|
| 235 |
-
"content":
|
| 236 |
})
|
| 237 |
st.rerun()
|
| 238 |
else:
|
|
|
|
| 218 |
query = st.chat_input("Ask your question here... (Example: How to apply for KITAS?)")
|
| 219 |
|
| 220 |
if query:
|
|
|
|
|
|
|
| 221 |
is_feedback = check_question_feedback(query, "anonymous")
|
| 222 |
|
| 223 |
if is_feedback['is_feedback']:
|
|
|
|
| 226 |
|
| 227 |
if not last_question:
|
| 228 |
resp = "Sorry, you have not asked a question, or the session has been reset. Please ask a question first before providing feedback."
|
| 229 |
+
mssg = translate_answer(query, resp)
|
| 230 |
st.session_state.messages.append({
|
| 231 |
"role": "assistant",
|
| 232 |
"type": "warning",
|
| 233 |
+
"content": mssg
|
| 234 |
})
|
| 235 |
st.rerun()
|
| 236 |
else:
|
src/handler.py
CHANGED
|
@@ -48,39 +48,31 @@ def normalize(text):
|
|
| 48 |
|
| 49 |
def is_feedback_message(text: str) -> bool:
|
| 50 |
cleaned = normalize(text)
|
| 51 |
-
|
| 52 |
-
return any(cleaned.startswith(keyword) for keyword in all_feedback_keywords)
|
| 53 |
|
| 54 |
def check_question_feedback(query, user_id="anonymous"):
|
| 55 |
-
lang = detect(query)
|
| 56 |
-
if lang != "en" and lang != "id":
|
| 57 |
-
question = translate_answer('en', query)
|
| 58 |
-
else:
|
| 59 |
-
question = query
|
| 60 |
-
|
| 61 |
feedback_obj = None
|
| 62 |
last_qna = {"question": None, "answer": None}
|
| 63 |
|
| 64 |
-
if is_feedback_message(
|
| 65 |
-
feedback_obj = extract_feedback_content(
|
| 66 |
last_qna = {
|
| 67 |
"question": get_last_question(user_id),
|
| 68 |
"answer": get_last_answer(user_id),
|
| 69 |
}
|
| 70 |
-
return {"is_feedback": True, "query":
|
| 71 |
else:
|
| 72 |
-
return {"is_feedback": False, "query":
|
| 73 |
|
| 74 |
def extract_feedback_content(raw_message: str) -> dict:
|
| 75 |
cleaned = normalize(raw_message)
|
| 76 |
|
| 77 |
-
feedback = GoogleTranslator(source='auto', target='en').translate(cleaned) if detect(cleaned) != 'en' else cleaned
|
| 78 |
for keyword in FEEDBACK_KEYWORDS:
|
| 79 |
-
if
|
| 80 |
-
remaining =
|
| 81 |
return {"feedback": keyword, "comment": remaining}
|
| 82 |
|
| 83 |
-
return {"feedback": None, "comment":
|
| 84 |
|
| 85 |
def save_feedback(feedback_obj: dict, last_qna: dict) -> str:
|
| 86 |
feedback_data = {
|
|
|
|
| 48 |
|
| 49 |
def is_feedback_message(text: str) -> bool:
|
| 50 |
cleaned = normalize(text)
|
| 51 |
+
return any(cleaned.startswith(keyword) for keyword in FEEDBACK_KEYWORDS)
|
|
|
|
| 52 |
|
| 53 |
def check_question_feedback(query, user_id="anonymous"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
feedback_obj = None
|
| 55 |
last_qna = {"question": None, "answer": None}
|
| 56 |
|
| 57 |
+
if is_feedback_message(query):
|
| 58 |
+
feedback_obj = extract_feedback_content(query)
|
| 59 |
last_qna = {
|
| 60 |
"question": get_last_question(user_id),
|
| 61 |
"answer": get_last_answer(user_id),
|
| 62 |
}
|
| 63 |
+
return {"is_feedback": True, "query": query, "feedback_obj": feedback_obj, "last_qna": last_qna}
|
| 64 |
else:
|
| 65 |
+
return {"is_feedback": False, "query": query, "feedback_obj": feedback_obj, "last_qna": last_qna}
|
| 66 |
|
| 67 |
def extract_feedback_content(raw_message: str) -> dict:
|
| 68 |
cleaned = normalize(raw_message)
|
| 69 |
|
|
|
|
| 70 |
for keyword in FEEDBACK_KEYWORDS:
|
| 71 |
+
if cleaned.startswith(keyword):
|
| 72 |
+
remaining = cleaned[len(keyword):].strip()
|
| 73 |
return {"feedback": keyword, "comment": remaining}
|
| 74 |
|
| 75 |
+
return {"feedback": None, "comment": cleaned}
|
| 76 |
|
| 77 |
def save_feedback(feedback_obj: dict, last_qna: dict) -> str:
|
| 78 |
feedback_data = {
|