Update app.py
Browse files
app.py
CHANGED
@@ -505,6 +505,11 @@ def init_session_state():
|
|
505 |
if key not in st.session_state:
|
506 |
st.session_state[key] = value
|
507 |
|
|
|
|
|
|
|
|
|
|
|
508 |
def init_theme_state():
|
509 |
"""Initialize theme-specific state variables"""
|
510 |
if 'current_theme' not in st.session_state:
|
@@ -1727,15 +1732,30 @@ def show_story_input():
|
|
1727 |
</div>
|
1728 |
""", unsafe_allow_html=True)
|
1729 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1730 |
# Input area
|
1731 |
text_input = st.text_area(
|
1732 |
"เขียนต่อจากเรื่องราว | Continue the story:",
|
|
|
1733 |
height=100,
|
1734 |
key="story_input_area",
|
1735 |
help="พิมพ์ประโยคภาษาอังกฤษเพื่อต่อเรื่อง",
|
1736 |
label_visibility="collapsed"
|
1737 |
)
|
1738 |
|
|
|
|
|
|
|
1739 |
# Submit button with character count
|
1740 |
col1, col2 = st.columns([3, 1])
|
1741 |
with col1:
|
@@ -1801,8 +1821,11 @@ def handle_story_submission(text: str):
|
|
1801 |
# Update session stats
|
1802 |
update_session_stats()
|
1803 |
|
1804 |
-
#
|
1805 |
-
st.session_state.
|
|
|
|
|
|
|
1806 |
|
1807 |
except Exception as e:
|
1808 |
logging.error(f"Error in story submission: {str(e)}")
|
|
|
505 |
if key not in st.session_state:
|
506 |
st.session_state[key] = value
|
507 |
|
508 |
+
if 'clear_input' not in st.session_state:
|
509 |
+
st.session_state.clear_input = False
|
510 |
+
if 'text_input' not in st.session_state:
|
511 |
+
st.session_state.text_input = ""
|
512 |
+
|
513 |
def init_theme_state():
|
514 |
"""Initialize theme-specific state variables"""
|
515 |
if 'current_theme' not in st.session_state:
|
|
|
1732 |
</div>
|
1733 |
""", unsafe_allow_html=True)
|
1734 |
|
1735 |
+
# Initialize clear_input flag if not exists
|
1736 |
+
if 'clear_input' not in st.session_state:
|
1737 |
+
st.session_state.clear_input = False
|
1738 |
+
|
1739 |
+
# Default value for text input
|
1740 |
+
default_value = "" if st.session_state.clear_input else st.session_state.get('text_input', "")
|
1741 |
+
|
1742 |
+
# If clear_input flag is True, reset it
|
1743 |
+
if st.session_state.clear_input:
|
1744 |
+
st.session_state.clear_input = False
|
1745 |
+
|
1746 |
# Input area
|
1747 |
text_input = st.text_area(
|
1748 |
"เขียนต่อจากเรื่องราว | Continue the story:",
|
1749 |
+
value=default_value,
|
1750 |
height=100,
|
1751 |
key="story_input_area",
|
1752 |
help="พิมพ์ประโยคภาษาอังกฤษเพื่อต่อเรื่อง",
|
1753 |
label_visibility="collapsed"
|
1754 |
)
|
1755 |
|
1756 |
+
# Save current input to session state
|
1757 |
+
st.session_state.text_input = text_input
|
1758 |
+
|
1759 |
# Submit button with character count
|
1760 |
col1, col2 = st.columns([3, 1])
|
1761 |
with col1:
|
|
|
1821 |
# Update session stats
|
1822 |
update_session_stats()
|
1823 |
|
1824 |
+
# Set flag to clear input on next rerun
|
1825 |
+
st.session_state.clear_input = True
|
1826 |
+
|
1827 |
+
# Rerun to update UI
|
1828 |
+
st.rerun()
|
1829 |
|
1830 |
except Exception as e:
|
1831 |
logging.error(f"Error in story submission: {str(e)}")
|