Heng2004 commited on
Commit
9c64bb2
·
verified ·
1 Parent(s): 7edd2ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -30
app.py CHANGED
@@ -8,6 +8,7 @@ from teacher_panel import (
8
  teacher_update_current,
9
  teacher_delete_current,
10
  teacher_on_table_select,
 
11
  )
12
 
13
  # Build Gradio UI
@@ -21,30 +22,15 @@ with gr.Blocks() as demo:
21
  fn=laos_science_bot,
22
  title="",
23
  description="",
24
- examples=[
25
- "ວິທະຍາສາດທຳມະຊາດແມ່ນຫຍັງ?",
26
-
27
- ],
28
  )
29
 
30
  # ---------------- Teacher tab ----------------
31
  with gr.Tab("👩‍🏫 Teacher Panel"):
32
- gr.Markdown(
33
- "ໜ້ານີ້ໃຫ້ຄູເພີ່ມ / ແກ້ໄຂ Q&A ເອງ. "
34
- "ຄໍາຕອບໃໝ່ຈະຖືກນໍາໃຊ້ທັນທີໃນ Student Chat."
35
- )
36
-
37
- q_box = gr.Textbox(
38
- label="ຄໍາຖາມ (ພາສາລາວ)",
39
- lines=3,
40
- placeholder="ພິມຄໍາຖາມວິທະຍາສາດທຳມະຊາດ...",
41
- )
42
- a_box = gr.Textbox(
43
- label="ຄໍາຕອບ (ພາສາລາວ)",
44
- lines=4,
45
- placeholder="ພິມຄໍາຕອບທີ່ຖືກຕ້ອງ ແລະເຂົ້າໃຈງ່າຍ...",
46
- )
47
 
 
 
48
  current_id_state = gr.State("")
49
 
50
  with gr.Row():
@@ -52,6 +38,13 @@ with gr.Blocks() as demo:
52
  btn_update = gr.Button("✏️ Update current")
53
  btn_delete = gr.Button("🗑️ Delete current")
54
 
 
 
 
 
 
 
 
55
  status_md = gr.Markdown("")
56
 
57
  qa_table = gr.Dataframe(
@@ -80,21 +73,23 @@ with gr.Blocks() as demo:
80
  inputs=[current_id_state],
81
  outputs=[q_box, a_box, current_id_state, qa_table, status_md],
82
  )
 
 
 
 
 
 
 
 
83
 
84
  qa_table.select(
85
  fn=teacher_on_table_select,
86
- inputs=None, # we only use the event data
87
  outputs=[q_box, a_box, current_id_state, status_md],
88
  )
89
- # 👇👇👇 ADD THIS NEW BLOCK HERE 👇👇👇
90
- # This ensures that whenever the page is refreshed, the table updates
91
- # to show the REAL current data from memory.
92
- demo.load(
93
- fn=manual_qa_table_data,
94
- inputs=None,
95
- outputs=qa_table
96
- )
97
- # 👆👆👆 END OF NEW BLOCK 👆👆👆
98
 
99
  if __name__ == "__main__":
100
- demo.launch()
 
8
  teacher_update_current,
9
  teacher_delete_current,
10
  teacher_on_table_select,
11
+ teacher_rebuild_cache_click, # <--- 1. IMPORT THIS!
12
  )
13
 
14
  # Build Gradio UI
 
22
  fn=laos_science_bot,
23
  title="",
24
  description="",
25
+ examples=["ວິທະຍາສາດທຳມະຊາດແມ່ນຫຍັງ?"],
 
 
 
26
  )
27
 
28
  # ---------------- Teacher tab ----------------
29
  with gr.Tab("👩‍🏫 Teacher Panel"):
30
+ gr.Markdown("ໜ້ານີ້ໃຫ້ຄູເພີ່ມ / ແກ້ໄຂ Q&A ເອງ.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ q_box = gr.Textbox(label="ຄໍາຖາມ (ພາສາລາວ)", lines=3)
33
+ a_box = gr.Textbox(label="ຄໍາຕອບ (ພາສາລາວ)", lines=4)
34
  current_id_state = gr.State("")
35
 
36
  with gr.Row():
 
38
  btn_update = gr.Button("✏️ Update current")
39
  btn_delete = gr.Button("🗑️ Delete current")
40
 
41
+ # 👇👇👇 2. ADD THIS NEW SECTION HERE 👇👇👇
42
+ gr.Markdown("---") # Horizontal Line
43
+ with gr.Row():
44
+ # This is the missing button!
45
+ btn_rebuild = gr.Button("⚡ Admin: Rebuild & Upload Cache (Click only when Curriculum changes)")
46
+ # 👆👆👆 END OF NEW SECTION 👆👆👆
47
+
48
  status_md = gr.Markdown("")
49
 
50
  qa_table = gr.Dataframe(
 
73
  inputs=[current_id_state],
74
  outputs=[q_box, a_box, current_id_state, qa_table, status_md],
75
  )
76
+
77
+ # 👇👇👇 3. WIRE UP THE NEW BUTTON 👇👇👇
78
+ btn_rebuild.click(
79
+ fn=teacher_rebuild_cache_click,
80
+ inputs=None,
81
+ outputs=[status_md] # Show success message
82
+ )
83
+ # 👆👆👆 END OF NEW WIRE 👆👆👆
84
 
85
  qa_table.select(
86
  fn=teacher_on_table_select,
87
+ inputs=None,
88
  outputs=[q_box, a_box, current_id_state, status_md],
89
  )
90
+
91
+ # Auto-refresh on load
92
+ demo.load(fn=manual_qa_table_data, inputs=None, outputs=qa_table)
 
 
 
 
 
 
93
 
94
  if __name__ == "__main__":
95
+ demo.launch()