Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ st.set_page_config(page_title="Carfind.co.za AI Assistant", layout="wide")
|
|
| 14 |
st.title("🚗 Carfind.co.za AI Assistant")
|
| 15 |
st.caption("Chat with Carfind.co.za and find your next car fast")
|
| 16 |
|
| 17 |
-
# Custom CSS
|
| 18 |
st.markdown(
|
| 19 |
"""
|
| 20 |
<style>
|
|
@@ -36,9 +36,13 @@ st.markdown(
|
|
| 36 |
padding: 10px;
|
| 37 |
border-radius: 10px;
|
| 38 |
box-shadow: 0 0 15px rgba(0,0,0,0.5);
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
-
.
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
</style>
|
| 44 |
""",
|
|
@@ -79,12 +83,28 @@ else:
|
|
| 79 |
st.markdown(message["content"], unsafe_allow_html=True)
|
| 80 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
st.session_state.messages = []
|
| 87 |
-
st.rerun()
|
| 88 |
|
| 89 |
if openai_key:
|
| 90 |
client = OpenAI(api_key=openai_key)
|
|
@@ -140,4 +160,4 @@ else:
|
|
| 140 |
st.error(f"An error occurred: {str(e)}")
|
| 141 |
|
| 142 |
else:
|
| 143 |
-
st.error("OpenAI key not found. Please ensure it is set as a Hugging Face secret.")
|
|
|
|
| 14 |
st.title("🚗 Carfind.co.za AI Assistant")
|
| 15 |
st.caption("Chat with Carfind.co.za and find your next car fast")
|
| 16 |
|
| 17 |
+
# Custom CSS for styling chat input and clear button inside it
|
| 18 |
st.markdown(
|
| 19 |
"""
|
| 20 |
<style>
|
|
|
|
| 36 |
padding: 10px;
|
| 37 |
border-radius: 10px;
|
| 38 |
box-shadow: 0 0 15px rgba(0,0,0,0.5);
|
| 39 |
+
display: flex;
|
| 40 |
+
align-items: center;
|
| 41 |
}
|
| 42 |
+
.clear-chat-icon {
|
| 43 |
+
cursor: pointer;
|
| 44 |
+
margin-left: 10px;
|
| 45 |
+
font-size: 1.4em;
|
| 46 |
}
|
| 47 |
</style>
|
| 48 |
""",
|
|
|
|
| 83 |
st.markdown(message["content"], unsafe_allow_html=True)
|
| 84 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 85 |
|
| 86 |
+
# Custom chat input row with clear chat icon
|
| 87 |
+
with st.container():
|
| 88 |
+
user_input = st.chat_input("Type your message here...")
|
| 89 |
+
st.markdown(
|
| 90 |
+
"""
|
| 91 |
+
<script>
|
| 92 |
+
function clearChat() {
|
| 93 |
+
fetch(window.location.href, {
|
| 94 |
+
method: 'POST',
|
| 95 |
+
headers: {'Content-Type': 'application/json'},
|
| 96 |
+
body: JSON.stringify({"clear_chat": true})
|
| 97 |
+
}).then(() => location.reload());
|
| 98 |
+
}
|
| 99 |
+
</script>
|
| 100 |
+
<span class='clear-chat-icon' onclick='clearChat()'>🗑️</span>
|
| 101 |
+
""",
|
| 102 |
+
unsafe_allow_html=True
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
# Listen for clear chat POST
|
| 106 |
+
if st.experimental_get_query_params().get("clear_chat"):
|
| 107 |
st.session_state.messages = []
|
|
|
|
| 108 |
|
| 109 |
if openai_key:
|
| 110 |
client = OpenAI(api_key=openai_key)
|
|
|
|
| 160 |
st.error(f"An error occurred: {str(e)}")
|
| 161 |
|
| 162 |
else:
|
| 163 |
+
st.error("OpenAI key not found. Please ensure it is set as a Hugging Face secret.")
|