Spaces:
Sleeping
Sleeping
Commit
Β·
7e727b6
1
Parent(s):
24b6129
button not active
Browse files
app.py
CHANGED
@@ -20,11 +20,13 @@ def remove_citation(text: str) -> str:
|
|
20 |
pattern = r"γ\d+β \w+γ"
|
21 |
return re.sub(pattern, "π", text)
|
22 |
|
23 |
-
# Initialize session state for messages and
|
24 |
if "messages" not in st.session_state:
|
25 |
st.session_state["messages"] = []
|
26 |
if "thread_id" not in st.session_state:
|
27 |
st.session_state["thread_id"] = None
|
|
|
|
|
28 |
|
29 |
st.title("Solution Specifier A")
|
30 |
|
@@ -54,23 +56,35 @@ for msg in st.session_state["messages"]:
|
|
54 |
st.write(msg["content"])
|
55 |
|
56 |
# Create the chat input widget at the bottom of the page
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# When the user hits ENTER on st.chat_input
|
60 |
-
if user_input:
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
with st.chat_message("assistant"):
|
76 |
-
st.write(response_text)
|
|
|
20 |
pattern = r"γ\d+β \w+γ"
|
21 |
return re.sub(pattern, "π", text)
|
22 |
|
23 |
+
# Initialize session state for messages, thread_id and processing state
|
24 |
if "messages" not in st.session_state:
|
25 |
st.session_state["messages"] = []
|
26 |
if "thread_id" not in st.session_state:
|
27 |
st.session_state["thread_id"] = None
|
28 |
+
if "is_processing" not in st.session_state:
|
29 |
+
st.session_state["is_processing"] = False
|
30 |
|
31 |
st.title("Solution Specifier A")
|
32 |
|
|
|
56 |
st.write(msg["content"])
|
57 |
|
58 |
# Create the chat input widget at the bottom of the page
|
59 |
+
# Disable it while processing a message
|
60 |
+
user_input = st.chat_input(
|
61 |
+
"Type your message here...",
|
62 |
+
disabled=st.session_state["is_processing"]
|
63 |
+
)
|
64 |
|
65 |
# When the user hits ENTER on st.chat_input
|
66 |
+
if user_input and not st.session_state["is_processing"]:
|
67 |
+
try:
|
68 |
+
# Set processing state to True
|
69 |
+
st.session_state["is_processing"] = True
|
70 |
+
|
71 |
+
# Add the user message to session state
|
72 |
+
st.session_state["messages"].append({"role": "user", "content": user_input})
|
73 |
+
|
74 |
+
# Display the user's message
|
75 |
+
with st.chat_message("user"):
|
76 |
+
st.write(user_input)
|
77 |
+
|
78 |
+
# Get the assistant's response
|
79 |
+
response_text = predict(user_input)
|
80 |
+
|
81 |
+
# Add the assistant response to session state
|
82 |
+
st.session_state["messages"].append({"role": "assistant", "content": response_text})
|
83 |
|
84 |
+
# Display the assistant's reply
|
85 |
+
with st.chat_message("assistant"):
|
86 |
+
st.write(response_text)
|
87 |
+
|
88 |
+
finally:
|
89 |
+
# Reset processing state when done
|
90 |
+
st.session_state["is_processing"] = False
|
|
|
|