Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,44 +55,9 @@ st.markdown("""
|
|
| 55 |
.stChatMessage[data-testid="stChatMessage-user"] { background: #f0f0f0; color: #000000; }
|
| 56 |
.stChatMessage[data-testid="stChatMessage-assistant"] { background: #e3f2fd; color: #000000; }
|
| 57 |
.lt-logo { vertical-align: middle; }
|
| 58 |
-
|
| 59 |
-
.
|
| 60 |
-
|
| 61 |
-
bottom: 0;
|
| 62 |
-
left: 50%;
|
| 63 |
-
transform: translateX(-50%);
|
| 64 |
-
width: 60vw;
|
| 65 |
-
min-width: 300px;
|
| 66 |
-
max-width: 900px;
|
| 67 |
-
z-index: 1000;
|
| 68 |
-
background: #fff;
|
| 69 |
-
border-radius: 1em 1em 0 0;
|
| 70 |
-
box-shadow: 0 -2px 16px rgba(0,0,0,0.07);
|
| 71 |
-
padding: 1em 1em 0.7em 1em;
|
| 72 |
-
display: flex;
|
| 73 |
-
align-items: center;
|
| 74 |
-
}
|
| 75 |
-
.floating-input-bar .chat-input {
|
| 76 |
-
flex: 1 1 auto;
|
| 77 |
-
border-radius: 14px;
|
| 78 |
-
border: 1px solid #d2d2d2;
|
| 79 |
-
padding: 0.7em 1em;
|
| 80 |
-
font-size: 1.1em;
|
| 81 |
-
margin-right: 0.7em;
|
| 82 |
-
}
|
| 83 |
-
.floating-input-bar .clear-btn {
|
| 84 |
-
border: none;
|
| 85 |
-
background: transparent;
|
| 86 |
-
font-size: 1.5em;
|
| 87 |
-
color: #888;
|
| 88 |
-
cursor: pointer;
|
| 89 |
-
margin-left: 0.1em;
|
| 90 |
-
margin-top: 1px;
|
| 91 |
-
transition: color 0.1s;
|
| 92 |
-
}
|
| 93 |
-
.floating-input-bar .clear-btn:hover { color: #e57373; }
|
| 94 |
-
/* Push main content up above floating bar */
|
| 95 |
-
.main-chat-area { margin-bottom: 5em; }
|
| 96 |
</style>
|
| 97 |
""", unsafe_allow_html=True)
|
| 98 |
st.markdown("""
|
|
@@ -161,7 +126,7 @@ def clear_chat_history():
|
|
| 161 |
st.rerun()
|
| 162 |
|
| 163 |
def display_chat_history():
|
| 164 |
-
st.markdown("<div class='
|
| 165 |
messages = db.collection("users").document(user_id).collection("messages").order_by("timestamp").stream()
|
| 166 |
assistant_icon_html = "<img src='https://raw.githubusercontent.com/AndrewLORTech/lortechwebsite/main/lorain.jpg' width='24' style='vertical-align:middle; border-radius:50%;'/>"
|
| 167 |
for msg in list(messages)[::-1]:
|
|
@@ -201,44 +166,12 @@ def synthesize_voice(text, voice_key, user_id):
|
|
| 201 |
thread_id = get_or_create_thread_id()
|
| 202 |
display_chat_history()
|
| 203 |
|
| 204 |
-
# ---
|
| 205 |
-
st.
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
</form>
|
| 211 |
-
<script>
|
| 212 |
-
// Auto-focus and scroll to bottom on new message
|
| 213 |
-
let chatbox = document.getElementById("chatbox");
|
| 214 |
-
if (chatbox) chatbox.scrollTop = chatbox.scrollHeight;
|
| 215 |
-
</script>
|
| 216 |
-
</div>
|
| 217 |
-
""", unsafe_allow_html=True)
|
| 218 |
-
|
| 219 |
-
# --- Handle Chat Input/Clear POST ---
|
| 220 |
-
import streamlit.web.server.websocket_headers
|
| 221 |
-
from urllib.parse import parse_qs
|
| 222 |
-
|
| 223 |
-
# Use query params to emulate form submission state (for Streamlit stateless-ness)
|
| 224 |
-
query_params = st.experimental_get_query_params()
|
| 225 |
-
import streamlit.runtime.scriptrunner.script_run_context as sctx
|
| 226 |
-
ctx = sctx.get_script_run_ctx()
|
| 227 |
-
form_data = {}
|
| 228 |
-
if ctx and hasattr(ctx, 'request'):
|
| 229 |
-
content_length = ctx.request.headers.get('content-length')
|
| 230 |
-
if content_length:
|
| 231 |
-
body = ctx.request.rfile.read(int(content_length)).decode()
|
| 232 |
-
form_data = parse_qs(body)
|
| 233 |
-
|
| 234 |
-
# Detect clear chat
|
| 235 |
-
if form_data.get("clear_chat"):
|
| 236 |
-
clear_chat_history()
|
| 237 |
-
|
| 238 |
-
# Detect user input
|
| 239 |
-
user_input = ""
|
| 240 |
-
if form_data.get("lorain_user_input"):
|
| 241 |
-
user_input = form_data.get("lorain_user_input")[0].strip()
|
| 242 |
|
| 243 |
if user_input:
|
| 244 |
# --- OpenAI Assistant Response ---
|
|
|
|
| 55 |
.stChatMessage[data-testid="stChatMessage-user"] { background: #f0f0f0; color: #000000; }
|
| 56 |
.stChatMessage[data-testid="stChatMessage-assistant"] { background: #e3f2fd; color: #000000; }
|
| 57 |
.lt-logo { vertical-align: middle; }
|
| 58 |
+
.fixed-bottom-bar { position: fixed; bottom: 0; left: 0; width: 100vw; background: #181a22; padding: 1.2em 0.5em 0.8em 0.5em; z-index: 9999; box-shadow: 0 -2px 8px rgba(0,0,0,0.06);}
|
| 59 |
+
.chat-area { margin-bottom: 6.1em; }
|
| 60 |
+
.st-emotion-cache-1avcm0n { justify-content: flex-end !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
</style>
|
| 62 |
""", unsafe_allow_html=True)
|
| 63 |
st.markdown("""
|
|
|
|
| 126 |
st.rerun()
|
| 127 |
|
| 128 |
def display_chat_history():
|
| 129 |
+
st.markdown("<div class='chat-area'>", unsafe_allow_html=True)
|
| 130 |
messages = db.collection("users").document(user_id).collection("messages").order_by("timestamp").stream()
|
| 131 |
assistant_icon_html = "<img src='https://raw.githubusercontent.com/AndrewLORTech/lortechwebsite/main/lorain.jpg' width='24' style='vertical-align:middle; border-radius:50%;'/>"
|
| 132 |
for msg in list(messages)[::-1]:
|
|
|
|
| 166 |
thread_id = get_or_create_thread_id()
|
| 167 |
display_chat_history()
|
| 168 |
|
| 169 |
+
# --- Fixed bottom bar: input + clear chat ---
|
| 170 |
+
with st.container():
|
| 171 |
+
cols = st.columns([10, 1])
|
| 172 |
+
user_input = cols[0].chat_input("Type your message here...")
|
| 173 |
+
if cols[1].button("🗑️", help="Clear Chat"):
|
| 174 |
+
clear_chat_history()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
if user_input:
|
| 177 |
# --- OpenAI Assistant Response ---
|