Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ from reportlab.pdfgen import canvas
|
|
12 |
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
|
13 |
from reportlab.pdfbase import pdfmetrics
|
14 |
from reportlab.pdfbase.ttfonts import TTFont
|
15 |
-
from datetime import datetime
|
16 |
from typing import Dict, List, Optional, Tuple
|
17 |
import random
|
18 |
|
@@ -428,13 +428,15 @@ def init_session_state():
|
|
428 |
'streak': 0,
|
429 |
'max_streak': 0
|
430 |
}
|
|
|
|
|
431 |
if 'stats' not in st.session_state:
|
432 |
st.session_state.stats = {
|
433 |
'total_sentences': 0,
|
434 |
'correct_first_try': 0,
|
435 |
'accuracy_rate': 0.0,
|
436 |
-
'vocabulary_used': set()
|
437 |
-
|
438 |
if 'achievements' not in st.session_state:
|
439 |
st.session_state.achievements = []
|
440 |
|
@@ -1326,6 +1328,7 @@ def apply_correction(story_index: int, corrected_text: str):
|
|
1326 |
"""Apply correction to a specific story entry."""
|
1327 |
if 0 <= story_index < len(st.session_state.story):
|
1328 |
original_text = st.session_state.story[story_index]['content']
|
|
|
1329 |
# เก็บประวัติการแก้ไข
|
1330 |
if 'corrections' not in st.session_state:
|
1331 |
st.session_state.corrections = {}
|
@@ -1333,14 +1336,21 @@ def apply_correction(story_index: int, corrected_text: str):
|
|
1333 |
st.session_state.corrections[story_index] = {
|
1334 |
'original': original_text,
|
1335 |
'corrected': corrected_text,
|
1336 |
-
'timestamp': datetime.
|
1337 |
}
|
|
|
1338 |
# แก้ไขประโยคในเรื่อง
|
1339 |
st.session_state.story[story_index]['content'] = corrected_text
|
1340 |
st.session_state.story[story_index]['is_corrected'] = True
|
1341 |
|
1342 |
# แสดงข้อความยืนยันการแก้ไข
|
1343 |
st.success("✅ แก้ไขประโยคเรียบร้อยแล้ว!")
|
|
|
|
|
|
|
|
|
|
|
|
|
1344 |
|
1345 |
def get_vocabulary_suggestions() -> List[str]:
|
1346 |
"""Get contextual vocabulary suggestions with Thai translations."""
|
|
|
12 |
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
|
13 |
from reportlab.pdfbase import pdfmetrics
|
14 |
from reportlab.pdfbase.ttfonts import TTFont
|
15 |
+
from datetime import datetime
|
16 |
from typing import Dict, List, Optional, Tuple
|
17 |
import random
|
18 |
|
|
|
428 |
'streak': 0,
|
429 |
'max_streak': 0
|
430 |
}
|
431 |
+
if 'corrections' not in st.session_state:
|
432 |
+
st.session_state.corrections = {}
|
433 |
if 'stats' not in st.session_state:
|
434 |
st.session_state.stats = {
|
435 |
'total_sentences': 0,
|
436 |
'correct_first_try': 0,
|
437 |
'accuracy_rate': 0.0,
|
438 |
+
'vocabulary_used': set(),
|
439 |
+
'corrections_made': 0
|
440 |
if 'achievements' not in st.session_state:
|
441 |
st.session_state.achievements = []
|
442 |
|
|
|
1328 |
"""Apply correction to a specific story entry."""
|
1329 |
if 0 <= story_index < len(st.session_state.story):
|
1330 |
original_text = st.session_state.story[story_index]['content']
|
1331 |
+
|
1332 |
# เก็บประวัติการแก้ไข
|
1333 |
if 'corrections' not in st.session_state:
|
1334 |
st.session_state.corrections = {}
|
|
|
1336 |
st.session_state.corrections[story_index] = {
|
1337 |
'original': original_text,
|
1338 |
'corrected': corrected_text,
|
1339 |
+
'timestamp': datetime.now().isoformat() # แก้จาก datetime.datetime.now()
|
1340 |
}
|
1341 |
+
|
1342 |
# แก้ไขประโยคในเรื่อง
|
1343 |
st.session_state.story[story_index]['content'] = corrected_text
|
1344 |
st.session_state.story[story_index]['is_corrected'] = True
|
1345 |
|
1346 |
# แสดงข้อความยืนยันการแก้ไข
|
1347 |
st.success("✅ แก้ไขประโยคเรียบร้อยแล้ว!")
|
1348 |
+
|
1349 |
+
# อัพเดทสถิติ (ถ้ามี)
|
1350 |
+
if 'stats' in st.session_state:
|
1351 |
+
# อาจเพิ่มการนับจำนวนครั้งที่แก้ไข
|
1352 |
+
st.session_state.stats['corrections_made'] = \
|
1353 |
+
st.session_state.stats.get('corrections_made', 0) + 1
|
1354 |
|
1355 |
def get_vocabulary_suggestions() -> List[str]:
|
1356 |
"""Get contextual vocabulary suggestions with Thai translations."""
|