Adinarayana02 commited on
Commit
c4b8e86
·
verified ·
1 Parent(s): 8692733

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -132
app.py CHANGED
@@ -71,7 +71,7 @@ def build_prompt(latest_input: str, previous_interactions: List[Interaction]) ->
71
  return prepared_prompt
72
 
73
  # Set the page config for Streamlit
74
- st.set_page_config(page_title="LUNA AI", page_icon="🤖", layout="wide")
75
 
76
  # Add premium CSS styling with the new blue color palette
77
  st.markdown("""
@@ -90,28 +90,6 @@ st.markdown("""
90
  font-size: 28px;
91
  font-weight: bold;
92
  border-bottom: 1px solid #0FA4AF; /* Lighter blue border */
93
- display: flex;
94
- justify-content: space-between;
95
- align-items: center;
96
- }
97
-
98
- .header .title {
99
- margin-left: 20px;
100
- }
101
-
102
- .header .nav-buttons {
103
- margin-right: 20px;
104
- }
105
-
106
- .header .nav-buttons a {
107
- color: #AFDDE5;
108
- text-decoration: none;
109
- font-size: 16px;
110
- margin: 0 10px;
111
- }
112
-
113
- .header .nav-buttons a:hover {
114
- text-decoration: underline;
115
  }
116
 
