Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,21 +5,17 @@ import time
|
|
5 |
import datetime
|
6 |
import os
|
7 |
|
8 |
-
# Load secrets from Hugging Face environment
|
9 |
generated_user = os.getenv("User")
|
10 |
generated_password = os.getenv("Password")
|
11 |
openai_key = os.getenv("openai_key")
|
12 |
assistant_id = os.getenv("ASSISTANT_ID")
|
13 |
|
14 |
-
# Streamlit page setup
|
15 |
st.set_page_config(page_title="Carfind.co.za AI Assistant", layout="wide")
|
16 |
st.markdown("<h1 style='text-align: center;'>π Carfind.co.za AI Assistant</h1>", unsafe_allow_html=True)
|
17 |
st.caption("Chat with Carfind.co.za and find your next car fast")
|
18 |
|
19 |
-
# Light / Dark mode toggle
|
20 |
dark_mode = st.toggle("π Switch to Light Mode", value=True)
|
21 |
|
22 |
-
# Custom styling for bubbles
|
23 |
st.markdown("""
|
24 |
<style>
|
25 |
.stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; }
|
@@ -28,7 +24,6 @@ st.markdown("""
|
|
28 |
</style>
|
29 |
""", unsafe_allow_html=True)
|
30 |
|
31 |
-
# Authentication
|
32 |
if "authenticated" not in st.session_state:
|
33 |
st.session_state.authenticated = False
|
34 |
|
@@ -46,21 +41,18 @@ if not st.session_state.authenticated:
|
|
46 |
else:
|
47 |
st.error("Incorrect username or password. Please try again.")
|
48 |
|
49 |
-
# Chat UI after login
|
50 |
else:
|
51 |
st.divider()
|
52 |
|
53 |
if "messages" not in st.session_state:
|
54 |
st.session_state["messages"] = []
|
55 |
|
56 |
-
# Show chat history
|
57 |
for msg in st.session_state["messages"]:
|
58 |
if msg["role"] == "assistant":
|
59 |
-
message(
|
60 |
else:
|
61 |
message(msg["content"], is_user=True, avatar_style="adventurer")
|
62 |
|
63 |
-
# Input and Clear Chat button
|
64 |
input_col, clear_col = st.columns([8, 1])
|
65 |
with input_col:
|
66 |
user_input = st.text_input("Type your message here...", key="chat_input")
|
@@ -101,7 +93,7 @@ else:
|
|
101 |
assistant_reply = client.beta.threads.messages.list(thread_id=thread.id).data[0].content[0].text.value
|
102 |
|
103 |
st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
|
104 |
-
message(
|
105 |
|
106 |
save_transcript(st.session_state.messages)
|
107 |
|
|
|
5 |
import datetime
|
6 |
import os
|
7 |
|
|
|
8 |
generated_user = os.getenv("User")
|
9 |
generated_password = os.getenv("Password")
|
10 |
openai_key = os.getenv("openai_key")
|
11 |
assistant_id = os.getenv("ASSISTANT_ID")
|
12 |
|
|
|
13 |
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 |
dark_mode = st.toggle("π Switch to Light Mode", value=True)
|
18 |
|
|
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
.stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; }
|
|
|
24 |
</style>
|
25 |
""", unsafe_allow_html=True)
|
26 |
|
|
|
27 |
if "authenticated" not in st.session_state:
|
28 |
st.session_state.authenticated = False
|
29 |
|
|
|
41 |
else:
|
42 |
st.error("Incorrect username or password. Please try again.")
|
43 |
|
|
|
44 |
else:
|
45 |
st.divider()
|
46 |
|
47 |
if "messages" not in st.session_state:
|
48 |
st.session_state["messages"] = []
|
49 |
|
|
|
50 |
for msg in st.session_state["messages"]:
|
51 |
if msg["role"] == "assistant":
|
52 |
+
message(msg['content'], is_user=False, avatar_url="https://www.carfind.co.za/images/Carfind-Icon.svg")
|
53 |
else:
|
54 |
message(msg["content"], is_user=True, avatar_style="adventurer")
|
55 |
|
|
|
56 |
input_col, clear_col = st.columns([8, 1])
|
57 |
with input_col:
|
58 |
user_input = st.text_input("Type your message here...", key="chat_input")
|
|
|
93 |
assistant_reply = client.beta.threads.messages.list(thread_id=thread.id).data[0].content[0].text.value
|
94 |
|
95 |
st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
|
96 |
+
message(assistant_reply, is_user=False, avatar_url="https://www.carfind.co.za/images/Carfind-Icon.svg")
|
97 |
|
98 |
save_transcript(st.session_state.messages)
|
99 |
|