Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,9 @@ from transformers import pipeline
|
|
3 |
from PIL import Image
|
4 |
from datetime import time
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
st.title("USC GPT - Find the perfect class")
|
8 |
|
@@ -16,4 +19,35 @@ units = st.slider(
|
|
16 |
"Number of units",
|
17 |
1, 4,
|
18 |
value = (1, 4)
|
19 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from PIL import Image
|
4 |
from datetime import time
|
5 |
|
6 |
+
if "messages" not in st.session_state:
|
7 |
+
st.session_state.messages = []
|
8 |
+
|
9 |
|
10 |
st.title("USC GPT - Find the perfect class")
|
11 |
|
|
|
19 |
"Number of units",
|
20 |
1, 4,
|
21 |
value = (1, 4)
|
22 |
+
)
|
23 |
+
|
24 |
+
|
25 |
+
for message in st.session_state.messages:
|
26 |
+
with st.chat_message(message["role"]):
|
27 |
+
st.markdown(message["content"])
|
28 |
+
|
29 |
+
if prompt := st.chat_input("What kind of class are you looking for?"):
|
30 |
+
# Display user message in chat message container
|
31 |
+
with st.chat_message("user"):
|
32 |
+
st.markdown(prompt)
|
33 |
+
# Add user message to chat history
|
34 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
### GPT Response
|
39 |
+
# Display assistant response in chat message container
|
40 |
+
with st.chat_message("assistant"):
|
41 |
+
message_placeholder = st.empty()
|
42 |
+
full_response = ""
|
43 |
+
assistant_response = "Hello there! How can I assist you today?"
|
44 |
+
)
|
45 |
+
# Simulate stream of response with milliseconds delay
|
46 |
+
for chunk in assistant_response.split():
|
47 |
+
full_response += chunk + " "
|
48 |
+
time.sleep(0.05)
|
49 |
+
# Add a blinking cursor to simulate typing
|
50 |
+
message_placeholder.markdown(full_response + "▌")
|
51 |
+
message_placeholder.markdown(full_response)
|
52 |
+
# Add assistant response to chat history
|
53 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|