Jintonic92 commited on
Commit
41ddd8a
Β·
verified Β·
1 Parent(s): 6d6d257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -13
app.py CHANGED
@@ -238,14 +238,22 @@ def main():
238
  st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
239
  else:
240
  st.info("Misconception 정보가 μ—†μŠ΅λ‹ˆλ‹€.")
241
- # try:
242
- # misconception_text = generator.get_misconception_text(misconception_id)
243
- # st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
244
- # except Exception as e:
245
- # logger.error(f"Error in get_misconception_text: {e}")
246
- # st.info("Misconception 정보가 μ—†μŠ΅λ‹ˆλ‹€.")
247
- # return None, None
248
-
 
 
 
 
 
 
 
 
249
  # μœ μ‚¬ 문제 생성 λ²„νŠΌ
250
  if st.button(f"πŸ“š μœ μ‚¬ 문제 ν’€κΈ° #{i + 1}", key=f"retry_{i}"):
251
  with st.spinner("μœ μ‚¬ 문제λ₯Ό μƒμ„±ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€..."):
@@ -254,13 +262,63 @@ def main():
254
  if new_question:
255
  st.write("### 🎯 μœ μ‚¬ 문제")
256
  st.write(new_question['question'])
257
- st.write("**보기:**")
258
- for choice, text in new_question['choices'].items():
259
- st.write(f"{choice}) {text}")
260
- st.write("**βœ… μ •λ‹΅:**", new_question['correct'])
261
- st.write("**πŸ“ ν•΄μ„€:**", new_question['explanation'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  else:
263
  st.error("μœ μ‚¬ 문제λ₯Ό 생성할 수 μ—†μŠ΅λ‹ˆλ‹€.")
 
 
264
  if __name__ == "__main__":
265
  main()
266
 
 
238
  st.info(f"Misconception ID: {int(misconception_id)}\n\n{misconception_text}")
239
  else:
240
  st.info("Misconception 정보가 μ—†μŠ΅λ‹ˆλ‹€.")
241
+
242
+ # # μœ μ‚¬ 문제 생성 λ²„νŠΌ
243
+ # if st.button(f"πŸ“š μœ μ‚¬ 문제 ν’€κΈ° #{i + 1}", key=f"retry_{i}"):
244
+ # with st.spinner("μœ μ‚¬ 문제λ₯Ό μƒμ„±ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€..."):
245
+ # logger.info(f"Generating similar question for misconception_id: {misconception_id}")
246
+ # new_question = generate_similar_question(wrong_q, misconception_id, generator)
247
+ # if new_question:
248
+ # st.write("### 🎯 μœ μ‚¬ 문제")
249
+ # st.write(new_question['question'])
250
+ # st.write("**보기:**")
251
+ # for choice, text in new_question['choices'].items():
252
+ # st.write(f"{choice}) {text}")
253
+ # st.write("**βœ… μ •λ‹΅:**", new_question['correct'])
254
+ # st.write("**πŸ“ ν•΄μ„€:**", new_question['explanation'])
255
+ # else:
256
+ # st.error("μœ μ‚¬ 문제λ₯Ό 생성할 수 μ—†μŠ΅λ‹ˆλ‹€.")
257
  # μœ μ‚¬ 문제 생성 λ²„νŠΌ
258
  if st.button(f"πŸ“š μœ μ‚¬ 문제 ν’€κΈ° #{i + 1}", key=f"retry_{i}"):
259
  with st.spinner("μœ μ‚¬ 문제λ₯Ό μƒμ„±ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€..."):
 
262
  if new_question:
263
  st.write("### 🎯 μœ μ‚¬ 문제")
264
  st.write(new_question['question'])
265
+
266
+ # 정닡을 μ„Έμ…˜ μŠ€ν…Œμ΄νŠΈμ— μ €μž₯
267
+ if f"similar_question_answered_{i}" not in st.session_state:
268
+ st.session_state[f"similar_question_answered_{i}"] = False
269
+ if f"similar_question_correct_{i}" not in st.session_state:
270
+ st.session_state[f"similar_question_correct_{i}"] = new_question['correct']
271
+
272
+ # 아직 λ‹΅λ³€ν•˜μ§€ μ•Šμ€ κ²½μš°μ—λ§Œ 보기 λ²„νŠΌ ν‘œμ‹œ
273
+ if not st.session_state[f"similar_question_answered_{i}"]:
274
+ st.write("**보기:**")
275
+ col1, col2 = st.columns(2)
276
+ with col1:
277
+ if st.button(f"A) {new_question['choices']['A']}", key=f"similar_A_{i}"):
278
+ st.session_state[f"similar_question_answered_{i}"] = True
279
+ if 'A' == new_question['correct']:
280
+ st.success("βœ… μ •λ‹΅μž…λ‹ˆλ‹€!")
281
+ else:
282
+ st.error("❌ ν‹€λ ΈμŠ΅λ‹ˆλ‹€.")
283
+ st.rerun()
284
+
285
+ if st.button(f"C) {new_question['choices']['C']}", key=f"similar_C_{i}"):
286
+ st.session_state[f"similar_question_answered_{i}"] = True
287
+ if 'C' == new_question['correct']:
288
+ st.success("βœ… μ •λ‹΅μž…λ‹ˆλ‹€!")
289
+ else:
290
+ st.error("❌ ν‹€λ ΈμŠ΅λ‹ˆλ‹€.")
291
+ st.rerun()
292
+
293
+ with col2:
294
+ if st.button(f"B) {new_question['choices']['B']}", key=f"similar_B_{i}"):
295
+ st.session_state[f"similar_question_answered_{i}"] = True
296
+ if 'B' == new_question['correct']:
297
+ st.success("βœ… μ •λ‹΅μž…λ‹ˆλ‹€!")
298
+ else:
299
+ st.error("❌ ν‹€λ ΈμŠ΅λ‹ˆλ‹€.")
300
+ st.rerun()
301
+
302
+ if st.button(f"D) {new_question['choices']['D']}", key=f"similar_D_{i}"):
303
+ st.session_state[f"similar_question_answered_{i}"] = True
304
+ if 'D' == new_question['correct']:
305
+ st.success("βœ… μ •λ‹΅μž…λ‹ˆλ‹€!")
306
+ else:
307
+ st.error("❌ ν‹€λ ΈμŠ΅λ‹ˆλ‹€.")
308
+ st.rerun()
309
+
310
+ # λ‹΅λ³€ν•œ 경우 κ²°κ³Ό 및 ν•΄μ„€ ν‘œμ‹œ
311
+ if st.session_state[f"similar_question_answered_{i}"]:
312
+ st.write("---")
313
+ st.write("**πŸ“ ν•΄μ„€:**", new_question['explanation'])
314
+ # λ‹€μ‹œ ν’€κΈ° λ²„νŠΌ
315
+ if st.button("πŸ”„ λ‹€μ‹œ ν’€κΈ°", key=f"reset_{i}"):
316
+ st.session_state[f"similar_question_answered_{i}"] = False
317
+ st.rerun()
318
  else:
319
  st.error("μœ μ‚¬ 문제λ₯Ό 생성할 수 μ—†μŠ΅λ‹ˆλ‹€.")
320
+
321
+
322
  if __name__ == "__main__":
323
  main()
324