117
  .chat-box {
@@ -196,75 +174,11 @@ st.markdown("""
196
  font-size: 20px;
197
  font-weight: bold;
198
  }
199
-
200
- .footer {
201
- background-color: #024950; /* Medium blue background for footer */
202
- padding: 20px;
203
- text-align: center;
204
- color: #AFDDE5; /* Light blue text in the footer */
205
- border-top: 1px solid #0FA4AF; /* Lighter blue border */
206
- }
207
-
208
- .feedback-button {
209
- background-color: #0FA4AF; /* Aqua blue button color */
210
- color: #003135; /* Dark blue text on button */
211
- border: none;
212
- border-radius: 20px;
213
- padding: 10px 20px;
214
- cursor: pointer;
215
- font-size: 16px;
216
- margin: 10px;
217
- }
218
-
219
- .feedback-popup {
220
- display: none;
221
- position: fixed;
222
- bottom: 80px;
223
- left: 50%;
224
- transform: translateX(-50%);
225
- background-color: #024950;
226
- border: 1px solid #0FA4AF;
227
- border-radius: 8px;
228
- padding: 20px;
229
- width: 300px;
230
- z-index: 1000;
231
- }
232
-
233
- .feedback-popup button {
234
- background-color: #0FA4AF;
235
- color: #003135;
236
- border: none;
237
- border-radius: 20px;
238
- padding: 10px 20px;
239
- cursor: pointer;
240
- font-size: 16px;
241
- margin-top: 10px;
242
- }
243
-
244
- .feedback-popup button:hover {
245
- background-color: #024950;
246
- }
247
-
248
- .feedback-popup textarea {
249
- width: 100%;
250
- border-radius: 8px;
251
- border: 1px solid #0FA4AF;
252
- padding: 10px;
253
- margin-bottom: 10px;
254
- }
255
  </style>
256
  """, unsafe_allow_html=True)
257
 
258
- # Header with title and navigation buttons
259
- st.markdown("""
260
- <div class="header">
261
- <div class="title">✨LUNA AI✨</div>
262
- <div class="nav-buttons">
263
- <a href="#home">Home</a>
264
- <a href="#about">About</a>
265
- </div>
266
- </div>
267
- """, unsafe_allow_html=True)
268
 
269
  # Container for chat messages and input area
270
  with st.container():
@@ -276,7 +190,8 @@ with st.container():
276
  st.markdown(
277
  '''
278
  <div class="subheader">
279
- Meet Luna, your friendly AI assistant ready to help you in any language! 🌐💬
 
280
  </div>
281
  ''',
282
  unsafe_allow_html=True
@@ -285,50 +200,48 @@ with st.container():
285
  if interaction.role == "human":
286
  st.markdown(f'<div class="chat-box user-message message"><strong>You:</strong> {interaction.content}</div>', unsafe_allow_html=True)
287
  else:
288
- st.markdown(f'<div class="chat-box assistant-message message"><div class="assistant-logo"><img src="https://example.com/your-logo.png" alt="LUNA AI"></div><strong>LUNA AI:</strong> {interaction.content}</div>', unsafe_allow_html=True)
289
-
290
- # Input area for user to type messages
291
- user_input = st.text_area("Your message:", "", key="user_input")
292
-
293
- # Button to send the message
 
 
 
 
 
 
 
294
  if st.button("Send"):
295
  if user_input:
296
- # Add the user's message to interactions
297
- st.session_state.previous_interactions.append(Interaction("human", user_input))
298
-
299
- # Generate AI response
300
  prompt = build_prompt(user_input, st.session_state.previous_interactions)
301
- ai_response = OpenAIPAF().think(prompt)
302
-
303
- # Add the assistant's response to interactions
304
- st.session_state.previous_interactions.append(Interaction("assistant", ai_response))
305
-
306
- # Clear the input area
307
- st.session_state.user_input = ""
308
-
309
- # Re-render the chat
310
- st.experimental_rerun()
 
 
 
 
 
 
 
 
 
 
311
 
312
- # Footer with feedback button and emoji options
313
- st.markdown("""
314
- <div class="footer">
315
- <button class="feedback-button" onclick="document.getElementById('feedback-popup').style.display='block'">💬 Give Feedback</button>
316
- <div id="feedback-popup" class="feedback-popup">
317
- <h3>We value your feedback! 📝</h3>
318
- <textarea placeholder="Share your thoughts..."></textarea>
319
- <button onclick="document.getElementById('feedback-popup').style.display='none'">Submit</button>
320
- </div>
321
- </div>
322
- """, unsafe_allow_html=True)
323
 
324
- # JavaScript to handle the feedback popup
325
- st.markdown("""
326
- <script>
327
- // Close the feedback popup when clicking outside of it
328
- window.onclick = function(event) {
329
- if (event.target === document.getElementById('feedback-popup')) {
330
- document.getElementById('feedback-popup').style.display = 'none';
331
- }
332
- }
333
- </script>
334
- """, unsafe_allow_html=True)
 
71
  return prepared_prompt
72
 
73
  # Set the page config for Streamlit
74
+ st.set_page_config(page_title="AI Chatbot", page_icon="🤖", layout="wide")
75
 
76
  # Add premium CSS styling with the new blue color palette
77
  st.markdown("""
 
90
  font-size: 28px;
91
  font-weight: bold;
92
  border-bottom: 1px solid #0FA4AF; /* Lighter blue border */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
 
95
  .chat-box {
 
174
  font-size: 20px;
175
  font-weight: bold;
176
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  </style>
178
  """, unsafe_allow_html=True)
179
 
180
+ # Header and container for chat messages
181
+ st.markdown('<div class="header">✨Luna✨<br>Your Friendly Digital Assistant chatbot!😊</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
182
 
183
  # Container for chat messages and input area
184
  with st.container():
 
190
  st.markdown(
191
  '''
192
  <div class="subheader">
193
+ Meet Luna,your friendly Ai assistant ready to help you in any language! 🌐💬
194
+
195
  </div>
196
  ''',
197
  unsafe_allow_html=True
 
200
  if interaction.role == "human":
201
  st.markdown(f'<div class="chat-box user-message message"><strong>You:</strong> {interaction.content}</div>', unsafe_allow_html=True)
202
  else:
203
+ st.markdown(f"""
204
+ <div class="chat-box assistant-message message">
205
+ <div class="assistant-logo">
206
+ <img src="https://avatar-prod-us-east-2.webexcontent.com/Avtr~V1~1eb65fdf-9643-417f-9974-ad72cae0e10f/V1~1a08968daf428f4f5d1ce0f04de95eb40bf8d6d8cb5a0463a6f858f52e3a9df9~49713ad2dabe4cb2a6f83a05c6d6e4f5"" alt="AI Assistant">
207
+ </div>
208
+ <div><strong>Assistant:</strong> {interaction.content}</div>
209
+ </div>
210
+ """, unsafe_allow_html=True)
211
+
212
+ # Text input field
213
+ user_input = st.text_area("Enter your message:", height=100, placeholder="Type your message here...")
214
+
215
+ # Submit button
216
  if st.button("Send"):
217
  if user_input:
218
+ assistant = OpenAIPAF()
219
+ assistant.setup()
220
+
221
+ # Build prompt and get response
222
  prompt = build_prompt(user_input, st.session_state.previous_interactions)
223
+ response = assistant.think(prompt)
224
+
225
+ # Update interactions
226
+ st.session_state.previous_interactions.append(Interaction(role="human", content=user_input))
227
+ st.session_state.previous_interactions.append(Interaction(role="assistant", content=response))
228
+
229
+ # Display response
230
+ st.markdown(f'<div class="chat-box user-message message"><strong>You:</strong> {user_input}</div>', unsafe_allow_html=True)
231
+ st.markdown(f"""
232
+ <div class="chat-box assistant-message message">
233
+ <div class="assistant-logo">
234
+ <img src="https://avatar-prod-us-east-2.webexcontent.com/Avtr~V1~1eb65fdf-9643-417f-9974-ad72cae0e10f/V1~1a08968daf428f4f5d1ce0f04de95eb40bf8d6d8cb5a0463a6f858f52e3a9df9~49713ad2dabe4cb2a6f83a05c6d6e4f5" alt="AI Assistant">
235
+ </div>
236
+ <div><strong>Assistant:</strong> {response}</div>
237
+ </div>
238
+ """, unsafe_allow_html=True)
239
+
240
+ # Keep only the last CONVO_TRAIL_CUTOFF interactions
241
+ if len(st.session_state.previous_interactions) > CONVO_TRAIL_CUTOFF:
242
+ st.session_state.previous_interactions = st.session_state.previous_interactions[-CONVO_TRAIL_CUTOFF:]
243
 
244
+ else:
245
+ st.warning("Please enter a message.")
 
 
 
 
 
 
 
 
 
246
 
247
+ st.write("This chatbot uses GPT-4o-mini model to respond to your messages.")