Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,7 +47,7 @@ def generate_question(topic, difficulty):
|
|
| 47 |
# 儲存參考答案
|
| 48 |
reference_answers[topic] = question # 假設問題即為參考答案,根據實際情況調整
|
| 49 |
|
| 50 |
-
return question
|
| 51 |
except Exception as e:
|
| 52 |
return f"⚠️ 發生錯誤:{e}"
|
| 53 |
|
|
@@ -83,7 +83,7 @@ def analyze_answer(user_input, topic):
|
|
| 83 |
"AI 分析": feedback,
|
| 84 |
"參考答案": correct_answer # 儲存參考答案
|
| 85 |
})
|
| 86 |
-
return f"{feedback}\n\n參考答案:{correct_answer}"
|
| 87 |
|
| 88 |
def get_errors_by_date_safe(date_str):
|
| 89 |
try:
|
|
@@ -95,32 +95,47 @@ def get_errors_by_date_safe(date_str):
|
|
| 95 |
return "✅ 該日無錯題紀錄。"
|
| 96 |
return "\n\n".join([f"🔹 題目: {e['題目']}\n📝 回答: {e['回答']}\n📖 AI 分析: {e['AI 分析']}\n📜 參考答案: {e['參考答案']}" for e in errors])
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
with gr.Blocks() as demo:
|
| 99 |
gr.Markdown("# 👨🏫 教師檢定智慧陪讀家教 🚀")
|
| 100 |
|
| 101 |
with gr.Row():
|
| 102 |
topic_input = gr.Dropdown(choices=topics, label="選擇複習主題")
|
| 103 |
difficulty_input = gr.Dropdown(choices=difficulties, label="選擇難度等級")
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
question_output = gr.Textbox(label="AI 生成的問題", lines=4)
|
| 106 |
-
|
| 107 |
-
inputs=[topic_input, difficulty_input],
|
| 108 |
-
outputs=question_output)
|
| 109 |
-
|
| 110 |
user_answer = gr.Textbox(label="你的回答", lines=3)
|
| 111 |
analyze_btn = gr.Button("📊 分析回答")
|
| 112 |
analysis_result = gr.Textbox(label="AI 分析與講解", lines=5)
|
| 113 |
-
|
| 114 |
-
inputs=[user_answer, topic_input],
|
| 115 |
-
outputs=analysis_result)
|
| 116 |
-
|
| 117 |
gr.Markdown("---")
|
| 118 |
-
gr.Markdown("
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
demo.launch()
|
|
|
|
| 47 |
# 儲存參考答案
|
| 48 |
reference_answers[topic] = question # 假設問題即為參考答案,根據實際情況調整
|
| 49 |
|
| 50 |
+
return question # 返回生成的問題
|
| 51 |
except Exception as e:
|
| 52 |
return f"⚠️ 發生錯誤:{e}"
|
| 53 |
|
|
|
|
| 83 |
"AI 分析": feedback,
|
| 84 |
"參考答案": correct_answer # 儲存參考答案
|
| 85 |
})
|
| 86 |
+
return f"{feedback}\n\n參考答案:{correct_answer}" # 這裡可以選擇不返回參考答案
|
| 87 |
|
| 88 |
def get_errors_by_date_safe(date_str):
|
| 89 |
try:
|
|
|
|
| 95 |
return "✅ 該日無錯題紀錄。"
|
| 96 |
return "\n\n".join([f"🔹 題目: {e['題目']}\n📝 回答: {e['回答']}\n📖 AI 分析: {e['AI 分析']}\n📜 參考答案: {e['參考答案']}" for e in errors])
|
| 97 |
|
| 98 |
+
def clear_all():
|
| 99 |
+
# 清空問題、回答、參考答案與錯題歷史,但保留PDF文本
|
| 100 |
+
global reference_answers, user_errors, error_history
|
| 101 |
+
reference_answers = {}
|
| 102 |
+
user_errors = {}
|
| 103 |
+
error_history.clear()
|
| 104 |
+
return "", "", "", get_errors_text()
|
| 105 |
+
|
| 106 |
+
def clear_question_and_answer():
|
| 107 |
+
# 清空生成的問題和用戶的回答
|
| 108 |
+
return "", ""
|
| 109 |
+
|
| 110 |
with gr.Blocks() as demo:
|
| 111 |
gr.Markdown("# 👨🏫 教師檢定智慧陪讀家教 🚀")
|
| 112 |
|
| 113 |
with gr.Row():
|
| 114 |
topic_input = gr.Dropdown(choices=topics, label="選擇複習主題")
|
| 115 |
difficulty_input = gr.Dropdown(choices=difficulties, label="選擇難度等級")
|
| 116 |
+
with gr.Row():
|
| 117 |
+
ask_btn = gr.Button("🎯 生成問題")
|
| 118 |
+
clear_question_btn = gr.Button("❌ 清空問題")
|
| 119 |
question_output = gr.Textbox(label="AI 生成的問題", lines=4)
|
| 120 |
+
|
|
|
|
|
|
|
|
|
|
| 121 |
user_answer = gr.Textbox(label="你的回答", lines=3)
|
| 122 |
analyze_btn = gr.Button("📊 分析回答")
|
| 123 |
analysis_result = gr.Textbox(label="AI 分析與講解", lines=5)
|
| 124 |
+
|
|
|
|
|
|
|
|
|
|
| 125 |
gr.Markdown("---")
|
| 126 |
+
gr.Markdown("📋 錯題自動記錄")
|
| 127 |
+
error_history_output = gr.Textbox(label="錯題紀錄", lines=10)
|
| 128 |
+
|
| 129 |
+
# 生成問題按鈕事件
|
| 130 |
+
ask_btn.click(fn=lambda t, d: generate_question(t, d),
|
| 131 |
+
inputs=[topic_input, difficulty_input],
|
| 132 |
+
outputs=[question_output])
|
| 133 |
+
# 清空問題按鈕事件
|
| 134 |
+
clear_question_btn.click(fn=clear_question_and_answer,
|
| 135 |
+
inputs=[],
|
| 136 |
+
outputs=[question_output, user_answer])
|
| 137 |
+
# 分析回答按鈕事件
|
| 138 |
+
analyze_btn.click(fn=analyze_answer,
|
| 139 |
+
inputs=[user_answer, topic_input],
|
| 140 |
+
outputs=[analysis_result, error_history_output])
|
| 141 |
demo.launch()
|