iamSammi commited on
Commit
6e84011
·
verified ·
1 Parent(s): 0a94d48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -5,15 +5,15 @@ import os
5
 
6
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
7
 
8
- # 設定教育心理學主題
9
- topics = ["學習理論", "動機與情意", "發展心理學", "個別差異", "教學與評量", "班級經營與學習環境", "教育心理學研究方法"]
10
  difficulties = ["簡單", "中等", "困難"]
11
 
12
  # 學習者錯誤統計
13
  user_errors = {}
14
 
15
  # **開發者預設教材 PDF 檔案**
16
- DEFAULT_PDF_PATH = "教材.pdf" # 確保此檔案存放在專案目錄中
17
 
18
  # 解析 PDF 並擷取文本(使用開發者預設的教材)
19
  def extract_text_from_pdf():
@@ -28,11 +28,11 @@ pdf_text = extract_text_from_pdf() # 讀取教材
28
 
29
  # AI 生成問題函數(基於預設教材)
30
  def generate_question(topic, difficulty):
31
- prompt = f"請根據以下教育心理學教材內容,設計一個'{difficulty}'難度的考題:\n{pdf_text}"
32
 
33
  response = openai.ChatCompletion.create(
34
  model="gpt-4",
35
- messages=[{"role": "system", "content": "你是一位教育心理學專家,請根據教材內容生成考題。"},
36
  {"role": "user", "content": prompt}]
37
  )
38
  return response['choices'][0]['message']['content']
@@ -79,7 +79,7 @@ def get_weaknesses():
79
  with gr.Blocks() as demo:
80
  gr.Markdown("# 教師檢定智慧陪讀家教 🚀")
81
 
82
- topic_input = gr.Dropdown(choices=topics, label="選擇教育心理學主題")
83
  difficulty_input = gr.Dropdown(choices=difficulties, label="選擇難度等級")
84
  question_output = gr.Textbox(label="AI 生成的問題")
85
 
 
5
 
6
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
7
 
8
+ # **新的主題選項**
9
+ topics = ["教育哲學", "教育社會學", "教育心理學", "課程與教學", "教學原理", "班級經營", "教育測驗與評量", "青少年問題與輔導"]
10
  difficulties = ["簡單", "中等", "困難"]
11
 
12
  # 學習者錯誤統計
13
  user_errors = {}
14
 
15
  # **開發者預設教材 PDF 檔案**
16
+ DEFAULT_PDF_PATH = "教材.pdf"
17
 
18
  # 解析 PDF 並擷取文本(使用開發者預設的教材)
19
  def extract_text_from_pdf():
 
28
 
29
  # AI 生成問題函數(基於預設教材)
30
  def generate_question(topic, difficulty):
31
+ prompt = f"請根據以下教育學教材內容,設計一個屬於'{topic}'主題、'{difficulty}'難度的考題:\n{pdf_text}"
32
 
33
  response = openai.ChatCompletion.create(
34
  model="gpt-4",
35
+ messages=[{"role": "system", "content": "你是一位教育專家,請根據教材內容提供符合主題的問題。"},
36
  {"role": "user", "content": prompt}]
37
  )
38
  return response['choices'][0]['message']['content']
 
79
  with gr.Blocks() as demo:
80
  gr.Markdown("# 教師檢定智慧陪讀家教 🚀")
81
 
82
+ topic_input = gr.Dropdown(choices=topics, label="選擇主題")
83
  difficulty_input = gr.Dropdown(choices=difficulties, label="選擇難度等級")
84
  question_output = gr.Textbox(label="AI 生成的問題")
85