ogegadavis254 commited on
Commit
6a9d8b2
·
verified ·
1 Parent(s): 8e32a1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import os
3
  import requests
4
  import json
 
5
 
6
  # Initialize a global variable to store the entire assistant response
7
  entire_assistant_response = ""
@@ -69,26 +70,67 @@ def get_streamed_response(message, history):
69
  return entire_assistant_response
70
 
71
  # Streamlit application
 
 
72
  st.sidebar.title("Raxder unofficial AI")
73
  st.sidebar.write("This is NOT an AI Therapist, use it at your OWN RISK! This might be the worst AI you have ever used.")
74
 
75
- # Initialize session state for history
76
  if "history" not in st.session_state:
77
  st.session_state.history = []
78
 
79
- # Create a placeholder for the chat history
80
  chat_placeholder = st.container()
81
 
82
- # Bottom input box
 
 
 
 
 
 
 
 
 
 
 
 
83
  user_input = st.text_input("You:", key="user_input")
84
  send_button = st.button("Send")
85
 
86
  if send_button and user_input:
87
- response = get_streamed_response(user_input, st.session_state.history)
88
- st.session_state.history.append((user_input, response))
 
 
89
 
90
- # Display chat history
91
  with chat_placeholder:
92
  for human, assistant in st.session_state.history:
93
- st.write(f"You: {human}")
94
- st.write(f"notDave: {assistant}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import os
3
  import requests
4
  import json
5
+ from streamlit_chat import message
6
 
7
  # Initialize a global variable to store the entire assistant response
8
  entire_assistant_response = ""
 
70
  return entire_assistant_response
71
 
72
  # Streamlit application
73
+ st.set_page_config(page_title="Raxder unofficial AI", page_icon="🤖")
74
+
75
  st.sidebar.title("Raxder unofficial AI")
76
  st.sidebar.write("This is NOT an AI Therapist, use it at your OWN RISK! This might be the worst AI you have ever used.")
77
 
78
+ history = []
79
  if "history" not in st.session_state:
80
  st.session_state.history = []
81
 
82
+ # Create a container for the chat history
83
  chat_placeholder = st.container()
84
 
85
+ # Accept user input at the bottom
86
+ st.markdown("""
87
+ <style>
88
+ .input-container {
89
+ position: fixed;
90
+ bottom: 0;
91
+ width: 100%;
92
+ background-color: #f0f2f6;
93
+ padding: 10px;
94
+ }
95
+ </style>
96
+ """, unsafe_allow_html=True)
97
+
98
  user_input = st.text_input("You:", key="user_input")
99
  send_button = st.button("Send")
100
 
101
  if send_button and user_input:
102
+ history = st.session_state.history
103
+ response = get_streamed_response(user_input, history)
104
+ history.append((user_input, response))
105
+ st.session_state.history = history
106
 
107
+ # Display chat history with colors
108
  with chat_placeholder:
109
  for human, assistant in st.session_state.history:
110
+ message(human, is_user=True, key=f"user_{human}")
111
+ message(assistant, is_user=False, key=f"assistant_{assistant}")
112
+
113
+ # Add user input container at the bottom
114
+ st.markdown("""
115
+ <div class="input-container">
116
+ <input type="text" id="input_box" placeholder="You:">
117
+ <button onclick="send_message()">Send</button>
118
+ </div>
119
+ """, unsafe_allow_html=True)
120
+
121
+ def send_message():
122
+ user_input = st.session_state.get("user_input", "")
123
+ if user_input:
124
+ history = st.session_state.history
125
+ response = get_streamed_response(user_input, history)
126
+ history.append((user_input, response))
127
+ st.session_state.history = history
128
+ st.session_state.user_input = ""
129
+
130
+ chat_placeholder.empty()
131
+ with chat_placeholder:
132
+ for human, assistant in st.session_state.history:
133
+ message(human, is_user=True, key=f"user_{human}")
134
+ message(assistant, is_user=False, key=f"assistant_{assistant}")
135
+
136
+ st.button("Send", on_click=send_message)