Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,7 +45,7 @@ Do not make any attempt to tell a guest that you will email them. I do not have
|
|
| 45 |
# 🎨 Streamlit UI Customization
|
| 46 |
st.set_page_config(page_title="Eau Claire AI Chatbot", page_icon="🤖", layout="centered")
|
| 47 |
|
| 48 |
-
# ✅ Custom Styling
|
| 49 |
st.markdown(
|
| 50 |
"""
|
| 51 |
<style>
|
|
@@ -92,12 +92,19 @@ st.markdown(
|
|
| 92 |
color: #0077cc; /* Eau Claire AI brand color */
|
| 93 |
margin-bottom: 15px;
|
| 94 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
</style>
|
| 96 |
""",
|
| 97 |
unsafe_allow_html=True
|
| 98 |
)
|
| 99 |
|
| 100 |
-
# ✅ Display Eau Cl•AI•re Logo
|
| 101 |
logo_url = "https://huggingface.co/spaces/EauClaireAI/Chatbot/resolve/main/Eau%20Cl•AI•re.png"
|
| 102 |
st.markdown(f'<div class="logo-container"><img src="{logo_url}" width="200"></div>', unsafe_allow_html=True)
|
| 103 |
|
|
@@ -108,7 +115,7 @@ st.markdown('<div class="chat-title">Eau Claire AI - AI Consulting Chatbot</div>
|
|
| 108 |
if "messages" not in st.session_state:
|
| 109 |
st.session_state.messages = []
|
| 110 |
|
| 111 |
-
# ✅ Display chat history
|
| 112 |
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
| 113 |
for message in st.session_state.messages:
|
| 114 |
if message["role"] == "user":
|
|
@@ -117,33 +124,45 @@ for message in st.session_state.messages:
|
|
| 117 |
st.markdown(f'<div class="ai-message">{message["content"]}</div>', unsafe_allow_html=True)
|
| 118 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 119 |
|
| 120 |
-
# ✅
|
| 121 |
-
if "
|
| 122 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
|
| 145 |
-
# ✅
|
|
|
|
|
|
|
| 146 |
st.rerun()
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# 🎨 Streamlit UI Customization
|
| 46 |
st.set_page_config(page_title="Eau Claire AI Chatbot", page_icon="🤖", layout="centered")
|
| 47 |
|
| 48 |
+
# ✅ Custom Styling
|
| 49 |
st.markdown(
|
| 50 |
"""
|
| 51 |
<style>
|
|
|
|
| 92 |
color: #0077cc; /* Eau Claire AI brand color */
|
| 93 |
margin-bottom: 15px;
|
| 94 |
}
|
| 95 |
+
|
| 96 |
+
.typing-indicator {
|
| 97 |
+
font-style: italic;
|
| 98 |
+
color: #999;
|
| 99 |
+
text-align: left;
|
| 100 |
+
margin-top: 5px;
|
| 101 |
+
}
|
| 102 |
</style>
|
| 103 |
""",
|
| 104 |
unsafe_allow_html=True
|
| 105 |
)
|
| 106 |
|
| 107 |
+
# ✅ Display Eau Cl•AI•re Logo
|
| 108 |
logo_url = "https://huggingface.co/spaces/EauClaireAI/Chatbot/resolve/main/Eau%20Cl•AI•re.png"
|
| 109 |
st.markdown(f'<div class="logo-container"><img src="{logo_url}" width="200"></div>', unsafe_allow_html=True)
|
| 110 |
|
|
|
|
| 115 |
if "messages" not in st.session_state:
|
| 116 |
st.session_state.messages = []
|
| 117 |
|
| 118 |
+
# ✅ Display chat history
|
| 119 |
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
| 120 |
for message in st.session_state.messages:
|
| 121 |
if message["role"] == "user":
|
|
|
|
| 124 |
st.markdown(f'<div class="ai-message">{message["content"]}</div>', unsafe_allow_html=True)
|
| 125 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 126 |
|
| 127 |
+
# ✅ AI Typing Indicator (Only shown if processing)
|
| 128 |
+
if "is_typing" in st.session_state and st.session_state.is_typing:
|
| 129 |
+
st.markdown('<div class="typing-indicator">AI is typing...</div>', unsafe_allow_html=True)
|
| 130 |
+
|
| 131 |
+
# ✅ User Input - Works with "Enter" Key & Button
|
| 132 |
+
def handle_message():
|
| 133 |
+
if st.session_state["input_text"]:
|
| 134 |
+
user_input = st.session_state["input_text"]
|
| 135 |
|
| 136 |
+
# ✅ Append user input to chat history
|
| 137 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 138 |
|
| 139 |
+
# ✅ Show AI is typing indicator
|
| 140 |
+
st.session_state.is_typing = True
|
| 141 |
+
st.rerun()
|
| 142 |
|
| 143 |
+
try:
|
| 144 |
+
# ✅ Generate AI response
|
| 145 |
+
response = client.chat.completions.create(
|
| 146 |
+
model="gpt-3.5-turbo",
|
| 147 |
+
messages=[{"role": "system", "content": system_prompt}] + st.session_state.messages
|
| 148 |
+
)
|
| 149 |
|
| 150 |
+
bot_reply = response.choices[0].message.content.strip()
|
| 151 |
|
| 152 |
+
# ✅ Append AI response to chat history
|
| 153 |
+
st.session_state.messages.append({"role": "assistant", "content": bot_reply})
|
| 154 |
|
| 155 |
+
except Exception as e:
|
| 156 |
+
st.session_state.messages.append({"role": "assistant", "content": f"Error: {str(e)}"})
|
| 157 |
|
| 158 |
+
# ✅ Reset input field and remove typing indicator
|
| 159 |
+
st.session_state["input_text"] = ""
|
| 160 |
+
st.session_state.is_typing = False
|
| 161 |
st.rerun()
|
| 162 |
|
| 163 |
+
# ✅ Input Field
|
| 164 |
+
user_input = st.text_input("Type your message here:", key="input_text", on_change=handle_message)
|
| 165 |
+
|
| 166 |
+
# ✅ Send Button (Optional)
|
| 167 |
+
if st.button("Send"):
|
| 168 |
+
handle_message()
|