Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,8 @@
|
|
| 1 |
-
# app.py
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
from models.sea_llm import generate_answer
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def laos_history_bot(message: str, history: list):
|
| 10 |
-
"""
|
| 11 |
-
Main chat function for Gradio.
|
| 12 |
-
1) Try to answer from QA pairs (instant).
|
| 13 |
-
2) If not found, call the model with RAG.
|
| 14 |
-
"""
|
| 15 |
-
if not message.strip():
|
| 16 |
-
return "ກະລຸນາພິມຄຳຖາມກ່ອນ."
|
| 17 |
-
|
| 18 |
-
# 1) direct QA lookup (fast)
|
| 19 |
-
direct = answer_from_qa(message)
|
| 20 |
-
if direct:
|
| 21 |
-
return direct
|
| 22 |
-
|
| 23 |
-
# 2) fallback: model + retrieval
|
| 24 |
-
try:
|
| 25 |
-
answer = generate_answer(message)
|
| 26 |
-
except Exception as e:
|
| 27 |
-
return f"ລະບົບມີບັນຫາ: {e}"
|
| 28 |
-
|
| 29 |
-
return answer
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
demo = gr.ChatInterface(
|
| 33 |
-
fn=laos_history_bot,
|
| 34 |
-
title="Laos History Chatbot (Lao language)",
|
| 35 |
-
description="ຖາມຂໍ້ມູນກ່ຽວກັບປະຫວັດສາດຂອງປະເທດລາວ (ສໍາລັບນັກຮຽນ ມ.1)",
|
| 36 |
-
examples=[
|
| 37 |
-
"ປະຫວັດສາດແມ່ນຫຍັງ?",
|
| 38 |
-
"ຄວາມສໍາຄັນຂອງການຮຽນປະຫວັດສາດແມ່ນຫຍັງ?",
|
| 39 |
-
"ຫຼັກຖານປະຫວັດສາດມີຫຍັງແດ່?",
|
| 40 |
-
],
|
| 41 |
-
)
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
demo.launch()
|
|
|
|
| 1 |
+
# app.py – entrypoint for Hugging Face Space
|
| 2 |
|
| 3 |
+
from ui import create_app
|
| 4 |
|
| 5 |
+
demo = create_app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
if __name__ == "__main__":
|
| 8 |
demo.launch()
|