youngtsai commited on
Commit
a3a63d1
·
1 Parent(s): 4eb8cf4
Files changed (4) hide show
  1. .gitignore +2 -0
  2. app.py +115 -2
  3. local_config.json.example +5 -0
  4. requirements.txt +2 -1
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # local_config
2
+ local_config.json
app.py CHANGED
@@ -6,9 +6,22 @@ import os
6
  from pyvis.network import Network
7
  import networkx as nx
8
 
 
 
9
  # Env Vars
10
- METABASE_USERNAME = os.getenv('METABASE_USERNAME')
11
- METABASE_PASSWORD = os.getenv('METABASE_PASSWORD')
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # Original elements
14
  elements = [
@@ -250,6 +263,97 @@ def generate_html_table(result_data, exercise_quiz_result):
250
  table_html += "</table>"
251
  return table_html
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
  with gr.Blocks() as app:
255
  gr.Markdown("# Metabase Query and Visualization")
@@ -269,6 +373,11 @@ with gr.Blocks() as app:
269
  with gr.Row():
270
  graph_html = gr.HTML()
271
 
 
 
 
 
 
272
  all_in_one_button.click(
273
  fn=query_metabase_topic,
274
  inputs=[class_code, topic_card_id, user_id],
@@ -281,6 +390,10 @@ with gr.Blocks() as app:
281
  fn=needs_analysis,
282
  inputs=[topic_result, exercise_quiz_result],
283
  outputs=graph_html
 
 
 
 
284
  )
285
 
286
  app.launch()
 
6
  from pyvis.network import Network
7
  import networkx as nx
8
 
9
+ from openai import OpenAI
10
+
11
  # Env Vars
12
+ # METABASE_USERNAME = os.getenv('METABASE_USERNAME')
13
+ # METABASE_PASSWORD = os.getenv('METABASE_PASSWORD')
14
+ # OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
15
+
16
+ # get by local_config.json file
17
+ with open("local_config.json") as f:
18
+ config = json.load(f)
19
+ METABASE_USERNAME = config['METABASE_USERNAME']
20
+ METABASE_PASSWORD = config['METABASE_PASSWORD']
21
+ OPENAI_API_KEY = config['OPENAI_API_KEY']
22
+
23
+ # OpenAI API
24
+ OPENAI_API_CLIENT = OpenAI(api_key=OPENAI_API_KEY)
25
 
26
  # Original elements
27
  elements = [
 
263
  table_html += "</table>"
264
  return table_html
265
 
266
+ def get_ai_suggestion(topic_result, exercise_quiz_result):
267
+ # 使用 OPenAI API 获取建议
268
+ model = "gpt-4o"
269
+ sys_content = f"""
270
+ You are a professional teaching expert. I am a classroom teacher.
271
+ Please provide user (he/she is a teacher) a personalized analysis
272
+ """
273
+ user_content = f"""
274
+ Based on the data,
275
+ topic: {topic_result},
276
+ exercise_quiz_result: {exercise_quiz_result}
277
+ Please provide suggestions for the course.
278
+
279
+ rules:
280
+ - The suggestions should be based on the data provided.
281
+ - The suggestions should be actionable and specific.
282
+ - The suggestions should be relevant to the course content.
283
+ - use ZH-TW language, this is very important.
284
+ - return markdown format
285
+
286
+ for this student based on the given knowledge graph and data:
287
+ 1. How to interpret this knowledge graph.
288
+ 2. How to assess the student's strengths and weaknesses.
289
+ 3. How I can help this student improve.
290
+
291
+ for example:
292
+ # 針對 emdob01 學生的課程建議
293
+ ### 1. 如何解讀此知識圖與數據
294
+ 知識圖呈現學生在不同知識點上的掌握程度,用數字顯示熟悉度(0-1)。例如:
295
+ - `jnc-4-05-3-1` : 1 代表完全掌握
296
+ - `jnc-4-06-2-2` : 0 代表未掌握
297
+
298
+ 該學生的表現數據顯示各個練習題的回答正確性與所花費的時間。這有助於了解學生對不同題目的理解程度和答題速度。
299
+
300
+ # 2. 如何評估學生的強項與弱項
301
+ ### 強項
302
+ - 學生在某些特定的練習題中得到了正確答案。例如:
303
+ - `認識等值分數` 題目 `quiz_id` 108363,答對且用時62秒
304
+ - `真分數、假分數與帶分數的命名及說、讀、聽、寫、做` 題目 `quiz_id` 116882,答對且用時123秒
305
+
306
+ ### 弱項
307
+ - 學生在大多數練習題中答錯問題,特別在以下主題:
308
+ - `認識等值分數`:多次答錯
309
+ - `簡單異分母分數的比較`:多次答錯,且用時較長
310
+ - `假分數與帶分數的互換`:多次答錯
311
+
312
+ # 3. 如何幫助學生改進
313
+ 基於以上分析,給予以下改善建議:
314
+
315
+ ### 針對弱點加強練習
316
+ 1. **認識等值分數**:
317
+ - 提供更多視覺化的教學資源,如分數圖表和視頻講解。
318
+ - 設計一系列有針對性的互動練習,幫助學生理解分數等值的概念。
319
+ - 安排小組討論,讓學生分享他們的解題思路並相互學習。
320
+
321
+ 2. **簡單異分母分數的比較**:
322
+ - 強化基本概念教學,如找共同分母的方法。
323
+ - 設計漸進增難度的習題,從簡單到複雜,逐步提高學生的理解和應用能力。
324
+ - 鼓勵學生使用實物模型或數線來理解異分母分數的比較。
325
+
326
+ 3. **假分數與帶分數的互換**:
327
+ - 重點教學如何將假分數轉換為帶分數,並展示具體步驟。
328
+ - 制作練習題目集,讓學生反復練習,並提供及時的反饋和指導。
329
+ - 透過遊戲或互動活動來增強學生對該概念的興趣和記憶。
330
+
331
+ # 總結與提點建議
332
+ - 在課後提供補充資料(如影片、練習冊)供學生複習。
333
+ - 設計定期的小測試來檢驗學生的進步情況。
334
+ - 鼓勵學生對於每次錯誤進行反思,分析失誤原因並加以改正。
335
+ - 建立個性化學習計劃,根據每次測試結果調整練習重點和方法。
336
+
337
+ 希望這些建議能夠幫助該學生提升學習效果並更好地掌握課程內容。
338
+ """
339
+
340
+ print(f"user_content: {user_content}")
341
+
342
+ messages = [
343
+ {"role": "system", "content": sys_content},
344
+ {"role": "user", "content": user_content}
345
+ ]
346
+ request_payload = {
347
+ "model": model,
348
+ "messages": messages,
349
+ "max_tokens": 4000,
350
+ }
351
+
352
+ response = OPENAI_API_CLIENT.chat.completions.create(**request_payload)
353
+ suggestion = response.choices[0].message.content
354
+
355
+ return suggestion
356
+
357
 
358
  with gr.Blocks() as app:
359
  gr.Markdown("# Metabase Query and Visualization")
 
373
  with gr.Row():
374
  graph_html = gr.HTML()
375
 
376
+ with gr.Row():
377
+ gr.Markdown("# AI suggestion Powered by Junyi Academy")
378
+ with gr.Row():
379
+ ai_suggestion = gr.Textbox()
380
+
381
  all_in_one_button.click(
382
  fn=query_metabase_topic,
383
  inputs=[class_code, topic_card_id, user_id],
 
390
  fn=needs_analysis,
391
  inputs=[topic_result, exercise_quiz_result],
392
  outputs=graph_html
393
+ ).then(
394
+ fn=get_ai_suggestion,
395
+ inputs=[topic_result, exercise_quiz_result],
396
+ outputs=ai_suggestion
397
  )
398
 
399
  app.launch()
local_config.json.example ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "METABASE_USERNAME": "xxxx@msn.com",
3
+ "METABASE_PASSWORD": "xxxxxx",
4
+ "OPENAI_API_KEY": "sk-proj-IXliAxxxxxxxb4N0"
5
+ }
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  requests
2
  gradio >= 4.36.0
3
  networkx
4
- pyvis
 
 
1
  requests
2
  gradio >= 4.36.0
3
  networkx
4
+ pyvis
5
+ openai