Update app.py
Browse files
app.py
CHANGED
@@ -1494,8 +1494,10 @@ def show_story():
|
|
1494 |
else:
|
1495 |
# Regular AI Response with ending mode indicator
|
1496 |
ending_info = ""
|
1497 |
-
|
1498 |
-
|
|
|
|
|
1499 |
|
1500 |
st.markdown(f"""
|
1501 |
<div style="
|
@@ -1521,8 +1523,10 @@ def show_story():
|
|
1521 |
border_color = "#4caf50" if entry.get('is_correct') else "#1e88e5"
|
1522 |
|
1523 |
ending_info = ""
|
1524 |
-
|
1525 |
-
|
|
|
|
|
1526 |
|
1527 |
st.markdown(f"""
|
1528 |
<div style="
|
@@ -1612,20 +1616,21 @@ def show_story_ending_options():
|
|
1612 |
def handle_ending_mode(text: str):
|
1613 |
"""Handle story submission during ending mode"""
|
1614 |
try:
|
|
|
1615 |
remaining = st.session_state.sentences_to_end
|
1616 |
-
|
1617 |
# Add user's sentence
|
1618 |
st.session_state.story.append({
|
1619 |
"role": "You",
|
1620 |
"content": text,
|
1621 |
"is_corrected": False,
|
1622 |
-
"is_correct": True,
|
1623 |
-
"timestamp": datetime.now().isoformat()
|
|
|
1624 |
})
|
1625 |
|
1626 |
-
# Decrease remaining count
|
1627 |
remaining -= 1
|
1628 |
-
st.session_state.sentences_to_end = remaining
|
1629 |
|
1630 |
if remaining > 0:
|
1631 |
# Generate AI's ending continuation
|
@@ -1635,14 +1640,19 @@ def handle_ending_mode(text: str):
|
|
1635 |
remaining_sentences=remaining
|
1636 |
)
|
1637 |
|
|
|
1638 |
st.session_state.story.append({
|
1639 |
"role": "AI",
|
1640 |
"content": ai_response,
|
1641 |
-
"timestamp": datetime.now().isoformat()
|
|
|
1642 |
})
|
1643 |
|
1644 |
# Decrease for AI's sentence
|
1645 |
-
|
|
|
|
|
|
|
1646 |
|
1647 |
else:
|
1648 |
# Generate final ending
|
@@ -1651,6 +1661,7 @@ def handle_ending_mode(text: str):
|
|
1651 |
st.session_state.ending_type
|
1652 |
)
|
1653 |
|
|
|
1654 |
st.session_state.story.append({
|
1655 |
"role": "AI",
|
1656 |
"content": final_response,
|
@@ -1662,7 +1673,7 @@ def handle_ending_mode(text: str):
|
|
1662 |
st.session_state.story_completed = True
|
1663 |
complete_story()
|
1664 |
|
1665 |
-
# Clear input
|
1666 |
st.session_state.story_input_area = ""
|
1667 |
st.rerun()
|
1668 |
|
|
|
1494 |
else:
|
1495 |
# Regular AI Response with ending mode indicator
|
1496 |
ending_info = ""
|
1497 |
+
# แสดงจำนวนประโยคที่เหลือเฉพาะเมื่ออยู่ในโหมดจบเรื่อง
|
1498 |
+
if (st.session_state.get('ending_mode') and
|
1499 |
+
'remaining_sentences' in entry):
|
1500 |
+
ending_info = f"🎭 เหลืออีก {entry['remaining_sentences']} ประโยค"
|
1501 |
|
1502 |
st.markdown(f"""
|
1503 |
<div style="
|
|
|
1523 |
border_color = "#4caf50" if entry.get('is_correct') else "#1e88e5"
|
1524 |
|
1525 |
ending_info = ""
|
1526 |
+
# แสดงจำนวนประโยคที่เหลือเฉพาะเมื่ออยู่ในโหมดจบเรื่อง
|
1527 |
+
if (st.session_state.get('ending_mode') and
|
1528 |
+
'remaining_sentences' in entry):
|
1529 |
+
ending_info = f"🎭 เหลืออีก {entry['remaining_sentences']} ประโยค"
|
1530 |
|
1531 |
st.markdown(f"""
|
1532 |
<div style="
|
|
|
1616 |
def handle_ending_mode(text: str):
|
1617 |
"""Handle story submission during ending mode"""
|
1618 |
try:
|
1619 |
+
# Get current remaining sentences
|
1620 |
remaining = st.session_state.sentences_to_end
|
1621 |
+
|
1622 |
# Add user's sentence
|
1623 |
st.session_state.story.append({
|
1624 |
"role": "You",
|
1625 |
"content": text,
|
1626 |
"is_corrected": False,
|
1627 |
+
"is_correct": True,
|
1628 |
+
"timestamp": datetime.now().isoformat(),
|
1629 |
+
"remaining_sentences": remaining # เพิ่มจำนวนประโยคที่เหลือ
|
1630 |
})
|
1631 |
|
1632 |
+
# Decrease remaining count for user's sentence
|
1633 |
remaining -= 1
|
|
|
1634 |
|
1635 |
if remaining > 0:
|
1636 |
# Generate AI's ending continuation
|
|
|
1640 |
remaining_sentences=remaining
|
1641 |
)
|
1642 |
|
1643 |
+
# Add AI response with remaining count
|
1644 |
st.session_state.story.append({
|
1645 |
"role": "AI",
|
1646 |
"content": ai_response,
|
1647 |
+
"timestamp": datetime.now().isoformat(),
|
1648 |
+
"remaining_sentences": remaining # เพิ่มจำนวนประโยคที่เหลือ
|
1649 |
})
|
1650 |
|
1651 |
# Decrease for AI's sentence
|
1652 |
+
remaining -= 1
|
1653 |
+
|
1654 |
+
# Update remaining sentences in session state
|
1655 |
+
st.session_state.sentences_to_end = remaining
|
1656 |
|
1657 |
else:
|
1658 |
# Generate final ending
|
|
|
1661 |
st.session_state.ending_type
|
1662 |
)
|
1663 |
|
1664 |
+
# Add final AI response
|
1665 |
st.session_state.story.append({
|
1666 |
"role": "AI",
|
1667 |
"content": final_response,
|
|
|
1673 |
st.session_state.story_completed = True
|
1674 |
complete_story()
|
1675 |
|
1676 |
+
# Clear input and rerun
|
1677 |
st.session_state.story_input_area = ""
|
1678 |
st.rerun()
|
1679 |
|