SarahXia0405 commited on
Commit
10d0ace
·
verified ·
1 Parent(s): a5c6d3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -15,7 +15,7 @@ if not OPENAI_API_KEY:
15
  client = OpenAI(api_key=OPENAI_API_KEY)
16
  DEFAULT_MODEL = "gpt-4.1-mini"
17
 
18
- # ---------- 默认 GenAI 课程大纲(来自你的周表,稍作改写) ----------
19
  DEFAULT_COURSE_TOPICS = [
20
  "Week 0 – Welcome & What is Generative AI; course outcomes LO1–LO5.",
21
  "Week 1 – Foundations of GenAI: LLMs, Transformer & self-attention, perplexity.",
@@ -30,7 +30,7 @@ DEFAULT_COURSE_TOPICS = [
30
  "Week 10 – Responsible AI; risks, governance, EU AI Act-style ideas.",
31
  ]
32
 
33
- # ---------- 学习模式列表 ----------
34
  LEARNING_MODES = [
35
  "Concept Explainer",
36
  "Socratic Tutor",
@@ -86,7 +86,10 @@ Safety and honesty:
86
 
87
  # ---------- syllabus 解析 ----------
88
  def parse_syllabus_docx(file_path: str, max_lines: int = 15) -> List[str]:
89
- """非常简单的 syllabus 解析:取前若干个非空段落当作主题行。"""
 
 
 
90
  topics: List[str] = []
91
  try:
92
  doc = Document(file_path)
@@ -214,7 +217,7 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant") as demo:
214
  value="Auto",
215
  label="Preferred answer language",
216
  )
217
- learning_mode = gr.Dropdown(
218
  choices=LEARNING_MODES,
219
  value="Concept Explainer",
220
  label="Learning mode",
@@ -227,6 +230,7 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant") as demo:
227
  )
228
  course_outline_state = gr.State(DEFAULT_COURSE_TOPICS)
229
 
 
230
  def update_outline(file):
231
  if file is None:
232
  return DEFAULT_COURSE_TOPICS
@@ -249,20 +253,28 @@ with gr.Blocks(title="Clare – Hanbridge AI Teaching Assistant") as demo:
249
  )
250
  clear_btn = gr.Button("Reset conversation")
251
 
252
- def respond(message, chat_history, course_outline):
 
 
 
 
 
 
 
 
253
  answer, new_history = chat_with_clare(
254
  message=message,
255
  history=chat_history,
256
- model_name=model_name.value,
257
- language_preference=language_preference.value,
258
- learning_mode=learning_mode.value,
259
  course_outline=course_outline,
260
  )
261
  return "", new_history
262
 
263
  user_input.submit(
264
  respond,
265
- [user_input, chatbot, course_outline_state],
266
  [user_input, chatbot],
267
  )
268
 
 
15
  client = OpenAI(api_key=OPENAI_API_KEY)
16
  DEFAULT_MODEL = "gpt-4.1-mini"
17
 
18
+ # ---------- 默认 GenAI 课程大纲 ----------
19
  DEFAULT_COURSE_TOPICS = [
20
  "Week 0 – Welcome & What is Generative AI; course outcomes LO1–LO5.",
21
  "Week 1 – Foundations of GenAI: LLMs, Transformer & self-attention, perplexity.",
 
30
  "Week 10 – Responsible AI; risks, governance, EU AI Act-style ideas.",
31
  ]
32
 
33
+ # ---------- 学习模式 ----------
34
  LEARNING_MODES = [
35
  "Concept Explainer",
36
  "Socratic Tutor",
 
86
 
87
  # ---------- syllabus 解析 ----------
88
  def parse_syllabus_docx(file_path: str, max_lines: int = 15) -> List[str]:
89
+ """
90
+ 非常简单的 syllabus 解析:取前若干个非空段落当作主题行。
91
+ 只是为了给 Clare 一些课程上下文,不追求超精确结构。
92
+ """
93
  topics: List[str] = []
94
  try:
95
  doc = Document(file_path)
 
217
  value="Auto",
218
  label="Preferred answer language",
219
  )
220
+ learning_mode = gr.Radio(
221
  choices=LEARNING_MODES,
222
  value="Concept Explainer",
223
  label="Learning mode",
 
230
  )
231
  course_outline_state = gr.State(DEFAULT_COURSE_TOPICS)
232
 
233
+ # syllabus 上传后更新课程大纲
234
  def update_outline(file):
235
  if file is None:
236
  return DEFAULT_COURSE_TOPICS
 
253
  )
254
  clear_btn = gr.Button("Reset conversation")
255
 
256
+ # 注意这里显式把组件的当前值传进来,而不是 .value
257
+ def respond(
258
+ message,
259
+ chat_history,
260
+ course_outline,
261
+ model_name_val,
262
+ language_pref_val,
263
+ learning_mode_val,
264
+ ):
265
  answer, new_history = chat_with_clare(
266
  message=message,
267
  history=chat_history,
268
+ model_name=model_name_val,
269
+ language_preference=language_pref_val,
270
+ learning_mode=learning_mode_val,
271
  course_outline=course_outline,
272
  )
273
  return "", new_history
274
 
275
  user_input.submit(
276
  respond,
277
+ [user_input, chatbot, course_outline_state, model_name, language_preference, learning_mode],
278
  [user_input, chatbot],
279
  )
280