Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,12 +90,22 @@ def generate_similar_question(wrong_q, misconception_id, generator):
|
|
| 90 |
st.error("μ μ¬ λ¬Έμ μμ±μ νμν λ°μ΄ν° νμμ΄ μλͺ»λμμ΅λλ€.")
|
| 91 |
return None
|
| 92 |
|
| 93 |
-
# misconception_idκ° μ ν¨νμ§ νμΈ
|
| 94 |
-
if pd.isna(misconception_id):
|
| 95 |
-
logger.warning("misconception_id is NaN")
|
| 96 |
-
return None
|
| 97 |
-
|
| 98 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
# λ°μ΄ν° μ€λΉ (νν λ³ν λ°©μ§)
|
| 100 |
input_data = {
|
| 101 |
'construct_name': str(wrong_q.get('ConstructName', '')),
|
|
@@ -119,12 +129,10 @@ def generate_similar_question(wrong_q, misconception_id, generator):
|
|
| 119 |
misconception_id=input_data['misconception_id']
|
| 120 |
)
|
| 121 |
|
| 122 |
-
# integrating module3
|
| 123 |
if generated_q:
|
| 124 |
verifier = load_answer_verifier()
|
| 125 |
with st.status("π€ AIκ° λ¬Έμ λ₯Ό κ²ν νκ³ μμ΅λλ€..."):
|
| 126 |
st.write("λ΅μμ μ νμ±μ κ²μ¦νκ³ μμ΅λλ€...")
|
| 127 |
-
# λ΅μ κ²μ¦ μλ
|
| 128 |
verified_answer = verifier.verify_answer(
|
| 129 |
question=generated_q.question,
|
| 130 |
choices=generated_q.choices
|
|
@@ -133,18 +141,15 @@ def generate_similar_question(wrong_q, misconception_id, generator):
|
|
| 133 |
if verified_answer:
|
| 134 |
logger.info(f"Answer verified: {verified_answer}")
|
| 135 |
st.write("β
κ²μ¦ μλ£!")
|
| 136 |
-
# μΈμ
μ€ν
μ΄νΈμ μ λ΅ μ μ₯
|
| 137 |
result = {
|
| 138 |
'question': generated_q.question,
|
| 139 |
'choices': generated_q.choices,
|
| 140 |
-
'correct': verified_answer,
|
| 141 |
'explanation': generated_q.explanation
|
| 142 |
}
|
| 143 |
-
# μ λ΅μ μΈμ
μ€ν
μ΄νΈμ μ μ₯
|
| 144 |
st.session_state['current_similar_question_answer'] = verified_answer
|
| 145 |
return result
|
| 146 |
else:
|
| 147 |
-
# κ²μ¦ μ€ν¨ μ μλ³Έ λ΅μ μ¬μ©
|
| 148 |
logger.warning("Answer verification failed, using original answer")
|
| 149 |
st.write("β οΈ κ²μ¦μ μ€ν¨νμ΅λλ€. μλ³Έ λ΅μμ μ¬μ©ν©λλ€.")
|
| 150 |
result = {
|
|
@@ -153,7 +158,6 @@ def generate_similar_question(wrong_q, misconception_id, generator):
|
|
| 153 |
'correct': generated_q.correct_answer,
|
| 154 |
'explanation': generated_q.explanation
|
| 155 |
}
|
| 156 |
-
# μ λ΅μ μΈμ
μ€ν
μ΄νΈμ μ μ₯
|
| 157 |
st.session_state['current_similar_question_answer'] = generated_q.correct_answer
|
| 158 |
return result
|
| 159 |
|
|
|
|
| 90 |
st.error("μ μ¬ λ¬Έμ μμ±μ νμν λ°μ΄ν° νμμ΄ μλͺ»λμμ΅λλ€.")
|
| 91 |
return None
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
try:
|
| 94 |
+
# misconception_idκ° μκ±°λ NaNμΈ κ²½μ° λ€λ₯Έ misconception μ¬μ©
|
| 95 |
+
if pd.isna(misconception_id):
|
| 96 |
+
logger.info("Original misconception_id is NaN, trying to find alternative")
|
| 97 |
+
# νμ¬κΉμ§ λμ¨ misconceptionλ€ μ€μμ μ ν
|
| 98 |
+
available_misconceptions = [m for m in st.session_state.misconceptions if not pd.isna(m)]
|
| 99 |
+
|
| 100 |
+
if available_misconceptions:
|
| 101 |
+
# κ°μ₯ μ΅κ·Όμ λμ¨ misconception μ ν
|
| 102 |
+
misconception_id = available_misconceptions[-1]
|
| 103 |
+
logger.info(f"Using alternative misconception_id: {misconception_id}")
|
| 104 |
+
else:
|
| 105 |
+
# κΈ°λ³Έ misconception ID μ¬μ© (μ: κ°μ₯ κΈ°λ³Έμ μΈ misconception)
|
| 106 |
+
misconception_id = 2001 # μ μ ν κΈ°λ³Έκ°μΌλ‘ μμ νμ
|
| 107 |
+
logger.info(f"Using default misconception_id: {misconception_id}")
|
| 108 |
+
|
| 109 |
# λ°μ΄ν° μ€λΉ (νν λ³ν λ°©μ§)
|
| 110 |
input_data = {
|
| 111 |
'construct_name': str(wrong_q.get('ConstructName', '')),
|
|
|
|
| 129 |
misconception_id=input_data['misconception_id']
|
| 130 |
)
|
| 131 |
|
|
|
|
| 132 |
if generated_q:
|
| 133 |
verifier = load_answer_verifier()
|
| 134 |
with st.status("π€ AIκ° λ¬Έμ λ₯Ό κ²ν νκ³ μμ΅λλ€..."):
|
| 135 |
st.write("λ΅μμ μ νμ±μ κ²μ¦νκ³ μμ΅λλ€...")
|
|
|
|
| 136 |
verified_answer = verifier.verify_answer(
|
| 137 |
question=generated_q.question,
|
| 138 |
choices=generated_q.choices
|
|
|
|
| 141 |
if verified_answer:
|
| 142 |
logger.info(f"Answer verified: {verified_answer}")
|
| 143 |
st.write("β
κ²μ¦ μλ£!")
|
|
|
|
| 144 |
result = {
|
| 145 |
'question': generated_q.question,
|
| 146 |
'choices': generated_q.choices,
|
| 147 |
+
'correct': verified_answer,
|
| 148 |
'explanation': generated_q.explanation
|
| 149 |
}
|
|
|
|
| 150 |
st.session_state['current_similar_question_answer'] = verified_answer
|
| 151 |
return result
|
| 152 |
else:
|
|
|
|
| 153 |
logger.warning("Answer verification failed, using original answer")
|
| 154 |
st.write("β οΈ κ²μ¦μ μ€ν¨νμ΅λλ€. μλ³Έ λ΅μμ μ¬μ©ν©λλ€.")
|
| 155 |
result = {
|
|
|
|
| 158 |
'correct': generated_q.correct_answer,
|
| 159 |
'explanation': generated_q.explanation
|
| 160 |
}
|
|
|
|
| 161 |
st.session_state['current_similar_question_answer'] = generated_q.correct_answer
|
| 162 |
return result
|
| 163 |
|