IAMTFRMZA commited on
Commit
95f3d98
·
verified ·
1 Parent(s): 745e01a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -30
app.py CHANGED
@@ -46,7 +46,7 @@ if "last_audio_path" not in st.session_state:
46
  if "selected_voice" not in st.session_state:
47
  st.session_state["selected_voice"] = "Jenny (US, Female)"
48
 
49
- # --- CSS for logo, chat, and input bar at top ---
50
  st.markdown("""
51
  <style>
52
  .block-container {padding-top: 1rem;}
@@ -57,36 +57,63 @@ st.markdown("""
57
  display: block;
58
  }
59
  .lor-brand-bar {
60
- width: 100vw; text-align: center; background: none;
61
- margin-bottom: 0.5em; margin-top: 0.1em;
 
 
 
 
62
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  .stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; margin-bottom: 10px; }
64
  .stChatMessage[data-testid="stChatMessage-user"] { background: #f0f0f0; color: #000000; }
65
  .stChatMessage[data-testid="stChatMessage-assistant"] { background: #e3f2fd; color: #000000; }
 
66
  .chat-history-wrapper {
67
- margin-top: 0.5em; padding-bottom: 2em; min-height: 60vh;
 
 
68
  }
69
- .input-top-bar {
70
- position: sticky; top: 0; z-index: 20;
71
- background: #191b22; padding: 0.5em 0 0.25em 0;
72
- display: flex; align-items: center; gap: 0.4em;
73
- border-bottom: 1px solid #22232c;
 
 
 
 
74
  }
75
- .input-top-bar .element-container { flex: 1 1 auto; }
76
- .input-top-bar input { font-size: 1.12em !important; }
77
- .clear-chat-btn { background: none; border: none; font-size: 1.4em; color: #666; cursor: pointer; }
78
  </style>
79
  """, unsafe_allow_html=True)
80
 
81
- # --- Top Branding, Mini Logo ---
82
  st.markdown("""
83
  <div class="lor-brand-bar">
84
  <img src="https://i0.wp.com/c2group.co.za/wp-content/uploads/2022/10/cropped-1_C2-Group-Technologies-Logo-2-1.png?w=1024&ssl=1" class="logo-mini" />
85
  <div style="font-size: 13px; color: #888;">Powered by C2 Group</div>
 
86
  </div>
87
  """, unsafe_allow_html=True)
88
 
89
- # --- Sidebar: audio/voice controls
90
  with st.sidebar:
91
  st.markdown("### Voice Settings & Controls")
92
  selected_voice = st.selectbox(
@@ -141,7 +168,7 @@ def display_chat_history():
141
  assistant_icon_html = "<img src='https://img.freepik.com/free-vector/graident-ai-robot-vectorart_78370-4114.jpg?semt=ais_hybrid&w=740' width='22' style='vertical-align:middle; border-radius:50%;'/>"
142
 
143
  chat_msgs = []
144
- for msg in list(messages)[::-1]: # Most recent first!
145
  data = msg.to_dict()
146
  if data["role"] == "user":
147
  chat_msgs.append(
@@ -172,34 +199,31 @@ def synthesize_voice(text, voice_key, user_id):
172
  st.session_state["last_voice"] = voice
173
  return out_path
174
 
175
- # --- INPUT AT THE TOP ---
 
 
 
176
  with st.container():
177
- st.markdown('<div class="input-top-bar">', unsafe_allow_html=True)
178
- col1, col2 = st.columns([10, 1])
179
- user_input = col1.chat_input("Type your message here...")
180
- if col2.button("🗑️", help="Clear Chat", key="clear-chat-top"):
181
- clear_chat_history()
182
  st.markdown('</div>', unsafe_allow_html=True)
183
 
184
- # --- CHAT: display under input, latest on top ---
185
- display_chat_history()
186
-
187
- # --- JS: auto-scroll to top on new message ---
188
  st.markdown("""
189
  <script>
190
  window.onload = function() {
191
  var anchor = document.getElementById("chat-top-anchor");
192
  if(anchor){ anchor.scrollIntoView({ behavior: "smooth", block: "start" }); }
193
  };
194
- window.setTimeout(function(){
195
- var anchor = document.getElementById("chat-top-anchor");
196
- if(anchor){ anchor.scrollIntoView({ behavior: "smooth", block: "start" }); }
197
- }, 200);
198
  </script>
199
  """, unsafe_allow_html=True)
200
 
 
 
 
 
 
201
  if user_input:
202
- # --- OpenAI Assistant Response ---
203
  thread_id = get_or_create_thread_id()
204
  client.beta.threads.messages.create(thread_id=thread_id, role="user", content=user_input)
205
  save_message("user", user_input)
 
46
  if "selected_voice" not in st.session_state:
47
  st.session_state["selected_voice"] = "Jenny (US, Female)"
48
 
49
+ # --- CSS ---
50
  st.markdown("""
51
  <style>
52
  .block-container {padding-top: 1rem;}
 
57
  display: block;
58
  }
59
  .lor-brand-bar {
60
+ width: 100vw;
61
+ text-align: center;
62
+ background: none;
63
+ margin-bottom: 0.5em;
64
+ margin-top: 0.1em;
65
+ position: relative;
66
  }
67
+
68
+ .clear-chat-btn-top {
69
+ position: absolute;
70
+ top: 10px;
71
+ right: 50px;
72
+ font-size: 1.4em;
73
+ color: #ccc;
74
+ background: none;
75
+ border: none;
76
+ cursor: pointer;
77
+ z-index: 1000;
78
+ transition: color 0.2s ease;
79
+ }
80
+
81
+ .clear-chat-btn-top:hover {
82
+ color: #fff;
83
+ }
84
+
85
  .stChatMessage { max-width: 85%; border-radius: 12px; padding: 8px; margin-bottom: 10px; }
86
  .stChatMessage[data-testid="stChatMessage-user"] { background: #f0f0f0; color: #000000; }
87
  .stChatMessage[data-testid="stChatMessage-assistant"] { background: #e3f2fd; color: #000000; }
88
+
89
  .chat-history-wrapper {
90
+ margin-top: 0.5em;
91
+ padding-bottom: 9em; /* enough space so input does not cover messages */
92
+ min-height: 60vh;
93
  }
94
+
95
+ .input-bottom-bar {
96
+ position: fixed;
97
+ bottom: 3.5em;
98
+ width: 100%;
99
+ background: #191b22;
100
+ padding: 0.5em 0.6em;
101
+ border-top: 1px solid #22232c;
102
+ z-index: 999;
103
  }
 
 
 
104
  </style>
105
  """, unsafe_allow_html=True)
106
 
107
+ # --- Top Branding + clear button ---
108
  st.markdown("""
109
  <div class="lor-brand-bar">
110
  <img src="https://i0.wp.com/c2group.co.za/wp-content/uploads/2022/10/cropped-1_C2-Group-Technologies-Logo-2-1.png?w=1024&ssl=1" class="logo-mini" />
111
  <div style="font-size: 13px; color: #888;">Powered by C2 Group</div>
112
+ <button class="clear-chat-btn-top" onclick="window.location.href='?clear=1'">🗑️</button>
113
  </div>
114
  """, unsafe_allow_html=True)
115
 
116
+ # --- Sidebar: voice settings ---
117
  with st.sidebar:
118
  st.markdown("### Voice Settings & Controls")
119
  selected_voice = st.selectbox(
 
168
  assistant_icon_html = "<img src='https://img.freepik.com/free-vector/graident-ai-robot-vectorart_78370-4114.jpg?semt=ais_hybrid&w=740' width='22' style='vertical-align:middle; border-radius:50%;'/>"
169
 
170
  chat_msgs = []
171
+ for msg in list(messages)[::-1]:
172
  data = msg.to_dict()
173
  if data["role"] == "user":
174
  chat_msgs.append(
 
199
  st.session_state["last_voice"] = voice
200
  return out_path
201
 
202
+ # --- CHAT DISPLAY ---
203
+ display_chat_history()
204
+
205
+ # --- Bottom chat input ---
206
  with st.container():
207
+ st.markdown('<div class="input-bottom-bar">', unsafe_allow_html=True)
208
+ user_input = st.chat_input("Type your message here...")
 
 
 
209
  st.markdown('</div>', unsafe_allow_html=True)
210
 
211
+ # --- JS auto-scroll ---
 
 
 
212
  st.markdown("""
213
  <script>
214
  window.onload = function() {
215
  var anchor = document.getElementById("chat-top-anchor");
216
  if(anchor){ anchor.scrollIntoView({ behavior: "smooth", block: "start" }); }
217
  };
 
 
 
 
218
  </script>
219
  """, unsafe_allow_html=True)
220
 
221
+ # --- Handle clear button ---
222
+ if st.query_params.get("clear") == "1":
223
+ clear_chat_history()
224
+
225
+ # --- Handle user input ---
226
  if user_input:
 
227
  thread_id = get_or_create_thread_id()
228
  client.beta.threads.messages.create(thread_id=thread_id, role="user", content=user_input)
229
  save_message("user", user_input)