Rathapoom commited on
Commit
a36d4a8
·
verified ·
1 Parent(s): a8ad087

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -23
app.py CHANGED
@@ -281,6 +281,9 @@ def apply_correction(story_index: int, corrected_text: str):
281
  if 0 <= story_index < len(st.session_state.story):
282
  original_text = st.session_state.story[story_index]['content']
283
  # เก็บประวัติการแก้ไข
 
 
 
284
  st.session_state.corrections[story_index] = {
285
  'original': original_text,
286
  'corrected': corrected_text,
@@ -289,6 +292,9 @@ def apply_correction(story_index: int, corrected_text: str):
289
  # แก้ไขประโยคในเรื่อง
290
  st.session_state.story[story_index]['content'] = corrected_text
291
  st.session_state.story[story_index]['is_corrected'] = True
 
 
 
292
 
293
  def get_vocabulary_suggestions() -> List[str]:
294
  """Get contextual vocabulary suggestions with Thai translations."""
@@ -521,27 +527,16 @@ with col1:
521
  story_display = st.container()
522
 
523
  with story_display:
524
- if not st.session_state.story:
525
- st.info("เริ่มต้นผจญภัยด้วยการเขียนประโยคแรกกันเลย! | Start your adventure by writing the first sentence!")
526
- else:
527
- for idx, entry in enumerate(st.session_state.story):
528
- if entry['role'] == 'You':
529
- col_text, col_button = st.columns([4, 1])
530
- with col_text:
531
- prefix = "👤 You (แก้ไขแล้ว):" if entry.get('is_corrected') else "👤 You:"
532
- st.write(f"{prefix} {entry['content']}")
533
-
534
- # ถ้ามี feedback และมีข้อผิด แสดงปุ่มแก้ไข
535
- if (idx in st.session_state.corrections and
536
- not entry.get('is_corrected') and
537
- st.session_state.feedback and
538
- st.session_state.feedback.get('has_errors')):
539
- with col_button:
540
- if st.button(f"✍️ แก้ไขประโยค", key=f"correct_{idx}"):
541
- apply_correction(idx, st.session_state.feedback['corrected'])
542
- st.rerun()
543
- elif entry['role'] == 'AI':
544
- st.write("🤖 AI:", entry['content'])
545
 
546
  # User Input Box
547
  st.markdown("""
@@ -569,11 +564,63 @@ with col2:
569
  if st.session_state.feedback:
570
  st.markdown("""
571
  <div class="thai-eng">
572
- <div class="thai">📝 คำแนะนำ</div>
573
  <div class="eng">Writing Feedback</div>
574
  </div>
575
  """, unsafe_allow_html=True)
576
- st.markdown(f"*{st.session_state.feedback}*")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
 
578
  # Help and Suggestions Box
579
  st.markdown("""
 
281
  if 0 <= story_index < len(st.session_state.story):
282
  original_text = st.session_state.story[story_index]['content']
283
  # เก็บประวัติการแก้ไข
284
+ if 'corrections' not in st.session_state:
285
+ st.session_state.corrections = {}
286
+
287
  st.session_state.corrections[story_index] = {
288
  'original': original_text,
289
  'corrected': corrected_text,
 
292
  # แก้ไขประโยคในเรื่อง
293
  st.session_state.story[story_index]['content'] = corrected_text
294
  st.session_state.story[story_index]['is_corrected'] = True
295
+
296
+ # แสดงข้อความยืนยันการแก้ไข
297
+ st.success("✅ แก้ไขประโยคเรียบร้อยแล้ว!")
298
 
299
  def get_vocabulary_suggestions() -> List[str]:
300
  """Get contextual vocabulary suggestions with Thai translations."""
 
527
  story_display = st.container()
528
 
529
  with story_display:
530
+ if not st.session_state.story:
531
+ st.info("เริ่มต้นผจญภัยด้วยการเขียนประโยคแรกกันเลย! | Start your adventure by writing the first sentence!")
532
+ else:
533
+ for idx, entry in enumerate(st.session_state.story):
534
+ if entry['role'] == 'You':
535
+ # ถ้าประโยคถูกแก้ไขแล้ว แสดงไอคอนดินสอ
536
+ correction_status = "✍️ " if entry.get('is_corrected') else ""
537
+ st.write(f"👤 You: {correction_status}{entry['content']}")
538
+ elif entry['role'] == 'AI':
539
+ st.write("🤖 AI:", entry['content'])
 
 
 
 
 
 
 
 
 
 
 
540
 
541
  # User Input Box
542
  st.markdown("""
 
564
  if st.session_state.feedback:
565
  st.markdown("""
566
  <div class="thai-eng">
567
+ <div class="thai">📝 คำแนะนำจากครู</div>
568
  <div class="eng">Writing Feedback</div>
569
  </div>
570
  """, unsafe_allow_html=True)
571
+
572
+ # แสดง feedback ในรูปแบบที่อ่านง่าย
573
+ feedback_container = st.container()
574
+ with feedback_container:
575
+ if st.session_state.feedback.get('has_errors', False):
576
+ st.markdown(f"""
577
+ <div style='background-color: #f0f2f6;
578
+ padding: 15px;
579
+ border-radius: 8px;
580
+ border-left: 4px solid #FF9800;
581
+ margin: 5px 0;
582
+ font-family: "Sarabun", sans-serif;'>
583
+ <p style='color: #1e88e5; margin-bottom: 10px;'>
584
+ {st.session_state.feedback['feedback']}
585
+ </p>
586
+ <p style='color: #666; font-size: 0.9em;'>
587
+ ประโยคที่ถูกต้อง:<br/>
588
+ <span style='color: #4CAF50; font-weight: bold;'>
589
+ {st.session_state.feedback['corrected']}
590
+ </span>
591
+ </p>
592
+ <button class='correction-button' onclick='submit_correction()'>
593
+ ✍️ แก้ไขประโยคให้ถูกต้อง
594
+ </button>
595
+ </div>
596
+ """, unsafe_allow_html=True)
597
+
598
+ # ปุ่มแก้ไขประโยค
599
+ if st.button("✍️ แก้ไขประโยคให้ถูกต้อง", key="correct_last"):
600
+ last_user_entry_idx = next(
601
+ (i for i, entry in reversed(list(enumerate(st.session_state.story)))
602
+ if entry['role'] == 'You'),
603
+ None
604
+ )
605
+ if last_user_entry_idx is not None:
606
+ apply_correction(
607
+ last_user_entry_idx,
608
+ st.session_state.feedback['corrected']
609
+ )
610
+ st.rerun()
611
+ else:
612
+ st.markdown(f"""
613
+ <div style='background-color: #f0f2f6;
614
+ padding: 15px;
615
+ border-radius: 8px;
616
+ border-left: 4px solid #4CAF50;
617
+ margin: 5px 0;
618
+ font-family: "Sarabun", sans-serif;'>
619
+ <p style='color: #1e88e5;'>
620
+ ✨ {st.session_state.feedback['feedback']}
621
+ </p>
622
+ </div>
623
+ """, unsafe_allow_html=True)
624
 
625
  # Help and Suggestions Box
626
  st.markdown("""