Heng2004 commited on
Commit
ddc6400
·
verified ·
1 Parent(s): 86725d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -3
app.py CHANGED
@@ -1,8 +1,93 @@
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()
 
1
+ # app.py
2
+ import gradio as gr
3
 
4
+ from model_utils import laos_history_bot
5
+ from loader import manual_qa_table_data
6
+ from teacher_panel import (
7
+ teacher_save_add_overwrite,
8
+ teacher_update_current,
9
+ teacher_delete_current,
10
+ teacher_on_table_select,
11
+ )
12
 
13
+ # Build Gradio UI
14
+ with gr.Blocks() as demo:
15
+ gr.Markdown("## 🐘 Laos History Chatbot – ສໍາລັບນັກຮຽນ ມ.1")
16
+
17
+ # ---------------- Student tab ----------------
18
+ with gr.Tab("👩‍🎓 Student Chat"):
19
+ gr.Markdown("ຖາມຄໍາຖາມປະຫວັດສາດພາສາລາວໄດ້ເລີຍ.")
20
+ gr.ChatInterface(
21
+ fn=laos_history_bot,
22
+ title="",
23
+ description="",
24
+ examples=[
25
+ "ປະຫວັດສາດແມ່ນຫຍັງ?",
26
+ "ປະຫວັດສາດມີຄວາມສໍາຄັນຈັ່ງໃດ໋?",
27
+ "ຫຼັກຖານປະຫວັດສາດມີຫຍັງແດ່?",
28
+ "ຈະປ່ຽນຈາກປີຄ.ສ ເປັນປີພ.ສ ໄດ້ແນວໃດ?",
29
+ ],
30
+ )
31
+
32
+ # ---------------- Teacher tab ----------------
33
+ with gr.Tab("👩‍🏫 Teacher Panel"):
34
+ gr.Markdown(
35
+ "ໜ້ານີ້ໃຫ້ຄູເພີ່ມ / ແກ້ໄຂ Q&A ເອງ. "
36
+ "ຄໍາຕອບໃໝ່ຈະຖືກນໍາໃຊ້ທັນທີໃນ Student Chat."
37
+ )
38
+
39
+ q_box = gr.Textbox(
40
+ label="ຄໍາຖາມ (ພາສາລາວ)",
41
+ lines=3,
42
+ placeholder="ພິມຄໍາຖາມປະຫວັດສາດ...",
43
+ )
44
+ a_box = gr.Textbox(
45
+ label="ຄໍາຕອບ (ພາສາລາວ)",
46
+ lines=4,
47
+ placeholder="ພິມຄໍາຕອບທີ່ຖືກຕ້ອງ ແລະເຂົ້າໃຈງ່າຍ...",
48
+ )
49
+
50
+ current_id_state = gr.State("")
51
+
52
+ with gr.Row():
53
+ btn_save = gr.Button("💾 Save Q&A (Add / Overwrite)")
54
+ btn_update = gr.Button("✏️ Update current")
55
+ btn_delete = gr.Button("🗑️ Delete current")
56
+
57
+ status_md = gr.Markdown("")
58
+
59
+ qa_table = gr.Dataframe(
60
+ headers=["ID", "ຄໍາຖາມ", "ຄໍາຕອບ"],
61
+ value=manual_qa_table_data(),
62
+ interactive=True,
63
+ wrap=True,
64
+ row_count=(0, "dynamic"),
65
+ )
66
+
67
+ # wire buttons
68
+ btn_save.click(
69
+ fn=teacher_save_add_overwrite,
70
+ inputs=[q_box, a_box, current_id_state],
71
+ outputs=[q_box, a_box, current_id_state, qa_table, status_md],
72
+ )
73
+
74
+ btn_update.click(
75
+ fn=teacher_update_current,
76
+ inputs=[q_box, a_box, current_id_state],
77
+ outputs=[q_box, a_box, current_id_state, qa_table, status_md],
78
+ )
79
+
80
+ btn_delete.click(
81
+ fn=teacher_delete_current,
82
+ inputs=[current_id_state],
83
+ outputs=[q_box, a_box, current_id_state, qa_table, status_md],
84
+ )
85
+
86
+ qa_table.select(
87
+ fn=teacher_on_table_select,
88
+ inputs=[qa_table],
89
+ outputs=[q_box, a_box, current_id_state, status_md],
90
+ )
91
 
92
  if __name__ == "__main__":
93
  demo.launch()