Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,16 +37,16 @@ def generate_question(topic, difficulty):
|
|
| 37 |
)
|
| 38 |
return response['choices'][0]['message']['content']
|
| 39 |
|
| 40 |
-
# AI
|
| 41 |
-
def analyze_answer(user_input,
|
| 42 |
global user_errors
|
| 43 |
|
| 44 |
# 使用 AI 來分析回答
|
| 45 |
-
prompt = f"學生回答:'{user_input}'\n\n
|
| 46 |
|
| 47 |
response = openai.ChatCompletion.create(
|
| 48 |
model="gpt-4",
|
| 49 |
-
messages=[{"role": "system", "content": "
|
| 50 |
{"role": "user", "content": prompt}]
|
| 51 |
)
|
| 52 |
|
|
@@ -75,7 +75,6 @@ with gr.Blocks() as demo:
|
|
| 75 |
topic_input = gr.Dropdown(choices=topics, label="選擇複習主題")
|
| 76 |
difficulty_input = gr.Dropdown(choices=difficulties, label="選擇難度等級")
|
| 77 |
question_output = gr.Textbox(label="AI 生成的問題")
|
| 78 |
-
correct_answer_output = gr.Textbox(label="正確答案")
|
| 79 |
|
| 80 |
ask_btn = gr.Button("生成問題")
|
| 81 |
ask_btn.click(generate_question, inputs=[topic_input, difficulty_input], outputs=question_output)
|
|
@@ -84,7 +83,7 @@ with gr.Blocks() as demo:
|
|
| 84 |
analysis_result = gr.Textbox(label="AI 分析與講解")
|
| 85 |
|
| 86 |
analyze_btn = gr.Button("分析回答")
|
| 87 |
-
analyze_btn.click(analyze_answer, inputs=[user_answer,
|
| 88 |
|
| 89 |
# 新增弱點歷史紀錄功能
|
| 90 |
weaknesses_output = gr.Textbox(label="弱點歷史紀錄")
|
|
|
|
| 37 |
)
|
| 38 |
return response['choices'][0]['message']['content']
|
| 39 |
|
| 40 |
+
# AI 判斷對錯並提供講解
|
| 41 |
+
def analyze_answer(user_input, topic):
|
| 42 |
global user_errors
|
| 43 |
|
| 44 |
# 使用 AI 來分析回答
|
| 45 |
+
prompt = f"學生回答:'{user_input}'\n\n請分析學生的回答是否正確,並提供詳細講解與建議。"
|
| 46 |
|
| 47 |
response = openai.ChatCompletion.create(
|
| 48 |
model="gpt-4",
|
| 49 |
+
messages=[{"role": "system", "content": "你是一位教育專家,請評估學生的回答,並提供詳細講解。"},
|
| 50 |
{"role": "user", "content": prompt}]
|
| 51 |
)
|
| 52 |
|
|
|
|
| 75 |
topic_input = gr.Dropdown(choices=topics, label="選擇複習主題")
|
| 76 |
difficulty_input = gr.Dropdown(choices=difficulties, label="選擇難度等級")
|
| 77 |
question_output = gr.Textbox(label="AI 生成的問題")
|
|
|
|
| 78 |
|
| 79 |
ask_btn = gr.Button("生成問題")
|
| 80 |
ask_btn.click(generate_question, inputs=[topic_input, difficulty_input], outputs=question_output)
|
|
|
|
| 83 |
analysis_result = gr.Textbox(label="AI 分析與講解")
|
| 84 |
|
| 85 |
analyze_btn = gr.Button("分析回答")
|
| 86 |
+
analyze_btn.click(analyze_answer, inputs=[user_answer, topic_input], outputs=analysis_result)
|
| 87 |
|
| 88 |
# 新增弱點歷史紀錄功能
|
| 89 |
weaknesses_output = gr.Textbox(label="弱點歷史紀錄")
|