Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,32 +44,46 @@ Every response must be clear, insightful, and guide the user toward either:
|
|
| 44 |
# 🎨 Streamlit UI Customization
|
| 45 |
st.set_page_config(page_title="Eau Claire AI Chatbot", page_icon="🤖", layout="centered")
|
| 46 |
|
| 47 |
-
|
| 48 |
-
# ✅ Remove the white bar & Streamlit header
|
| 49 |
st.markdown(
|
| 50 |
"""
|
| 51 |
<style>
|
| 52 |
-
|
| 53 |
-
.block-container {
|
| 54 |
-
padding-top: 0px;
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
/* Hide the default header */
|
| 58 |
header { visibility: hidden; }
|
|
|
|
| 59 |
|
| 60 |
-
/*
|
| 61 |
-
.
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
-
</style>
|
| 65 |
-
""",
|
| 66 |
-
unsafe_allow_html=True
|
| 67 |
-
)
|
| 68 |
|
| 69 |
-
# ✅ Styled Chatbot Title (Fix)
|
| 70 |
-
st.markdown(
|
| 71 |
-
"""
|
| 72 |
-
<style>
|
| 73 |
.chat-title {
|
| 74 |
font-size: 24px;
|
| 75 |
font-weight: bold;
|
|
@@ -78,23 +92,29 @@ st.markdown(
|
|
| 78 |
margin-bottom: 15px;
|
| 79 |
}
|
| 80 |
</style>
|
| 81 |
-
<div class="chat-title">Eau Claire AI - AI Consulting Chatbot</div>
|
| 82 |
""",
|
| 83 |
unsafe_allow_html=True
|
| 84 |
)
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# ✅ Initialize chat history in session state
|
| 89 |
if "messages" not in st.session_state:
|
| 90 |
-
st.session_state.messages = [
|
| 91 |
|
| 92 |
-
# ✅ Display chat history
|
|
|
|
| 93 |
for message in st.session_state.messages:
|
| 94 |
if message["role"] == "user":
|
| 95 |
-
st.
|
| 96 |
elif message["role"] == "assistant":
|
| 97 |
-
st.
|
|
|
|
| 98 |
|
| 99 |
# ✅ User Input with "Enter" Key to Send
|
| 100 |
user_input = st.text_input("Type your message here:", key="input", on_change=lambda: st.session_state.update({"submit": True}))
|
|
@@ -110,7 +130,7 @@ if st.session_state.get("submit") and user_input:
|
|
| 110 |
# ✅ Generate AI response with full chat history
|
| 111 |
response = client.chat.completions.create(
|
| 112 |
model="gpt-3.5-turbo",
|
| 113 |
-
messages=st.session_state.messages
|
| 114 |
)
|
| 115 |
|
| 116 |
bot_reply = response.choices[0].message.content.strip()
|
|
@@ -118,7 +138,7 @@ if st.session_state.get("submit") and user_input:
|
|
| 118 |
# ✅ Append AI response to chat history
|
| 119 |
st.session_state.messages.append({"role": "assistant", "content": bot_reply})
|
| 120 |
|
| 121 |
-
# ✅
|
| 122 |
st.rerun()
|
| 123 |
|
| 124 |
except Exception as e:
|
|
|
|
| 44 |
# 🎨 Streamlit UI Customization
|
| 45 |
st.set_page_config(page_title="Eau Claire AI Chatbot", page_icon="🤖", layout="centered")
|
| 46 |
|
| 47 |
+
# ✅ Custom Styling for Better Readability
|
|
|
|
| 48 |
st.markdown(
|
| 49 |
"""
|
| 50 |
<style>
|
| 51 |
+
.block-container { padding-top: 0px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
header { visibility: hidden; }
|
| 53 |
+
.stApp { padding-top: 0px; }
|
| 54 |
|
| 55 |
+
/* Center the logo */
|
| 56 |
+
.logo-container {
|
| 57 |
+
display: flex;
|
| 58 |
+
justify-content: center;
|
| 59 |
+
margin-bottom: 10px;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/* Chat styling */
|
| 63 |
+
.chat-container {
|
| 64 |
+
width: 100%;
|
| 65 |
+
max-width: 600px;
|
| 66 |
+
margin: auto;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.user-message {
|
| 70 |
+
background-color: #0077cc;
|
| 71 |
+
color: white;
|
| 72 |
+
padding: 10px;
|
| 73 |
+
border-radius: 10px;
|
| 74 |
+
text-align: right;
|
| 75 |
+
margin: 5px 0;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.ai-message {
|
| 79 |
+
background-color: #333;
|
| 80 |
+
color: white;
|
| 81 |
+
padding: 10px;
|
| 82 |
+
border-radius: 10px;
|
| 83 |
+
text-align: left;
|
| 84 |
+
margin: 5px 0;
|
| 85 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
.chat-title {
|
| 88 |
font-size: 24px;
|
| 89 |
font-weight: bold;
|
|
|
|
| 92 |
margin-bottom: 15px;
|
| 93 |
}
|
| 94 |
</style>
|
|
|
|
| 95 |
""",
|
| 96 |
unsafe_allow_html=True
|
| 97 |
)
|
| 98 |
|
| 99 |
+
# ✅ Display Eau Cl•AI•re Logo (Change URL if needed)
|
| 100 |
+
logo_url = "https://huggingface.co/spaces/EauClaireAI/Chatbot/resolve/main/Eau%20Cl•AI•re.png"
|
| 101 |
+
st.markdown(f'<div class="logo-container"><img src="{logo_url}" width="200"></div>', unsafe_allow_html=True)
|
| 102 |
+
|
| 103 |
+
# ✅ Styled Chatbot Title
|
| 104 |
+
st.markdown('<div class="chat-title">Eau Claire AI - AI Consulting Chatbot</div>', unsafe_allow_html=True)
|
| 105 |
|
| 106 |
# ✅ Initialize chat history in session state
|
| 107 |
if "messages" not in st.session_state:
|
| 108 |
+
st.session_state.messages = []
|
| 109 |
|
| 110 |
+
# ✅ Display chat history with formatting
|
| 111 |
+
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
| 112 |
for message in st.session_state.messages:
|
| 113 |
if message["role"] == "user":
|
| 114 |
+
st.markdown(f'<div class="user-message">{message["content"]}</div>', unsafe_allow_html=True)
|
| 115 |
elif message["role"] == "assistant":
|
| 116 |
+
st.markdown(f'<div class="ai-message">{message["content"]}</div>', unsafe_allow_html=True)
|
| 117 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 118 |
|
| 119 |
# ✅ User Input with "Enter" Key to Send
|
| 120 |
user_input = st.text_input("Type your message here:", key="input", on_change=lambda: st.session_state.update({"submit": True}))
|
|
|
|
| 130 |
# ✅ Generate AI response with full chat history
|
| 131 |
response = client.chat.completions.create(
|
| 132 |
model="gpt-3.5-turbo",
|
| 133 |
+
messages=[{"role": "system", "content": system_prompt}] + st.session_state.messages
|
| 134 |
)
|
| 135 |
|
| 136 |
bot_reply = response.choices[0].message.content.strip()
|
|
|
|
| 138 |
# ✅ Append AI response to chat history
|
| 139 |
st.session_state.messages.append({"role": "assistant", "content": bot_reply})
|
| 140 |
|
| 141 |
+
# ✅ Refresh UI
|
| 142 |
st.rerun()
|
| 143 |
|
| 144 |
except Exception as e:
|