Update app.py
Browse files
app.py
CHANGED
@@ -515,6 +515,42 @@ def submit_story():
|
|
515 |
# Clear input
|
516 |
st.session_state.text_input = ""
|
517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
# Theme Helper Functions
|
519 |
def get_available_themes(level: str) -> List[Dict]:
|
520 |
"""Get list of themes available for the current level."""
|
@@ -1338,29 +1374,43 @@ def apply_correction(story_index: int, corrected_text: str):
|
|
1338 |
if 0 <= story_index < len(st.session_state.story):
|
1339 |
original_text = st.session_state.story[story_index]['content']
|
1340 |
|
1341 |
-
#
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
'
|
1347 |
-
'
|
1348 |
-
|
1349 |
-
}
|
1350 |
-
|
1351 |
-
# แก้ไขประโยคในเรื่อง
|
1352 |
-
st.session_state.story[story_index]['content'] = corrected_text
|
1353 |
-
st.session_state.story[story_index]['is_corrected'] = True
|
1354 |
|
1355 |
# แสดงข้อความยืนยันการแก้ไข
|
1356 |
st.success("✅ แก้ไขประโยคเรียบร้อยแล้ว!")
|
1357 |
|
1358 |
-
# อัพเดทสถิติ
|
1359 |
if 'stats' in st.session_state:
|
1360 |
-
# อาจเพิ่มการนับจำนวนครั้งที่แก้ไข
|
1361 |
st.session_state.stats['corrections_made'] = \
|
1362 |
st.session_state.stats.get('corrections_made', 0) + 1
|
1363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1364 |
def get_vocabulary_suggestions() -> List[str]:
|
1365 |
"""Get contextual vocabulary suggestions with Thai translations."""
|
1366 |
try:
|
@@ -1529,6 +1579,61 @@ def update_points(is_correct_first_try: bool):
|
|
1529 |
st.session_state.stats['total_sentences'] * 100
|
1530 |
)
|
1531 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1532 |
# แสดงผลคะแนนและความสำเร็จ
|
1533 |
def show_achievements():
|
1534 |
"""แสดงความสำเร็จและสถิติ"""
|
|
|
515 |
# Clear input
|
516 |
st.session_state.text_input = ""
|
517 |
|
518 |
+
('is_starter'):
|
519 |
+
# แสดงประโยคเริ่มต้นพิเศษ
|
520 |
+
st.markdown(f"""
|
521 |
+
<div style="background-color: #f0f7ff;
|
522 |
+
padding: 15px;
|
523 |
+
border-radius: 8px;
|
524 |
+
margin: 5px 0;
|
525 |
+
border-left: 4px solid #1e88e5;">
|
526 |
+
<p style="color: #1e88e5; margin-bottom: 5px;">🎬 เริ่มเรื่อง:</p>
|
527 |
+
<p style="color: #666;">{entry.get('thai_content', '')}</p>
|
528 |
+
<p>{entry['content']}</p>
|
529 |
+
</div>
|
530 |
+
""", unsafe_allow_html=True)
|
531 |
+
else:
|
532 |
+
st.markdown(f"""
|
533 |
+
<div style="padding: 10px; margin: 5px 0;">
|
534 |
+
<p>🤖 AI: {entry['content']}</p>
|
535 |
+
</div>
|
536 |
+
""", unsafe_allow_html=True)
|
537 |
+
elif entry['role'] == 'You':
|
538 |
+
status_icon = "✅ " if entry.get('is_correct') else "✍️ "
|
539 |
+
if entry.get('is_corrected'):
|
540 |
+
# แสดงข้อความที่ถูกแก้ไขแล้ว
|
541 |
+
st.markdown(f"""
|
542 |
+
<div style="padding: 10px; margin: 5px 0; background-color: #f0f9ff; border-radius: 5px;">
|
543 |
+
<p>👤 You: {status_icon}{entry['content']}</p>
|
544 |
+
</div>
|
545 |
+
""", unsafe_allow_html=True)
|
546 |
+
else:
|
547 |
+
# แสดงข้อความปกติ
|
548 |
+
st.markdown(f"""
|
549 |
+
<div style="padding: 10px; margin: 5px 0;">
|
550 |
+
<p>👤 You: {status_icon}{entry['content']}</p>
|
551 |
+
</div>
|
552 |
+
""", unsafe_allow_html=True)
|
553 |
+
|
554 |
# Theme Helper Functions
|
555 |
def get_available_themes(level: str) -> List[Dict]:
|
556 |
"""Get list of themes available for the current level."""
|
|
|
1374 |
if 0 <= story_index < len(st.session_state.story):
|
1375 |
original_text = st.session_state.story[story_index]['content']
|
1376 |
|
1377 |
+
# อัพเดทข้อความเดิมแทนที่จะเพิ่มใหม่
|
1378 |
+
st.session_state.story[story_index].update({
|
1379 |
+
'content': corrected_text,
|
1380 |
+
'is_corrected': True,
|
1381 |
+
'is_correct': True,
|
1382 |
+
'original_text': original_text,
|
1383 |
+
'correction_timestamp': datetime.now().isoformat()
|
1384 |
+
})
|
|
|
|
|
|
|
|
|
|
|
1385 |
|
1386 |
# แสดงข้อความยืนยันการแก้ไข
|
1387 |
st.success("✅ แก้ไขประโยคเรียบร้อยแล้ว!")
|
1388 |
|
1389 |
+
# อัพเดทสถิติ
|
1390 |
if 'stats' in st.session_state:
|
|
|
1391 |
st.session_state.stats['corrections_made'] = \
|
1392 |
st.session_state.stats.get('corrections_made', 0) + 1
|
1393 |
|
1394 |
+
# เพิ่ม CSS สำหรับการแสดงผล
|
1395 |
+
st.markdown("""
|
1396 |
+
<style>
|
1397 |
+
.story-message {
|
1398 |
+
padding: 10px;
|
1399 |
+
margin: 5px 0;
|
1400 |
+
border-radius: 5px;
|
1401 |
+
}
|
1402 |
+
.story-message.ai {
|
1403 |
+
background-color: #f0f7ff;
|
1404 |
+
}
|
1405 |
+
.story-message.user {
|
1406 |
+
background-color: #fff;
|
1407 |
+
}
|
1408 |
+
.story-message.corrected {
|
1409 |
+
background-color: #f0f9ff;
|
1410 |
+
}
|
1411 |
+
</style>
|
1412 |
+
""", unsafe_allow_html=True)
|
1413 |
+
|
1414 |
def get_vocabulary_suggestions() -> List[str]:
|
1415 |
"""Get contextual vocabulary suggestions with Thai translations."""
|
1416 |
try:
|
|
|
1579 |
st.session_state.stats['total_sentences'] * 100
|
1580 |
)
|
1581 |
|
1582 |
+
def show_story():
|
1583 |
+
story_display = st.container()
|
1584 |
+
|
1585 |
+
with story_display:
|
1586 |
+
if not st.session_state.story:
|
1587 |
+
st.info("เลือกธีมเรื่องราวที่ต้องการเพื่อเริ่มต้นการผจญภัย!")
|
1588 |
+
else:
|
1589 |
+
# เก็บข้อความล่าสุดของแต่ละ index
|
1590 |
+
latest_messages = {}
|
1591 |
+
for idx, entry in enumerate(st.session_state.story):
|
1592 |
+
if entry['role'] == 'You':
|
1593 |
+
latest_messages[idx] = entry
|
1594 |
+
else:
|
1595 |
+
# สำหรับข้อความของ AI ให้แสดงทุกข้อความ
|
1596 |
+
latest_messages[idx] = entry
|
1597 |
+
|
1598 |
+
# แสดงข้อความที่ไม่ซ้ำ
|
1599 |
+
for idx, entry in latest_messages.items():
|
1600 |
+
if entry['role'] == 'AI':
|
1601 |
+
if entry.get('is_starter'):
|
1602 |
+
# แสดงประโยคเริ่มต้นพิเศษ
|
1603 |
+
st.markdown(f"""
|
1604 |
+
<div style="background-color: #f0f7ff;
|
1605 |
+
padding: 15px;
|
1606 |
+
border-radius: 8px;
|
1607 |
+
margin: 5px 0;
|
1608 |
+
border-left: 4px solid #1e88e5;">
|
1609 |
+
<p style="color: #1e88e5; margin-bottom: 5px;">🎬 เริ่มเรื่อง:</p>
|
1610 |
+
<p style="color: #666;">{entry.get('thai_content', '')}</p>
|
1611 |
+
<p>{entry['content']}</p>
|
1612 |
+
</div>
|
1613 |
+
""", unsafe_allow_html=True)
|
1614 |
+
else:
|
1615 |
+
st.markdown(f"""
|
1616 |
+
<div style="padding: 10px; margin: 5px 0;">
|
1617 |
+
<p>🤖 AI: {entry['content']}</p>
|
1618 |
+
</div>
|
1619 |
+
""", unsafe_allow_html=True)
|
1620 |
+
elif entry['role'] == 'You':
|
1621 |
+
status_icon = "✅ " if entry.get('is_correct') else "✍️ "
|
1622 |
+
if entry.get('is_corrected'):
|
1623 |
+
# แสดงข้อความที่ถูกแก้ไขแล้ว
|
1624 |
+
st.markdown(f"""
|
1625 |
+
<div style="padding: 10px; margin: 5px 0; background-color: #f0f9ff; border-radius: 5px;">
|
1626 |
+
<p>👤 You: {status_icon}{entry['content']}</p>
|
1627 |
+
</div>
|
1628 |
+
""", unsafe_allow_html=True)
|
1629 |
+
else:
|
1630 |
+
# แสดงข้อความปกติ
|
1631 |
+
st.markdown(f"""
|
1632 |
+
<div style="padding: 10px; margin: 5px 0;">
|
1633 |
+
<p>👤 You: {status_icon}{entry['content']}</p>
|
1634 |
+
</div>
|
1635 |
+
""", unsafe_allow_html=True)
|
1636 |
+
|
1637 |
# แสดงผลคะแนนและความสำเร็จ
|
1638 |
def show_achievements():
|
1639 |
"""แสดงความสำเร็จและสถิติ"""
|