Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
|
|
2 |
from streamlit_chat import message
|
3 |
from openai import OpenAI
|
4 |
import time
|
5 |
-
import datetime
|
6 |
import os
|
7 |
|
8 |
generated_user = os.getenv("User")
|
@@ -14,11 +13,12 @@ st.set_page_config(page_title="Carfind.co.za AI Assistant", layout="wide")
|
|
14 |
st.markdown("<h1 style='text-align: center;'>🚗 Carfind.co.za AI Assistant</h1>", unsafe_allow_html=True)
|
15 |
st.caption("Chat with Carfind.co.za and find your next car fast")
|
16 |
|
|
|
17 |
st.markdown("""
|
18 |
<style>
|
19 |
.stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; }
|
20 |
-
.stChatMessage[data-testid="stChatMessage-user"] { background: #
|
21 |
-
.stChatMessage[data-testid="stChatMessage-assistant"] { background: #
|
22 |
</style>
|
23 |
""", unsafe_allow_html=True)
|
24 |
|
@@ -84,22 +84,27 @@ else:
|
|
84 |
break
|
85 |
time.sleep(1)
|
86 |
|
87 |
-
#
|
88 |
messages_response = client.beta.threads.messages.list(
|
89 |
thread_id=st.session_state["thread_id"]
|
90 |
)
|
91 |
|
92 |
-
#
|
93 |
assistant_icon_html = "<img src='https://www.carfind.co.za/images/Carfind-Icon.svg' width='22' style='vertical-align:middle;'/>"
|
94 |
|
95 |
-
# Display
|
96 |
for msg in reversed(messages_response.data):
|
97 |
if msg.role == "user":
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
else:
|
100 |
-
# Use markdown manually to render inline icon and text
|
101 |
st.markdown(
|
102 |
-
f"<div style='background-color:#
|
103 |
f"{assistant_icon_html} <strong>Carfind Assistant:</strong> {msg.content[0].text.value}"
|
104 |
f"</div>",
|
105 |
unsafe_allow_html=True
|
|
|
2 |
from streamlit_chat import message
|
3 |
from openai import OpenAI
|
4 |
import time
|
|
|
5 |
import os
|
6 |
|
7 |
generated_user = os.getenv("User")
|
|
|
13 |
st.markdown("<h1 style='text-align: center;'>🚗 Carfind.co.za AI Assistant</h1>", unsafe_allow_html=True)
|
14 |
st.caption("Chat with Carfind.co.za and find your next car fast")
|
15 |
|
16 |
+
# Updated styling for readability
|
17 |
st.markdown("""
|
18 |
<style>
|
19 |
.stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; }
|
20 |
+
.stChatMessage[data-testid="stChatMessage-user"] { background: #f0f0f0; color: #000000; }
|
21 |
+
.stChatMessage[data-testid="stChatMessage-assistant"] { background: #D6E9FE; color: #000000; }
|
22 |
</style>
|
23 |
""", unsafe_allow_html=True)
|
24 |
|
|
|
84 |
break
|
85 |
time.sleep(1)
|
86 |
|
87 |
+
# Retrieve entire conversation history
|
88 |
messages_response = client.beta.threads.messages.list(
|
89 |
thread_id=st.session_state["thread_id"]
|
90 |
)
|
91 |
|
92 |
+
# Assistant icon
|
93 |
assistant_icon_html = "<img src='https://www.carfind.co.za/images/Carfind-Icon.svg' width='22' style='vertical-align:middle;'/>"
|
94 |
|
95 |
+
# Display conversation
|
96 |
for msg in reversed(messages_response.data):
|
97 |
if msg.role == "user":
|
98 |
+
# Add simple user avatar (👤) for each message
|
99 |
+
st.markdown(
|
100 |
+
f"<div style='background-color:#f0f0f0; color:#000000; padding:10px; border-radius:8px; margin:5px 0;'>"
|
101 |
+
f"👤 <strong>You:</strong> {msg.content[0].text.value}"
|
102 |
+
f"</div>",
|
103 |
+
unsafe_allow_html=True
|
104 |
+
)
|
105 |
else:
|
|
|
106 |
st.markdown(
|
107 |
+
f"<div style='background-color:#D6E9FE; color:#000000; padding:10px; border-radius:8px; margin:5px 0;'>"
|
108 |
f"{assistant_icon_html} <strong>Carfind Assistant:</strong> {msg.content[0].text.value}"
|
109 |
f"</div>",
|
110 |
unsafe_allow_html=True
|